stop loss code not working
Forums › ProRealTime English forum › ProOrder support › stop loss code not working
- This topic has 6 replies, 4 voices, and was last updated 5 years ago by Nicolas.
Tagged: stop loss, trailing stop
-
-
06/02/2019 at 3:39 PM #99821
Hi
Was hoping someone can shed some light on the code below:
12345IF Bullish THENbuy (100/(2*atr)) perpoint AT MARKETset stop loss (2*atr)set stop trailing (4*atr)ENDIFIn the back test i was expecting the worst trade value to be £100 but turns out as £466. If you swap the position of the set stop loss and trailing i.e. have
12set stop trailing (4*atr)set stop loss (2*atr)then the worst trade value os £384
If you change everything to 4*atr as below then the max loss comes to £232
12345IF Bullish THENbuy (100/(4*atr)) perpoint AT MARKETset stop loss (4*atr)set stop trailing (4*atr)ENDIFI’m quite confused as to what i’m doing wrong. Anybody able to help please?
Kind regards
JV
06/02/2019 at 4:15 PM #99822Since you are using two different SL instructions, the second one will always override the first one.
Moreover, set stop trailing will backtest using a 1-pip step.
You’d better using custom code, instead.
You can retrieve many snippets on the forum or from the Snippet Library you can find using the search box.
06/02/2019 at 5:25 PM #99830jayvee – Welcome to the forums.
There are some basic rules that everyone needs to follow when posting in the forums and you have broken two of them.
Please always use the ‘Insert PRT Code’ button when putting code in your posts as it makes it much easier for others to read. The ‘Insert PRT Code’ button can be found at the far right of the tools that are located above the box where you type your post.
I have tidied up the code in your last post for you. 🙂
Also ensure that you post your topic in the correct forum. You posted in the General Discussion forum with a ProOrder autotrading related question. I have moved your topic to the correct forum.
06/02/2019 at 9:57 PM #9983306/02/2019 at 10:17 PM #99834I presume where it says in the documentation (https://www.prorealcode.com/blog/learning/kinds-trailing-stop-proorder/) the below is incorrect then?
1SET STOP LOSS x TRAILING yIs there a way of combining a hard stop loss (set stop loss x) as I’ve done above with Nicolas’ code as it only executes when the candle closes? Apologies, I know this is probably really basic!
1234567891011121314151617181920212223242526272829303132333435363738//trailing stop functiontrailingstart = 20 //trailing will start @trailinstart points profittrailingstep = 5 //trailing step to move the "stoploss"//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THENnewSL = tradeprice(1)+trailingstep*pipsizeENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep*pipsize THENnewSL = newSL+trailingstep*pipsizeENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THENnewSL = tradeprice(1)-trailingstep*pipsizeENDIF//next movesIF newSL>0 AND newSL-close>=trailingstep*pipsize THENnewSL = newSL-trailingstep*pipsizeENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIF06/02/2019 at 11:16 PM #99835Despite documentation, the line:
1SET STOP LOSS x TRAILING yis incorrect, since it contains 2 different kinds of SL on the same line. Use
12SET STOP LOSS 0040 //requirese difference in Price, say 0040SET STOP pLOSS 40 //requires numbers of Pipsthen add the above code, as is (provided you set your own pip values), to your strategy.
1 user thanked author for this post.
06/03/2019 at 8:05 AM #99843 -
AuthorPosts
Find exclusive trading pro-tools on