How can I use Dynamic stop loss with my Code?
Forums › ProRealTime English forum › ProOrder support › How can I use Dynamic stop loss with my Code?
- This topic has 10 replies, 4 voices, and was last updated 2 years ago by robertogozzi.
-
-
10/13/2021 at 2:07 AM #179523this my code12345678910111213141516171819202122232425262728// Definition of code parametersDEFPARAM CumulateOrders = FALSE // Cumulating positions deactivatedtimeframe(DEFAULT)positionsize = 1// Conditions to enter long positionsmyPRCDynamicRSI, myPRCDynamicRSI2, myPRCDynamicRSI3, myPRCDynamicRSI4 = CALL "PRC_DynamicRSI"[0.1, 0.1, 14, 60]c1 = (myPRCDynamicRSI > myPRCDynamicRSI2)indicator1, indicator2, ignored = CALL "Terminus indicator"[9, 6, 3, 1, 0]c2 = (indicator1 CROSSES OVER indicator2)ignored, indicator3, indicator4 = CALL "Terminus indicator"[9, 6, 3, 1, 0]c3 = (indicator3 CROSSES OVER indicator4)IF c1 AND c2 AND C3 THENBUY positionsize CONTRACT AT MARKETSET STOP pTRAILING 4.0SET TARGET pPROFIT 3.0ENDIFC4 = (indicator1 > indicator2)C5 = (indicator3 > indicator4)C6 = (myPRCDynamicRSI CROSSES OVER myPRCDynamicRSI2)IF C4 AND C5 AND C6 THENBUY positionsize CONTRACT AT MARKETSET STOP pTRAILING 4.0SET TARGET pPROFIT 3.0ENDIF// EXIT LONG CONDITIONSIF LONGONMARKET AND (myPRCDynamicRSI CROSSES UNDER myPRCDynamicRSI2)THENSELL AT MARKETENDIFThis is Roperto's Dynamic stop loss123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051//******************************************************************************************************//// trailing stop functiontrailingstep = 5 //5 trailing step to move the "stoploss" after BreakEvenstartBreakeven = 5 //5 pips in gain to activate the breakeven functionPointsToKeep = 3 //3 pips to keep in profit above/below entry price when the breakeven is activated////reset the stoploss valueIF NOT ONMARKET THENnewSL = 0breakevenLevel = 0ENDIF//******************************************************************************************************// ----- BREAKEVEN code////reset the breakevenLevel when no trade are on market// --- LONG sideIF LONGONMARKET AND (close - tradeprice(1)) >= (startBreakeven * pipsize) AND breakevenlevel = 0 THENbreakevenLevel = tradeprice(1) + (PointsToKeep * pipsize) //calculate the breakevenLevelENDIF// --- SHORT sideIF SHORTONMARKET AND (tradeprice(1) - close) >= (startBreakeven * pipsize) AND breakevenlevel = 0 THENbreakevenLevel = tradeprice(1) + (PointsToKeep * pipsize) //calculate the breakevenLevelENDIF//Set new Stop LossIF breakevenLevel > 0 THENnewSL = BreakEvenLevelENDIF//******************************************************************************************************// ----- TRAILING STOP code////manage long positionsIF LONGONMARKET AND BreakEvenLevel THEN//next moves after BreakEvenIF newSL > 0 AND ((close - newSL) >= (trailingstep * pipsize)) THENnewSL = newSL + (trailingstep * pipsize)ENDIFENDIF//manage short positionsIF SHORTONMARKET AND BreakEvenLevel THEN//next moves after BreakEvenIF newSL > 0 AND ((newSL - close) >= (trailingstep * pipsize)) THENnewSL = newSL - (trailingstep * pipsize)ENDIFENDIF//stop order to exit the positionsIF newSL > 0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIF//******************************************************************************************************10/13/2021 at 8:56 AM #179539
Even if I understand what you want ask to us with your title, please describe it in your post content next time.
You have to remove all SET STOP TRAILING of your initial code and copy/paste Roberto’s code at the end. It should operate correctly this way.
1 user thanked author for this post.
10/13/2021 at 10:39 AM #17955810/13/2021 at 10:53 AM #17956010/13/2021 at 11:11 AM #17956110/13/2021 at 11:20 AM #179569Do not embed files of any kind in your post, as this slows down loading the pages.
Use the attach button only.
Thank you 🙂
10/13/2021 at 11:24 AM #179570When any code is not really huge (hundreds of lines), it’s advisable to copy and paste the code (along with the ITF file, if available). Thank you 🙂
This your indicator:
1234567891011121314151617181920212223242526// Author: Tom's - Leofi// Name: Terminus indicator// Description: Trend average indicator// Var indicatoremaSlow = Average[slow, type](close)emaNormal = Average[normal, type](close)emaFast = Average[fast, type](close)// Logicif (emaFast > emaNormal and emaNormal > emaSlow) thenbackgroundcolor(0,250,0)elsif (emaFast < emaNormal and emaNormal < emaSlow) thenbackgroundcolor(250,0,0)elsebackgroundcolor(250,165,0)endif// Boolean draw indicatorif (drawIndicator) thenindicatorAlpha = 250elseindicatorAlpha = 0endifreturn emaFast coloured(200, 200, 200, indicatorAlpha) STYLE(line, 2) as "Fast Average 0", emaNormal coloured(80, 80, 80, indicatorAlpha) STYLE(line, 2) as "Normal Average 1", emaSlow coloured(0, 0, 0, indicatorAlpha) STYLE(line, 2) as "Slow Average 2"1 user thanked author for this post.
10/13/2021 at 11:32 AM #17957110/13/2021 at 11:39 AM #179573Yes, but to test it we needed the code.
It may work while backtesting, not in autotrading, as the trailing stop seems too tight.
Post details about any issues you have experienced with the above code.10/13/2021 at 1:15 PM #179585Hi Roberto,
It seems that this dynamic stop loss works only when the price is above breakeven level, but it doesn’t provide protection initial stop loss and and then trail, is there a chance to add protection stop loss and then work as dynamic??
10/13/2021 at 3:08 PM #179594This is not a STOP LOSS, your strategy needs to take care of that.
It’s a trailing stop, so it starts working AFTER having gained at least trailingstep pips (at the closing of the bar).
Keep SET TARGET pPROFIT and replace SET STOP pTRAILING with SET STOP pLOSS (usually TP is at least 1.5+ times the SL).
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on