Multiple entry executions but only trailing SL on one
Forums › ProRealTime English forum › ProOrder support › Multiple entry executions but only trailing SL on one
- This topic has 14 replies, 4 voices, and was last updated 1 month ago by Crazzycameel.
-
-
11/15/2024 at 3:33 PM #240405
Hello!
I am currently working on a long only strategy, where I have two different entry executions, for reference they look like this:
entry method 1:
1234567if time >= timestart and time < timeend thenIF DAYCALL and bulltrend and golong and CB1H and close > entry1 and not longonmarket thenbuy positionsize contract at marketSET STOP %LOSS 1.3SET TARGET %PROFIT 2.15ENDIFENDIFand
entry method 2:
12345if DAYCALL and Rev1 and BollTrig0 and trendup and not longonmarket thenbuy positionsize contract at marketSET STOP %LOSS 1.3SET TARGET %PROFIT 2.15ENDIFcurrently I am managing stoploss with a trailing SL that looks like this:
1234567891011121314151617181920212223242526//trailing stop functiontrailingstart = 20 //trailing will start @trailinstart points profittrailingstep = 6 //trailing step to move the "stoploss"//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first moveIF 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//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPENDIFhowever this makes it so that applies to both entry methods, I would only like to have trailing SL for entry method 1, where as entry method 2, i just want SL to be put breakeven and never move again.
Is there any solution to distinguish this?
best regards
Jonathan
11/16/2024 at 3:35 PM #240410You could run two separate strategies? Keep it simple.
11/16/2024 at 9:10 PM #240415unfortunately not, as i dont want there to be a scenario where they execute at the same time
11/16/2024 at 9:35 PM #240416Try …
123456789101112131415161718192021222324252627282930313233343536Method1 = 1If Method1 Thenif time >= timestart and time < timeend thenIF DAYCALL and bulltrend and golong and CB1H and close > entry1 and not longonmarket thenbuy positionsize contract at marketSET STOP %LOSS 1.3SET TARGET %PROFIT 2.15ENDIFENDIF//trailing stop functiontrailingstart = 20 //trailing will start @trailinstart points profittrailingstep = 6 //trailing step to move the "stoploss"//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first moveIF 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//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPENDIFENDIF11/16/2024 at 11:02 PM #240417does unfortunately not do it. Method 2 still trails the stoploss the same way. but i think you you’re onto something about defining the different methods to split them up, im just not very experience on that end yet
11/17/2024 at 9:01 AM #240419123456789101112131415161718192021222324252627282930313233343536373839404142434445Method1 = 1If Method1 Thenif time >= timestart and time < timeend thenIF DAYCALL and bulltrend and golong and CB1H and close > entry1 and not longonmarket thenbuy positionsize contract at marketSET STOP %LOSS 1.3SET TARGET %PROFIT 2.15ENDIFENDIF//trailing stop functiontrailingstart = 20 //trailing will start @trailinstart points profittrailingstep = 6 //trailing step to move the "stoploss"//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first moveIF 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//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPENDIFENDIFMethod2 = 1If Method2 Thenif DAYCALL and Rev1 and BollTrig0 and trendup and not longonmarket thenbuy positionsize contract at marketSET STOP %LOSS 1.3SET TARGET %PROFIT 2.15ENDIFENDIF11/17/2024 at 9:30 AM #240420Try below to only take a position under one Method … I’ve not tested and not had coffee yet! 🙂
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647Method1 = 1If Method1 Thenif time >= timestart and time < timeend thenIF DAYCALL and bulltrend and golong and CB1H and close > entry1 and not longonmarket thenbuy positionsize contract at marketMethod2 = 0SET STOP %LOSS 1.3SET TARGET %PROFIT 2.15ENDIFENDIF//trailing stop functiontrailingstart = 20 //trailing will start @trailinstart points profittrailingstep = 6 //trailing step to move the "stoploss"//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first moveIF 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//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPENDIFENDIFMethod2 = 1If Method2 Thenif DAYCALL and Rev1 and BollTrig0 and trendup and not longonmarket thenbuy positionsize contract at marketMethod1 = 0SET STOP %LOSS 1.3SET TARGET %PROFIT 2.15ENDIFENDIF11/17/2024 at 10:53 AM #240424Just had a shot of caffeine, this should work better (not tested) …
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051If NOT onmarket ThenMethod1 = 1Method2 = 1If Method1 Thenif time >= timestart and time < timeend thenIF DAYCALL and bulltrend and golong and CB1H and close > entry1 and not longonmarket thenbuy positionsize contract at marketMethod2 = 0SET STOP %LOSS 1.3SET TARGET %PROFIT 2.15ENDIFENDIF//trailing stop functiontrailingstart = 20 //trailing will start @trailinstart points profittrailingstep = 6 //trailing step to move the "stoploss"//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first moveIF 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//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPENDIFENDIFMethod2 = 1If Method2 Thenif DAYCALL and Rev1 and BollTrig0 and trendup and not longonmarket thenbuy positionsize contract at marketMethod1 = 0SET STOP %LOSS 1.3SET TARGET %PROFIT 2.15ENDIFENDIFENDIF2 users thanked author for this post.
11/17/2024 at 11:09 AM #24042911/17/2024 at 1:49 PM #24043411/17/2024 at 3:22 PM #240438So here we are, a question that is relevant to this Topic … using Nicolas Trailing Stop (as in the code above) with SELL AT newSL STOP at Line 38 … will the SET STOP %LOSS 1.3 at Line 10 still work?
OR will the ‘Line 38 Stop instruction’ cancel / make redundant the ‘Line 10 Stop Instruction’??
Anybody know or hazard a guess?
11/17/2024 at 3:53 PM #240439Have dropped the ITF below, and the full strategy code following:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107//RUNS ON 1HOUR TIMEFRAMEdefparam cumulateorders = falsedefparam preloadbars = 10000positionsize = 8timestart = 090000timeend = 220000TIMEFRAME (DAILY)clxd, ignored, ignored, ignored, ignored, ignored, ignored, ignored, ignored, ignored, ignored, ignored, ignored, ignored, ignored = CALL "Clean SP x ML ON v2 Indicator"TIMEFRAME (DAILY, updateonclose)ignored, nobuy, dshortframe, dlongframe, bulltrend, DaytriggerBULL, DAYCALL, ignored, ignored, ignored,ignored, ignored, ignored, ignored, ignored = CALL "Clean SP x ML ON v2 Indicator"TIMEFRAME (4 hour)ignored, ignored, ignored, ignored, ignored, ignored, ignored, clx4, ignored, ignored, ignored, ignored, ignored, ignored, ignored = CALL "Clean SP x ML ON v2 Indicator"TIMEFRAME (DEFAULT)ignored, ignored, ignored, ignored, ignored, ignored, ignored, ignored, cp, CB1H, entry1, Rev1, BollTrig0, trendup, nodayentry = CALL "Clean SP x ML ON v2 Indicator"golong = (close < nobuy)//ENTRY METHOD 1if time >= timestart and time < timeend thenIF DAYCALL and bulltrend and golong and CB1H and close > entry1 and not longonmarket thenbuy positionsize contract at marketSET STOP %LOSS 1.3SET TARGET %PROFIT 2.15ENDIFENDIF//ENTRY METHOD 2if DAYCALL and Rev1 and BollTrig0 and trendup and not longonmarket thenbuy positionsize contract at marketSET STOP %LOSS 1.3SET TARGET %PROFIT 2.15ENDIF//TRAILING STOP function. WANT TO USE THIS ONE FOR METHOD 1.trailingstart = 20 //trailing will start @trailinstart points profittrailingstep = 6 //trailing step to move the "stoploss"//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first moveIF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THENnewSL = tradeprice(1)+trailingstep*pipsize //(minus för att pris ska bli BE på execution, eftersom både denna och den undre exekverar+6 i första rörelsen)ENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep*pipsize THENnewSL = newSL+trailingstep*pipsizeENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPENDIF//BREAKEVEN function. WANT TO USE THIS ONE FOR METHOD 2.once breakeven1 =1if breakeven1 thenbreakevenPC = 0.4PointsToKeep = (tradeprice(1)*(0.032/100))startBreakeven = tradeprice(1)*(breakevenPC/100)if breakeven1>0 thenIF NOT ONMARKET THENbreakevenLevel=0ENDIFIF LONGONMARKET AND high-tradeprice(1)>=startBreakeven*pipsize THENbreakevenLevel = tradeprice(1)+PointsToKeep*pipsizeENDIFIF breakevenLevel>0 THENSELL AT breakevenLevel STOPENDIFendifendif//OTHER EXITSif longonmarket and abs(open-close)<1 and high<high[1] and positionperf>0 and high-close>2.75 thensell at marketendifOTD = Barindex - TradeIndex(1) > IntradayBarIndexif longonmarket and clxd and clx4 and positionperf < 0 and OTD and not nodayentry thensell at marketendifHave not yet tried out the alternatives you have dropped during the day as i am on the run for a bit, but will hopefully get a few hours this evening. I appreciate the help big time, mate
1 user thanked author for this post.
11/17/2024 at 4:15 PM #24044111/17/2024 at 8:30 PM #240445using Nicolas Trailing Stop
Does not cancel / make redundant a Set Stop %Loss or Set Stop pLoss instruction.
11/17/2024 at 8:35 PM #240446The following code does it for me:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182If NOT onmarket ThenMethod1 = 1Method2 = 1ENDIF//ENTRY METHOD 1If Method1 Thenif time >= timestart and time < timeend thenIF DAYCALL and bulltrend and golong and CB1H and close > entry1 and not longonmarket thenbuy positionsize contract at marketMethod2 = 0SET STOP %LOSS 1.3SET TARGET %PROFIT 2.15ENDIFENDIFENDIF//TRAILING STOP function FOR METHOD 1trailingstart = 20 //trailing will start @trailinstart points profittrailingstep = 6 //trailing step to move the "stoploss"///reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF///manage long positionsIF LONGONMARKET and Method1 THEN//first moveIF 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///stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPENDIF//ENTRY METHOD 2If Method2 Thenif DAYCALL and Rev1 and BollTrig0 and trendup and not longonmarket thenbuy positionsize contract at marketMethod1 = 0SET STOP %LOSS 1.3SET TARGET %PROFIT 2.15ENDIFENDIF//BREAKEVEN function FOR METHOD 2.once breakeven1 =1if breakeven1 thenbreakevenPC = 0.4PointsToKeep = (tradeprice(1)*(0.032/100))startBreakeven = tradeprice(1)*(breakevenPC/100)if breakeven1>0 thenIF NOT ONMARKET THENbreakevenLevel=0ENDIFIF LONGONMARKET and Method2 = 1 AND high-tradeprice(1)>=startBreakeven*pipsize THENbreakevenLevel = tradeprice(1)+PointsToKeep*pipsizeENDIFIF breakevenLevel>0 THENSELL AT breakevenLevel STOPENDIFendifendif//GRAPH Method1 coloured ("red")//GRAPH Method2 coloured ("blue")//graphonprice newSL coloured ("green")//graphonprice breakevenLevel coloured ("fuchsia")1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on