Code for partial close with percentage

Forums ProRealTime English forum ProOrder support Code for partial close with percentage

Viewing 15 posts - 31 through 45 (of 62 total)
  • #161755

    No, it’s not halving a position despite Flag=0, it’s Flag=0 because a position had been halved (because Flag=1 before that partial closure).

    Bear in mind that GRAPH shows the value retained at the end of the execution, not the one retained ar the beginning (the beginning is just the end of the previous candle).

     

    #161777

    I get what you mean. See image below.

    Note that only 1 buy order was executed and all the orders closed are half of remaining position.

    The first halving is correct, and Flag thereafter is zero. So, I wonder why its continuing to execute the code despite the FLAG=1 condition not being met. If I check previous bars from 2nd halving as highlighted in image, Flag is zero, so code should not run after the first 50% is closed. In this case, its halving until, the qty is less than 0.5 contract.

    #161785

    I can only try to replicate your trades, provided:

    • you post the code you used in your tests
    • you post what instrument, TF, date and time those trades refer to

     

    #161808

    This is the code,

    Instrument- APT (Afterpay Ltd) in 1 Min Timeframe. 3K unit data loaded

     

    #161827

    The DTOSC in the library requires no parameters.

    Please post a complete working code or I won’t be able to help you!

    Post the ITF file of the indicator.

     

     

    #161828

    I had modified the DTOSC code to include cross over dot that’s why it needs two values. Here is the ITF file attached

    #161863

    Itested it on DAX because with Afterpay Ltd I couldn’t get any trade.

    Everything works fine and it halves  positions only once per trade.

     

    #161870

    Ran the same code in DAX, it keeps halving positions, see the image attached

    #161890

    Ok, I got it.

    It’s because you are using the MTF support incorrectly.

    You are using a 1-minute TF but have no support for the DEFAULT TF, so it is executed every minute but you have writtem only instructions for the Daily and 1h TF’s.

    If you add UPDATEONCLOSE to your TIMEFRAME instruction everything is fine.

    If you DO NOT want to use UPDATEONCLOSE  then you have to use TIMEFRAME(default) for the FLAG variable, as follows:

     

    #161909

    Thank you. You are right. Its now working as expected. Thanks for the help

    #162168

    Ciao Roberto, thanks very much for the work you’ve done on the partial close code.

    If I wanted to close 25% of my position after a .5% gain, another 25% after 1% gain, and the same after 1.5% (leaving the remainder to run to the TP or trailing stop) would this be the best way to do it?

     

    #162170

    That’s correct, but you only need the EXITING calculations and instructions only ONCE, since the next time it will still be 25% of the remaining opositions. Well… not exactly, if you BUY 8 contracts the first time you will close 2 contracts (8  * 0.25), while next time you will close 1.5 contracts (6 * 0.25), etc…

    To overcome this, if you plan to always close, not a percentage, but a fixed number like the first time, you simply need to compute the number of contracts to exit the first time and use that number (instead of a percentage) for any subsequent closure.

    In any case you don’t need to use 3 IF…ENDIF’s.

    Of course that would be completely different if you wanted to close, say 10% the first time, then 13% the second time, 21% the third time, etc…

     

     

     

    #162175

    you only need the EXITING calculations and instructions only ONCE

    ah yes, of course (too much copy and pasting), thanks for that!

    #162182

    that would be completely different if you wanted to close, say 10% the first time, then 13% the second time, 21% the third time

    Something like this then?

     

    #162194

    turns out that must be wrong as it either runs with no effect at all (same result as with no partial close) or it gets a parsing error (must begin and end with the same entity).

    what am i doing wrong?

Viewing 15 posts - 31 through 45 (of 62 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login