Trailing stop function – what are the STOP orders for?
Forums › ProRealTime English forum › ProOrder support › Trailing stop function – what are the STOP orders for?
- This topic has 6 replies, 5 voices, and was last updated 7 months ago by robertogozzi.
-
-
09/28/2021 at 1:51 PM #178651Trailing stop function12345678910111213141516171819202122232425262728293031323334353637383940//trailing stop functiontrailingstart = 10 //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 THENnewSL = tradeprice(1)+trailingstepENDIF//next movesIF newSL>0 AND close>close[1] THENnewSL = newSL+trailingstepENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart THENnewSL = tradeprice(1)-trailingstep//newSL = close + (1 * trailingstep)ENDIF//next movesIF newSL>0 AND close<close[1] THENnewSL = newSL-trailingstep//newSL = close + (1 * trailingstep)ENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIF
Hi
In this trailing stop function, what is the purpose of STOP in the last commands SELL AT newSL STOP and EXITSHORT AT newSL STOP? Is it a stop loss command or does it stop the code from continuing to run the commands after STOP if the conditions are met?
Thanks
Sachin
09/28/2021 at 2:08 PM #178652In this page of the blog you will find the explanation of the code :
https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/
1 user thanked author for this post.
09/28/2021 at 2:10 PM #178653It is a pending STOP order.
1 user thanked author for this post.
10/01/2021 at 1:08 AM #178831Hi Nicholas
Thanks for clarifying.
Does the code in the below page of the blog incorporate a minimum stop distance required by the broker? e.g. a minimum stop distance of 10 points for any instrument?
https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/
Thanks
Sachin
10/01/2021 at 1:22 AM #178832This is Nicolas’ code with the addition of distance and a delayed execution https://www.prorealcode.com/topic/problemi-con-broker-ig-riguardo-lutilizzo-di-algo-con-trailing-stop-e-trailing/#post-175071
Distance is at line 9.
Delayed execution is at line 6, just replace 0 with any number to delay execution for N bars from entry.
1 user thanked author for this post.
04/23/2024 at 1:15 PM #23184504/23/2024 at 2:41 PM #231857I don’t know, as I don’t use IB.
If the ProRealTime language is wholly supported, it should, but that’s just speculation.
-
AuthorPosts
Find exclusive trading pro-tools on