Different stop losses for longs and shorts
Forums › ProRealTime English forum › ProOrder support › Different stop losses for longs and shorts
- This topic has 18 replies, 7 voices, and was last updated 7 years ago by
Vonasi.
-
-
01/04/2018 at 3:17 PM #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
123SET STOP pLOSS 10SET TARGET pPROFIT 15SET STOP pTRAILING 20and this set of parameters for shorts
123SET STOP pLOSS 20SET TARGET pPROFIT 30SET STOP pTRAILING 25Ive had a few shots at it but cant get it working in anyway
01/04/2018 at 3:35 PM #57252You can just set variables say TP and SL within your IF THEN BUY SELL like this:
1234567891011121314IF your conditions THENBUY 1 Contract AT MARKETTP = 10SL = 5ENDIFIF your conditions THENSELLSHORT 1 Contract AT MARKETTP = 20SL = 10ENDIFSET TARGET pPROFIT TPSET STOP pLOSS SL1 user thanked author for this post.
01/04/2018 at 5:28 PM #57268You can just set variables say TP and SL within your IF THEN BUY SELL like this:
1234567891011121314IF your conditions THENBUY 1 Contract AT MARKETTP = 10SL = 5ENDIFIF your conditions THENSELLSHORT 1 Contract AT MARKETTP = 20SL = 10ENDIFSET TARGET pPROFIT TPSET STOP pLOSS SLAwesome 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
01/04/2018 at 5:39 PM #57271Brisvegas, 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
12345IF your conditions THENBUY 1 Contract AT MARKETTP = 10SL = 5ENDIFmight 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
12345IF your conditions AND Not OnMarket THENBUY 1 Contract AT MARKETTP = 10SL = 5ENDIFto make sure that when OnMarket the whole IF…ENDIF block is skipped.
01/04/2018 at 5:46 PM #57274Thanks 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.
01/04/2018 at 11:21 PM #57308I 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 ..
01/04/2018 at 11:30 PM #57309LOL 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/
01/04/2018 at 11:54 PM #57312Sorry 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.
01/05/2018 at 8:47 AM #57320LOL would be great if the people who build the website were as talented as the coders here .
Sorry, I do my best…
01/05/2018 at 9:57 AM #57325LOL 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!
01/05/2018 at 11:17 AM #5733801/05/2018 at 12:54 PM #57353is it possible to write the code like this?
1234if longonmarket thenset stop ploss 50set target pprofit 50endifYes. 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.
01/05/2018 at 12:56 PM #5735401/05/2018 at 11:16 PM #57462LOL 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
01/07/2018 at 2:18 PM #57599Hi 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
-
AuthorPosts
Find exclusive trading pro-tools on