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/22/2020 at 10:40 PM #151247
Hello
help with break-even code as a second position and second exit
I have conditions to go long and conditions to go short and I have exit conditions which is a stop loss and take profit but what i would like to try and do, If the take profit is activated is to have a second contract (pound per point) which would have a break-even at entry and a second exit condition to specifically for the second contract (pound per point). C3 and C6 Should be the exit for the second contract I would like this to happen if the TP is hit not before
I have seen and read (Breakeven code for your automated trading strategy) but I do not know how to implement it
Hopefully I’ve explained it well enough 2 contracts one gets sold at a Take profit the second one is allowed to continue until the macd crosses or break even is hit
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Conditions to enter long positionsindicator1 = CALL HLAroon[70]c1 = (indicator1 > 0)indicator2 = CALL HLAroon[19]c2 = (indicator2 CROSSES OVER 0)IF c1 AND c2 THENBUY 2 PERPOINT AT MARKETENDIF// Conditions to exit long positionsindicator3 = MACDline[6,19,9](close)indicator4 = ExponentialAverage[9](MACDline[6,19,9](close))c3 = (indicator3 CROSSES UNDER indicator4)IF NOT ShortOnMarket AND c3 THENSELL AT MARKETENDIF// Conditions to enter short positionsindicator5 = CALL HLAroon[70]c4 = (indicator5 < 0)indicator6 = CALL HLAroon[19]c5 = (indicator6 CROSSES UNDER 0)IF NOT LongOnMarket AND c4 AND c5 THENSELLSHORT 2 PERPOINT AT MARKETENDIF// Conditions to exit short positionsindicator7 = MACDline[6,19,9](close)indicator8 = ExponentialAverage[9](MACDline[6,19,9](close))c6 = (indicator7 CROSSES OVER indicator8)IF c6 THENEXITSHORT 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 Tp11/27/2020 at 5:24 PM #151943I think I posted this in the wrong place
11/27/2020 at 5:29 PM #151945i have been trying with the Breakeven code but i find it hard to do what i want,
On the second position I would like it to exit with an indicator after Break even has been activated
11/27/2020 at 5:38 PM #151946123456789101112131415161718192021222324252627282930313233343536373839404142434445464748// Conditions to enter long positionsindicator1 = AroonUp[19]indicator2 = AroonDown[19]c1 = (indicator1 CROSSES OVER indicator2)if c1 thenBUY 2 LOT AT MARKETSET STOP PLOSS Tp //first stoplossendif// --- BUY SIDE ---//test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET AND TP>=startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)+PointsToKeep*pipsizeENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevel>0 THENSELL AT breakevenLevel STOPENDIF// --- end of BUY SIDE ---// Conditions to exit 2nd Long positionsindicator3 = AroonUp[19]indicator4 = AroonDown[19]c2 = (indicator3 CROSSES UNDER indicator4)IF c2 THENSELL 1 LOT 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 Tp//reset the breakevenLevel when no trade are on marketIF NOT ONMARKET THENbreakevenLevel=0ENDIF11/27/2020 at 6:20 PM #151949That one above is wrong sorry i’ve tried it this way it below but it’s still not right
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253defparam cumulateorders = falsestartBreakeven = Tp //how much pips/points in gain to activate the breakeven function?PointsToKeep = 5 //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 positionsindicator1 = AroonUp[19]indicator2 = AroonDown[19]c1 = (indicator1 CROSSES OVER indicator2)// Conditions to exit 2nd Long positionsindicator3 = AroonUp[19]indicator4 = AroonDown[19]c2 = (indicator3 CROSSES UNDER indicator4)if c1 thenBUY 2 LOT AT MARKETSET STOP PLOSS St //first stoplossendifIF LongOnMarket AND c2 THENSELL 1 LOT AT MARKETENDIFIF LongOnMarket AND Tp THENSELL 1 LOT AT MARKETENDIFIF LongOnMarket AND St THENSELL 2 LOT AT MARKETENDIF//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*pipsizeENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevel>0 THENSELL AT breakevenLevel STOPENDIF// --- end of BUY SIDE ---// Stops and targets : Enter your protection stops and profit targets hereSt = ROUND((AverageTrueRange[14](CLOSE))*2)Tp = ROUND((AverageTrueRange[14](CLOSE))*1.5)11/27/2020 at 6:33 PM #151951i think iv got
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051startBreakeven = Tp //how much pips/points in gain to activate the breakeven function?PointsToKeep = 5 //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 positionsindicator1 = AroonUp[19]indicator2 = AroonDown[19]c1 = (indicator1 CROSSES OVER indicator2)// Conditions to exit 2nd Long positionsindicator3 = AroonUp[19]indicator4 = AroonDown[19]c2 = (indicator3 CROSSES UNDER indicator4)if c1 thenBUY 2 LOT AT MARKETSET STOP PLOSS St //first stoplossendifIF LongOnMarket AND c2 THENSELL 1 LOT AT MARKETENDIFIF LongOnMarket AND Tp THENSELL 1 LOT AT MARKETENDIF//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*pipsizeENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevel>0 THENSELL 1 LOT AT breakevenLevel STOPENDIF// --- end of BUY SIDE ---// 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 St11/27/2020 at 7:41 PM #151962Nope that’s not right either i’ll try again with just the break-even
11/27/2020 at 9:09 PM #151966I’ll try and explain what I’m doing better I want to buy or sell two lots or contracts or pounds per points,
- with a take profit condition for 1 lot (AverageTrueRange[14](CLOSE))*1.5)
- with a stop loss condition for 2 lots (AverageTrueRange[14](CLOSE))*2)
- with a break-even condition for 1 lot after take profit is hit
- With a exit condition to let the 2nd lot run for more profit
Below is all the code that I have for this and is not in working condition I’ve
1234567891011121314151617181920212223242526272829303132333435363738394041424344defparam cumulateorders = falsestartBreakeven = 30 //how much pips/points in gain to activate the breakeven function?PointsToKeep = 5 //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 positions 2 lotsindicator1 = AroonUp[19]indicator2 = AroonDown[19]c1 = (indicator1 CROSSES OVER indicator2)// Conditions to exit 1st Long positions breakeven should be Activated at this pointTp = ROUND((AverageTrueRange[14](CLOSE))*1.5)// Conditions to exit 2nd Long positions should be the average from entry candelindicator2 = MACDline[6,19,9](close)indicator3 = ExponentialAverage[9](MACDline[6,19,9](close))c2 = (indicator2 CROSSES UNDER indicator3)// Conditions stop loss for 2 lots Long positions should be the average from entry candelSt = ROUND((AverageTrueRange[14](CLOSE))*2)// Conditions for breakeven Long positionsif c1 thenBUY 2 LOT AT MARKETSET STOP PLOSS stendif//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*pipsizeENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevel>0 THENSELL 1 LOT AT breakevenLevel STOPENDIF// --- end of BUY SIDE ---just laid it out to make it simple
11/27/2020 at 10:55 PM #151970Giving it my best shot and I’m still falling short,
I don’t know if it’s the break-evensys 224123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051defparam 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 positions 2 lotsindicator1 = AroonUp[19]indicator2 = AroonDown[19]c1 = (indicator1 CROSSES OVER indicator2)if c1 thenBUY 2 LOT AT MARKETSET STOP LOSS stendif//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*pipsizeENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevel>0 THENSELL 1 LOT AT breakevenLevel STOPENDIF// Conditions to exit 1st Long positions breakeven should be Activated at this pointIF LongOnMarket AND Tp THENSELL 1 LOT AT MARKETENDIF// Conditions to exit 2nd Long positionsindicator4 = MACDline[22,46,9](close)indicator5 = ExponentialAverage[9](MACDline[6,19,9](close))c2 = (indicator4 CROSSES UNDER indicator5)IF LONGONMARKET AND c2 THENSELL AT MARKETENDIF// --- end of BUY SIDE ---// Stops and targets : Enter your protection stops and profit targets hereTp = ROUND((AverageTrueRange[14](CLOSE))*1.5)St = ROUND((AverageTrueRange[14](CLOSE))*2)or all the take profit or the stop loss that’s causing the trade to end too soon
11/27/2020 at 11:40 PM #151973I’ve tried a more simpler system without the break-even i’m still having issues it turns out it’s the take profit that’s causing the issue I don’t know what to do from here
sys229123456789101112131415161718192021222324252627282930// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Conditions to enter long positionsindicator1 = CALL HLAroon[19]c1 = (indicator1 CROSSES OVER 0)IF c1 THENBUY 2 PERPOINT AT MARKETENDIF// Conditions to exit long positionsindicator2 = MACDline[22,46,9](close)indicator3 = ExponentialAverage[9](MACDline[22,46,9](close))c2 = (indicator2 CROSSES UNDER indicator3)IF c2 THENSELL AT MARKETENDIFIF Tp THENSELL 1 PERPOINT AT MARKETENDIF// Stops and targets : Enter your protection stops and profit targets hereSt = ((AverageTrueRange[14](CLOSE))*2)Tp = ROUND((AverageTrueRange[14](CLOSE))*1.5)SET STOP LOSS St11/28/2020 at 12:25 AM #151974Yes, Take Profit is the issue, you forgot to add
1SET TARGET PROFIT Tpline 21 doesn’t make sense, you are making a logical comparison with TP which does not retain a logical value. Use the above line as line 29, instead.
11/28/2020 at 2:29 AM #151980but I only want it to sell half
11/28/2020 at 9:07 AM #151986Then change line line 21 to:
1IF Close >= (TradePrice + Tp) THENbut beware that your SL and TP changes every candle. I don’t know if that is what you want.
11/28/2020 at 2:09 PM #152011Is it at all possible to fix it to the candle that open the trade
11/28/2020 at 3:35 PM #152024Yes, you need to place their calculation within the conditions to enter a trade, along with the keyword NOT ONMARKET to make sure they are not changed while the trade is open:
12345678910111213141516171819202122232425262728// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Conditions to enter long positionsindicator1 = CALL HLAroon[19]c1 = (indicator1 CROSSES OVER 0)IF c1 AND Not OnMarket THEN// Stops and targets : Enter your protection stops and profit targets hereSt = ((AverageTrueRange[14](CLOSE))*2)Tp = ROUND((AverageTrueRange[14](CLOSE))*1.5)BUY 2 PERPOINT AT MARKETENDIF// Conditions to exit long positionsindicator2 = MACDline[22,46,9](close)indicator3 = ExponentialAverage[9](MACDline[22,46,9](close))c2 = (indicator2 CROSSES UNDER indicator3)IF c2 AND LongOnMarket THENSELL AT MARKETENDIFIF Close >= (TradePrice + Tp) THENSELL 1 PERPOINT AT MARKETENDIFSET STOP LOSS St1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on