Different stop losses for longs and shorts

Forums ProRealTime English forum ProOrder support Different stop losses for longs and shorts

Viewing 15 posts - 1 through 15 (of 19 total)
  • #57248

    Just wondering if its possible to have 2 different stop loss strategies in a trading strat for longs and shorts and what is the syntax to acheive this  . lets say this set of parameters for longs

    and this set of parameters for shorts

    Ive had a few shots at it but cant get it working  in anyway

     

    #57252

    You can just set variables say TP and SL within your IF THEN BUY SELL like this:

     

    1 user thanked author for this post.
    #57268

    You can just set variables say TP and SL within your IF THEN BUY SELL like this:

    Awesome thanks for that , would appear to be perfect for the job at hand , I really appreciate the level of knowledge and generosity in these forums

    #57271

    Brisvegas, ProOrder won’t allow you to use both STOP orders as in your lines 2-3, line 2 will be immediately overridden by line 3 (since it comes last) and it will not be reported as an error.

    Vonasi‘s code is the correct way to accomplish different SLs and TPs for LONG and SHORT trades.

    Despite not being 100% sure I want to point out that your code

    might modify TP and SL values even when OnMarket, because if your conditions are true the BUY won’t be executed in case you forbade this from happening with DEFPARAM ComulateOrders = FALSE, but all lines will be evaluated and variables set accordingly. So, in case you have some trailing stop code that has previously changed those value, they might be restored to the original ones, thus producing unwanted results.

    I suggest that the above code be changed to

    to make sure that when OnMarket the whole IF…ENDIF block is skipped.

     

     

    2 users thanked author for this post.
    #57274

    Thanks for spotting that Robertogozzi. I always use AND NOT OnMarket but left is out for simplification as I always assume that everyone else knows what they are doing!

    Many strategies can be confused by having variables set every time entry conditions are met even if the actual BUY and SELL does not take place due to CumulateOrders = false.

    #57308

    I do know what im doing but i got to say the resources for actually learning this code are very skinny outside this forum  , I am a trader first and then a coder , i have the maths of all this down pat , its just half a line of syntax that slows me down and for the life of me i could find no documentation to assist me  , I only ask here as a last resort unlike some , working it out for yourself is the best way if you can , trust me i have tried to work on some syntax for weeks before asking in here  ..

    #57309

    LOL would be great if the people who build the website were as talented as the coders here  . This should be front and centre and in a drop down menu on every page in this site  . I am actually starting a bookmark folder for this place as there is little rhyme or reason to the cataloguing of content  😉       https://www.prorealcode.com/documentation/

    #57312

    Sorry Brisvegas I was not trying to imply that you do not know what you are doing. Sometimes the written word is not the best form of communication. I was actually criticising myself for always assuming too much. As my girlfriend always says Assume makes an ASS out of U and ME.

    Six months ago I spent a week of my life trying to fathom out how SET STOP and SET TARGET worked within a code which is why I happily answered your opening post.

    #57320

    LOL would be great if the people who build the website were as talented as the coders here  .

    Sorry, I do my best…

    #57325

    LOL would be great if the people who build the website were as talented as the coders here .

    Sorry, I do my best…

    ….and your best is very very good even when you are supposed to be on holiday!

    #57338

    is it possible to write the code like this?

     

    #57353

    is it possible to write the code like this?

    Yes. The SET instruction just places an order on the market that is in place until the position is closed or until the SET value is set to zero. I just find that having the SET instructions at the end of a code with a variable allows more elegant adjustment of stops and targets.

    #57354

    Thats what i thought Vonasi, thanks for confirming.

    #57462

    LOL would be great if the people who build the website were as talented as the coders here .

    Sorry, I do my best…

    Sorry Nicolas you do a great job overall no doubt

    #57599

    Hi everybody,

     

    after many trials of placing the different set for loss&profit in long and short positions, I’ve done the following way and it seems to give backtests with less tick/tick values.

    what do you think?

     

    IF LONGONMARKET AND CLOSE>=(TRADEPRICE+(TPL*PIPSIZE)) OR CLOSE<=(TRADEPRICE-(SL*PIPSIZE)) THEN

    SELL AT MARKET

    ENDIF

     

    IF SHORTONMARKET AND CLOSE<=(TRADEPRICE-(TP1*PIPSIZE)) OR CLOSE>=(TRADEPRICE+(SL1*PIPSIZE)) THEN

    EXITSHORT AT MARKET

    ENDIF

     

Viewing 15 posts - 1 through 15 (of 19 total)

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