Stoploss and breakeven not working.
Forums › ProRealTime English forum › ProOrder support › Stoploss and breakeven not working.
- This topic has 9 replies, 3 voices, and was last updated 6 years ago by
robertogozzi.
-
-
09/03/2019 at 6:05 PM #106387
Hello guys, I would appreciate some help as I have a strategy that works fine when I do a backtest but it fails on live market. For some reason out of my knowledge the stoploss order at breakeven doesnt work. In the attached files, picture 1 shows how the order closed once it touched the stoploss at breakeven. But, in picture 2, the long trade is still ongoing in real market. Thank you very much for your help. Regards Manuel
Breakeven stop loss doesnt work1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465DEFPARAM CumulateOrders = false // Acumulación de posiciones desactivadamedia=30 //average to useunits=5 //units to buy or selltakeprofit = 100 //takeprofit in pointsstoploss = 100 //stoploss in pointsBreakevenAt = 25 //percent achieved of target to move stop to entry (breakeven)PointsToKeep = 1 //how much points to keep in profit above of below our entry price when the breakeven is activated (beware of spread)// Condiciones para entrada de posiciones largasindicator1 = ExponentialAverage[media](close)indicator2 = ExponentialAverage[media*2](close)c1 = (indicator1 > indicator2)indicator3 = ExponentialAverage[media*2](close)c2 = (close < indicator3)IF c1 AND c2 THENBUY units CONTRACT AT MARKETSET STOP pTRAILING stoplossENDIF// Condiciones de entrada de posiciones cortasindicator6 = ExponentialAverage[media](close)indicator7 = ExponentialAverage[media*2](close)c4 = (indicator6 < indicator7)indicator8 = ExponentialAverage[media*2](close)c5 = (close > indicator8)IF c4 AND c5 THENSELLSHORT units CONTRACT AT MARKETSET STOP pTRAILING stoplossENDIF//reset the breakevenLevel when no trade are on marketIF NOT ONMARKET THENbreakevenLevel=0ENDIFstartBreakeven = takeprofit*(BreakevenAt/100)//how much points in gain to activate the breakeven function// --- 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 LONGONMARKET AND breakevenLevel>0 THENSELL AT breakevenLevel STOPENDIF// --- SELL SIDE ---//test if the price have moved favourably of "startBreakeven" points alreadyIF SHORTONMARKET AND tradeprice(1)-close>=startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)-PointsToKeep*pipsizeENDIF//place the new stop orders on market at breakevenLevelIF SHORTONMARKET AND breakevenLevel>0 THENEXITSHORT AT breakevenLevel STOPENDIFgraphonprice breakevenlevel as "Breakeven"09/03/2019 at 6:07 PM #106390Sorry, forgot to attach the pictures.
09/03/2019 at 6:43 PM #106396What you are doing wrong is posting in the wrong forum and not giving your topic a meaningful title! 🙂
I will move it to the ProOrder forum as it is a strategy question. I will also give it a more meaningful title than ‘What am I doing wrong?’
09/03/2019 at 6:53 PM #106402You are right. Sorry about that.
The topic reflects my frustration but it doesn’t help other users to identify what the question is about.
Thanks09/04/2019 at 10:35 AM #106454Unfortunately your pics don’t show the date and time when the trade entered, so I cannot find them to replicate your situation.
09/04/2019 at 12:22 PM #106476Entry on DAX, yesterday 03/09/19 at 10 am. See attached picture for more details.
The black point show where the trade should have closed.
Regards
Manuel
09/04/2019 at 2:11 PM #106491Hi,
I have been working on a coded version for a trailing stop without using SET STOP pTRAILING. Unfortunately, results are not the same.
I would appreciate if anyone can help to code a trailing stop which that the same that my original code.
Option 1: original code using SET STOP pTRAILING
Option1: Using SET STOP pTRAILING1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465DEFPARAM CumulateOrders = false // Acumulación de posiciones desactivadamedia=30 //average to useunits=5 //units to buy or selltakeprofit = 100 //takeprofit in pointsstoploss = 100 //stoploss in pointsBreakevenAt = 25 //percent achieved of target to move stop to entry (breakeven)PointsToKeep = 1 //how much points to keep in profit above of below our entry price when the breakeven is activated (beware of spread)// Condiciones para entrada de posiciones largasindicator1 = ExponentialAverage[media](close)indicator2 = ExponentialAverage[media*2](close)c1 = (indicator1 > indicator2)indicator3 = ExponentialAverage[media*2](close)c2 = (close < indicator3)IF c1 AND c2 THENBUY units CONTRACT AT MARKETSET STOP pTRAILING stoplossENDIF// Condiciones de entrada de posiciones cortasindicator6 = ExponentialAverage[media](close)indicator7 = ExponentialAverage[media*2](close)c4 = (indicator6 < indicator7)indicator8 = ExponentialAverage[media*2](close)c5 = (close > indicator8)IF c4 AND c5 THENSELLSHORT units CONTRACT AT MARKETSET STOP pTRAILING stoplossENDIF//reset the breakevenLevel when no trade are on marketIF NOT ONMARKET THENbreakevenLevel=0ENDIFstartBreakeven = takeprofit*(BreakevenAt/100)//how much points in gain to activate the breakeven function// --- 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 LONGONMARKET AND breakevenLevel>0 THENSELL AT breakevenLevel STOPENDIF// --- SELL SIDE ---//test if the price have moved favourably of "startBreakeven" points alreadyIF SHORTONMARKET AND tradeprice(1)-close>=startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)-PointsToKeep*pipsizeENDIF//place the new stop orders on market at breakevenLevelIF SHORTONMARKET AND breakevenLevel>0 THENEXITSHORT AT breakevenLevel STOPENDIFgraphonprice breakevenlevel as "Breakeven"Option 2: new code without using SET STOP pTRAILING
Option 2123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081DEFPARAM CumulateOrders = false // Acumulación de posiciones desactivadamedia= 30 //average to useunits= 5 //units to buy or sellstoploss = 100 //initial stoploss in pointstrailingstart = 25 //trailing will start @trailinstart points profittrailingstep = 100 //trailing step to move the stoplosspointstokeep = 5 //how much points to keep in profit above of below our entry price when the breakeven is activated (beware of spread)// Condiciones para entrada de posiciones largasindicator1 = ExponentialAverage[media](close)indicator2 = ExponentialAverage[media*2](close)c1 = (indicator1 > indicator2)indicator3 = ExponentialAverage[media*2](close)c2 = (close < indicator3)IF c1 AND c2 THENBUY units CONTRACT AT MARKETENDIF// Condiciones de entrada de posiciones cortasindicator6 = ExponentialAverage[media](close)indicator7 = ExponentialAverage[media*2](close)c4 = (indicator6 < indicator7)indicator8 = ExponentialAverage[media*2](close)c5 = (close > indicator8)IF c4 AND c5 THENSELLSHORT units CONTRACT AT MARKETENDIF//reset the stoploss valueIF NOT ONMARKET THENnewSL=0InitialSL=0ENDIF//manage long positionsIF LONGONMARKET THENIF InitialSL = 0 THENInitialSL = tradeprice(1) - stoploss*pipsizeEndif//first move (breakeven)IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THENnewSL = tradeprice(1)+pointstokeep*pipsizeENDIF//next movesIF newSL>0 AND high-newSL>=trailingstep*pipsize THENnewSL = high - trailingstep*pipsizeENDIFENDIF//manage short positionsIF SHORTONMARKET THENIF InitialSL = 0 THENInitialSL = tradeprice(1) + stoploss*pipsizeEndif//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THENnewSL = tradeprice(1)-pointstokeep*pipsizeENDIF//next movesIF newSL>0 AND newSL-low>=trailingstep*pipsize THENnewSL = low + trailingstep*pipsizeENDIFENDIF//stop order to exit the positionsIF onmarket and newSL=0 thenSELL AT InitialSL STOPEXITSHORT AT InitialSL STOPENDIFIF onmarket and newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIFGraphonprice InitialSL coloured (220,100,100)as "Initial SL"Graphonprice newSL as "Trailing SL"09/04/2019 at 2:49 PM #106495The trade you mentioned closed as due at the breakeven level your code calculated.
09/04/2019 at 3:29 PM #106505In a backtest YES, but in real market it doesnt work.
Picture 1 shows the same results than you. Trade closed at breakeven.
Picture 2 shows how the trade is still ongoing and the stop loss at breakeven was not respected.
09/05/2019 at 8:19 AM #106547I cannot replicate the live trade, but trying to figure out what the reason could have bean, the only issue could have been having a breakevenlevel price too close to the closing price when the pending stop order is placed. But it isn’t, the difference was about 14 pips and I don’t think there could have been such a high requirement at that time, unless there were some scheduled incoming news that might have increased volatility and the broker might have raised the distance requirements to a much higher value.
I can’t think of anything else.
I suggest that you hit Ctrl+M from the platform and send a request for assistance with the above details.
-
AuthorPosts
Find exclusive trading pro-tools on