help with break-even code as a second position and second exit
Forums › ProRealTime English forum › ProOrder support › help with break-even code as a second position and second exit
- This topic has 38 replies, 3 voices, and was last updated 5 years ago by
robertogozzi.
Tagged: estimation, prc_qqe, qqe, qualitative, quantitative
-
-
11/28/2020 at 6:06 PM #152041
I’ve cleaned up the code and remove the exit indicator to see if the contracts continue but the code will continue to sell the second contract and that’s the one I want to allow it to run too continue basically i’ve added a picture and on the picture there’s a blue Arrow which shows a sell that is correct but there’s also a red arrow which also shows a sell I want to stop that one from happening
sys 236123456789101112131415161718192021222324// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Conditions to enter long positionsindicator1 = AroonUp[19]indicator2 = AroonDown[19]c1 = (indicator1 CROSSES OVER indicator2)IF c1 AND Not OnMarket THEN// Stops and targets : Enter your protection stops and profit targets hereSt = ROUND((AverageTrueRange[14](CLOSE))*2)Tp = ROUND((AverageTrueRange[14](CLOSE))*1.5)BUY 2 PERPOINT AT MARKETENDIF// targetIF Close >= (TradePrice + Tp) THENSELL 1 PERPOINT AT MARKETENDIF// StopsSET STOP LOSS St11/28/2020 at 8:27 PM #152047That’s because each time line 18 is executed, if conditions are still met, SELL will be executed again closing the second position.
To keep it running (until you add a condition to close it), replace line 18 with this one:
1IF Close >= (TradePrice + Tp) AND abs(CountOfPosition) = 2 THENso it will execute SELL only the first time.
1 user thanked author for this post.
11/28/2020 at 10:18 PM #152051That is absolutely brilliant thank you
11/29/2020 at 12:32 AM #152060I am so sorry to ask for more help with the same indicator,
sys 2371234567891011121314151617181920212223242526272829// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Conditions to enter short positionsindicator1 = CALL DDMIHL1c3 = (indicator1 CROSSES UNDER 0)IF c3 AND Not OnMarket THEN// Stops and targets : Enter your protection stops and profit targets hereSt = ROUND((AverageTrueRange[14](CLOSE))*2)Tp = ROUND((AverageTrueRange[14](CLOSE))*1.5)SELLSHORT 2 PERPOINT AT MARKETENDIFIF Close >= (TradePrice + Tp) AND abs(CountOfPosition) = 2 THENBUY 1 PERPOINT AT MARKETENDIF// Conditions to exit short positionsindicator3 = DI[10](close)indicator4 = WeightedAverage[11](DI[10](close))c4 = (indicator3 CROSSES OVER indicator4)IF c4 AND abs(CountOfPosition) = 1 THENBUY AT MARKETENDIF// Stops and targetsSET STOP LOSS StI can’t get the short side of a position to work not too sure what it is if you don’t mind thank you very much
11/29/2020 at 1:57 AM #152061I’ve played around with it I found the sell shorts and exit shorts were wrong but I believe the line 16 is not right for shorts i’ve adjusted that as well
sys 239123456789101112131415161718192021222324252627282930// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Conditions to enter long positionsindicator1 = CALL DDMIHL1c1 = (indicator1 CROSSES UNDER 0)IF c1 AND Not OnMarket THEN// Stops and targets : Enter your protection stops and profit targets hereSt = ROUND((AverageTrueRange[14](CLOSE))*2)Tp = ROUND((AverageTrueRange[14](CLOSE))*1.5)SELLSHORT 2 PERPOINT AT MARKETENDIFIF Close <= (TradePrice - Tp) AND abs(CountOfPosition) = 2 THENEXITSHORT 1 PERPOINT AT MARKETENDIF// Stops and targetsSET STOP LOSS St// Conditions to exit long positionsindicator3 = DI[10](close)indicator4 = WeightedAverage[11](DI[10](close))c2 = (indicator3 CROSSES OVER indicator4)IF c2 AND abs(CountOfPosition) = 1 THENEXITSHORT AT MARKETENDIF11/29/2020 at 2:29 AM #152063Yes, correct.
1 user thanked author for this post.
11/29/2020 at 11:09 PM #152152Hello i’m afraid that system that you have helped me build may have an underlying fault built into it or it might just be a part of the sellshort side of the code,
What I have is a screenshot the top 1 is the normal logic and the bottom one is the break-even and scale-out and as you can see the bottom one does not shortsell as much as I think it should and when you compare it to the normal logic it looks bad i’m wondering if there’s anything that can be done here, thannk youI will post both systems normal logic first then the break-even
normal logic1234567891011121314151617181920212223242526// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Conditions to enter long positionsindicator2, indicator1, ignored = CALL "PRC_QQE indicator"[5, 14, 4.236]c1 = (indicator1 CROSSES OVER indicator2)IF c1 THENBUY 1 PERPOINT AT MARKETENDIF// Conditions to enter short positionsindicator4, indicator3, ignored = CALL "PRC_QQE indicator"[5, 14, 4.236]c2 = (indicator3 CROSSES UNDER indicator4)IF c2 THENSELLSHORT 1 PERPOINT AT MARKETENDIF// Stops and targets : Enter your protection stops and profit targets hereSt = ROUND((AverageTrueRange[14](CLOSE))*2)Tp = ROUND((AverageTrueRange[14](CLOSE))*1.5)SET STOP LOSS StSET TARGET PROFIT Tpbreak-even12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788// Conditions to enter long positionsdefparam cumulateorders = falsestartBreakeven = TP //how much pips/points in gain to activate the breakeven function?PointsToKeep = 10 //how much pips/points to keep in profit above of below our entry price when the breakeven is activated (beware of spread)// Conditions to enter long positionsindicator2, indicator1, ignored = CALL "PRC_QQE indicator"[11, 14, 4.236]c1 = (indicator1 CROSSES OVER indicator2)if c1 AND Not OnMarket THEN// Stops and targets :St = ROUND((AverageTrueRange[14](CLOSE))*2)Tp = ROUND((AverageTrueRange[14](CLOSE))*1.5)BUY 2 PERPOINT AT MARKETSET STOP PLOSS St //first stoplossendif//reset the breakevenLevel when no trade are on marketIF NOT ONMARKET THENbreakevenLevel=0ENDIF// --- BUY SIDE ---//test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)+PointsToKeep*pipsizeENDIFIF LONGONMARKET AND Close >= (TradePrice + Tp) AND abs(CountOfPosition) = 2 THENSELL 1 PERPOINT AT MARKETENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevel>0 THENSELL AT breakevenLevel STOPENDIF// Conditions to exit long positionsindicator3, indicator4, ignored = CALL "PRC_QQE indicator"[11, 14, 4.236]B1 = (indicator4 CROSSES UNDER indicator3)IF B1 THENSELL AT MARKETENDIF// Conditions to enter short positions// Conditions to enter short positionsindicator1, indicator2, ignored = CALL "PRC_QQE indicator"[11, 14, 4.236]A1 = (indicator2 CROSSES UNDER indicator1)if A1 AND Not OnMarket THEN// Stops and targets :St = ROUND((AverageTrueRange[14](CLOSE))*2)Tp = ROUND((AverageTrueRange[14](CLOSE))*1.5)SELLSHORT 2 PERPOINT AT MARKETSET STOP PLOSS St //first stoplossendif//reset the breakevenLevel when no trade are on marketIF NOT ONMARKET THENbreakevenLevel=0ENDIF// --- Sell SIDE ---//test if the price have moved favourably of "startBreakeven" points alreadyIF SHORTONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)+PointsToKeep*pipsizeENDIFIF SHORTONMARKET AND Close <= (TradePrice - Tp) AND abs(CountOfPosition) = 2 THENEXITSHORT 1 PERPOINT AT MARKETENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevel>0 THENSELL AT breakevenLevel STOPENDIF// Conditions to exit short positionsindicator3, indicator4, ignored = CALL "PRC_QQE indicator"[11, 14, 4.236]B1 = (indicator4 CROSSES OVER indicator3)IF B1 THENEXITSHORT AT MARKETENDIF11/30/2020 at 12:21 AM #152157There’s always something to be done. If something doesn’t work as expected it’s just a matter of making it work!
Append these few lines at the end of your code:
1234Graph B1Graph abs(CountOfPosition)GraphOnPrice (TradePrice + Tp) coloured(0,255,0,255) AS "Long EXIT 1"GraphOnPrice (TradePrice - Tp) coloured(0,0,255,255) AS "Short EXIT 1"you will be able to see data plotted using GRAPH in the variable window of ProBackTest and data plotted using GRAPHONPRICE on your chart,candleby candle.
You will be able to detect any wrong value that may cause issues.
You can add more variables, if needed.
1 user thanked author for this post.
11/30/2020 at 1:30 AM #152164Definitely should be some shorts there you can see an August at the beginning of the chart there’s a crossover and it not on market yet no short and in September there’s a long where they shouldn’t be it goes long yet the qqe has not crossed over i’m going to test a different indicator “what if it’s the indicator”
11/30/2020 at 1:42 AM #152166Eureka I found it he was the indicator numbers
12/02/2020 at 1:48 AM #152363Hello I’ve noticed some anomalies on the chart and I’m not too sure what they are are I’ve uploaded a picture and I put red arrows on it they don’t affect the equity curve nor is there contracts for them i’m wondering if they can affect the trading backtest algorithm or if on market and the blue arrows show a buy but the conditions for the trade was not met the qqe did not crossover, i’m thinking that’s a problem with the code for the QQE or if it repainted.
sys 241123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100// Conditions to enter long positionsdefparam cumulateorders = falsestartBreakeven = TP //how much pips/points in gain to activate the breakeven function?PointsToKeep = 2 //how much pips/points to keep in profit above of below our entry price when the breakeven is activated (beware of spread)// Conditions to enter long positionsindicator2, indicator1, ignored = CALL "PRC_QQE indicator"[11, 20, 4.236]A1 = (indicator1 CROSSES OVER indicator2)indicator3 = Williams[8](close)A2 = (indicator3 >= -20)IF A1 AND A2 AND Not OnMarket THEN// Stops and targets :St = ROUND((AverageTrueRange[14](CLOSE))*2)Tp = ROUND((AverageTrueRange[14](CLOSE))*1.5)BUY 2 PERPOINT AT MARKETSET STOP PLOSS St //first stoplossendif//reset the breakevenLevel when no trade are on marketIF NOT ONMARKET THENbreakevenLevel=0ENDIF// --- BUY SIDE ---//test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)+PointsToKeep*pipsizeENDIFIF LONGONMARKET AND Close >= (TradePrice + Tp) AND abs(CountOfPosition) = 2 THENSELL 1 PERPOINT AT MARKETENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevel>0 THENSELL AT breakevenLevel STOPENDIF// Conditions to exit long positionsindicator5, indicator4, ignored = CALL "PRC_QQE indicator"[11, 20, 4.236]B1 = (indicator4 CROSSES UNDER indicator5)IF B1 THENSELL AT MARKETENDIF// Conditions to enter short positions// Conditions to enter short positionsindicator7, indicator6, ignored = CALL "PRC_QQE indicator"[11, 20, 4.236]C1 = (indicator6 CROSSES UNDER indicator7)indicator8 = Williams[8](close)C2 = (indicator8 <= -80)IF C1 AND C2 AND Not OnMarket THEN// Stops and targets :St = ROUND((AverageTrueRange[14](CLOSE))*2)Tp = ROUND((AverageTrueRange[14](CLOSE))*1.5)SELLSHORT 2 PERPOINT AT MARKETSET STOP PLOSS St //first stoplossendif//reset the breakevenLevel when no trade are on marketIF NOT ONMARKET THENbreakevenLevel=0ENDIF// --- Sell SIDE ---//test if the price have moved favourably of "startBreakeven" points alreadyIF SHORTONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)+PointsToKeep*pipsizeENDIFIF SHORTONMARKET AND Close <= (TradePrice - Tp) AND abs(CountOfPosition) = 2 THENEXITSHORT 1 PERPOINT AT MARKETENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevel>0 THENEXITSHORT AT breakevenLevel STOPENDIF// Conditions to exit short positionsindicator10, indicator9, ignored = CALL "PRC_QQE indicator"[11, 20, 4.236]D1 = (indicator9 CROSSES OVER indicator10)IF D1 THENEXITSHORT AT MARKETENDIFGraph B1Graph abs(CountOfPosition)GraphOnPrice (TradePrice + Tp) coloured(0,255,0,255) AS "Long EXIT 1"GraphOnPrice (TradePrice - Tp) coloured(0,0,255,255) AS "Short EXIT 1"thank you
12/02/2020 at 2:44 AM #152367You should duplicate line 5 and move one of them just after line 17 and the other one after line 62.
1 user thanked author for this post.
12/02/2020 at 2:33 PM #152411Hello thank you
I did that and had exactly the same results so no real effect by doing that
12/02/2020 at 4:04 PM #152419What is exactly the problòem where the arrows are plotted.
What date are those candles?
Since there’s no variable declared in the original indicator I don’t know in which order you arranged them, when you call the indicator, is the first parameter the RSIperiod?
12/02/2020 at 6:20 PM #152431Yeah sorry I did not know no what was causing that one contract to come into the market and then go out and like I said it was not affecting the equity curve and it wasn’t showing any contracts on the price chart those blue Arrows that I pointed out in the picture, so what I did I started to strip away at the code and take stuff off so I took the break-even off and that did not affect it and I simplified the code just long and it was still there it’s obvious now to me that is the take profit contract for some reason
I thank you very much for your help so far
-
AuthorPosts
Find exclusive trading pro-tools on