change points to trailing stop percentages
Forums › ProRealTime English forum › ProOrder support › change points to trailing stop percentages
- This topic has 5 replies, 3 voices, and was last updated 2 years ago by
Nicolas.
-
-
12/02/2022 at 10:30 AM #205163
Hi, I can’t seem to change the code to work in percent, and I don’t know how to change the variables. thank you
once trailinstop= ActiveTs
trailingstart = TS
trailingstep = TsStep
once breakeaven = ActiveBE
startBreakeven = StartBe
PointsToKeep = PointBe
if trailinstop>0 then
IF NOT ONMARKET THEN
newSL=0
ENDIF
IF LONGONMARKET THEN
IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
newSL = tradeprice(1)+trailingstep*pipsize
ENDIF
IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
newSL = newSL+trailingstep*pipsize
ENDIF
ENDIF
IF SHORTONMARKET THEN
IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN
newSL = tradeprice(1)-trailingstep*pipsize
ENDIF
IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
newSL = newSL-trailingstep*pipsize
ENDIF
ENDIF
IF newSL>0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
endif
if breakeaven>0 then
IF NOT ONMARKET THEN
breakevenLevel=0
ENDIF
IF LONGONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN
breakevenLevel = tradeprice(1)+PointsToKeep*pipsize
ENDIF
IF breakevenLevel>0 THEN
SELL AT breakevenLevel STOP
ENDIF
IF SHORTONMARKET AND tradeprice(1)-close>startBreakeven*pipsize THEN
breakevenLevel = tradeprice(1)-PointsToKeep*pipsize
ENDIF
IF breakevenLevel>0 THEN
EXITSHORT AT breakevenLevel STOP
ENDIF
ENDIF12/02/2022 at 11:20 AM #205166Use the default instruction for trailing stop in percent: https://www.prorealcode.com/documentation/percenttrailing/
or look in this thread, there are many version of trailing stop: https://www.prorealcode.com/topic/trailing-stop-and-breakeven-codes/
12/02/2022 at 11:49 AM #20516812/02/2022 at 12:00 PM #205173This a modified version of Nicolas’ code to use percentages:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152//*********************************************************************************// https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/// (lines 17- 56)// using Percentages////trailing stop function//StartPerCent = 0.5 //Trailing Stop will activate after 0.5% gainStepPerCent = 0.1 //Trailing Steps will occur at any further 0.1% gain//trailingstart = PositionPrice * StartPerCent / 100 / PipSizetrailingstep = PositionPrice * StepPerCent / 100 / PipSize////reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND close-PositionPrice>=trailingstart*pipsize THENnewSL = PositionPrice+trailingstep*pipsizeENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep*pipsize THENnewSL = max(newSL,newSL+trailingstep*pipsize)ENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND PositionPrice-close>=trailingstart*pipsize THENnewSL = PositionPrice-trailingstep*pipsizeENDIF//next movesIF newSL>0 AND newSL-close>=trailingstep*pipsize THENnewSL = min(newSL,newSL-trailingstep*pipsize)ENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIF//*********************************************************************************//graphonprice PositionPrice coloured("Blue")//graphonprice newSL coloured("Red")//graph TrailingStart//graph TrailingStep12/02/2022 at 12:12 PM #20517412/02/2022 at 3:56 PM #205187Don’t fool us, telling you are not the author of that file! 😆
It’s a pity for you to waste our time, just to disguise your advertising, and by using mutliple profiles on the website to hide yourself not being sufficiently good at math to convert points distance in percent. It is a shame.
-
AuthorPosts
Find exclusive trading pro-tools on