Code for partial close with percentage

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

Viewing 15 posts - 16 through 30 (of 62 total)
  • #154549

    As to my code, Vonasi realized that the error is due to the fact the the name of that variable starts with REM which is a reserved word for COMMENTS (like double slashes).

    Just replace Rem with MyRem and it should work.

     

    #154551

    Thanks Roberto😀

    Now it works!!!

    #161613

    Hi Roberto

    How do i run this code only once. That is, exit 50% based on the condition and stop running this code. For remaining position, I have another condition.

    #161621

    There you go:

    QUIT will exit the strategy from AutoTrading. Any open position will either be kept open or closed according to the option you have selected in the platform.

     

    #161628

    thanks Roberto, but I meant – once 50% position is closed, then no further 50% close even when condition is met.

    To clarify,

    I want 50% of positions to close when Condtion1 is met, the above code already does this, but the code closes 50% position each time the condition is met – I need it to run 50% close only once.

    For the remaining 50% I have another set of condition. This 50% remaining position is intended for larger trend ride.

     

    I have this code for closing 50%, but the conter concept isn’t working

     

     

     

    #161631

    Bob’s your uncle:

     

    #161637

    this code didnt work, it kept closing the position by half each time condition was met, I have this code but the counter is not working,

    See image below, I need the last two orders ie. Buy 233 contract then sell 116.5 contract. Once this is done, I don’t need the below code to run as I will close the remaining order based on another set of codes.

    Hope it makes sense

     

    #161645

    It works like a charm for me:

    once half position is closed, no further action is taken.

    #161654

    I tried it. With BUY 1 Contract as in code above, it works.

    But when I change the 1 contract to variable size of PositionSize Contract, the code closes 50% position multiple times. This makes no sense – it should work exactly same with Postitionsize contract as well I think

    #161656

    It’s weird, it trades when FLAG=1 which is set when NOT OnMarket.

    Once a position is partially closed, FLAG is set to 0 and can’t be set again to 1 until ALL positions are closed.

    Try using this at lines 16 and 19:

     

    #161657

    Looks like the code was working only because the buy quantity was set to 1. If I change it to anything else it does not work. I tried flag=1, no difference See below the exact code,’

     

     

    #161676

    It works perfectly for me, with 10 positions.

    I noticed that you are using POSITIONSIZE.

    If you set POSITIONSIZE to an inituial value, than halve it without restoring its initial value when not onmarket, then the next trade it will be halved once more. I guess this might be the cause.

    Simply add this line after line 7:

     

    #161679

    I tried with 10 position size, it doesn’t work. See the image, this is the code I ran

    What am I doing wrong? When I change to quantity to 1, it works. Neigher a variable position size nor anything above 1 is working for me

     

     

    #161687

    Use the GRAPH instructions that I posted, it’s better to spot any weird change in values, candle by candle.

     

    #161741

    Please see the image

    The code is closing order despite flag value being zero at the bar the partial close occured

Viewing 15 posts - 16 through 30 (of 62 total)

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