Probacktest errors on calculation of take profit and stop loss
Forums › ProRealTime English forum › ProOrder support › Probacktest errors on calculation of take profit and stop loss
- This topic has 14 replies, 4 voices, and was last updated 7 years ago by
Madrosat.
-
-
01/29/2018 at 10:37 PM #60902
Good evening to everybody.
I open this post because I was experimenting some systems when i have noticed some backtest errors on setting stop loss and take profit, so I’ve made a test with a simple breakout strategy and the errors keep on being.
The strategy is simple: I buy nextbaropen when price close over an highest[30](high)[1] and i set a stop loss at the lowest[10](low) and the same distance i set as take profit.
The system goes like this:
123456789101112defparam cumulateorders=falseentry=closeSL=entry-lowest[10](low)if entry>highest[30](high)[1]thenbuy 1 shares at marketset stop loss SLset target profit SLendifgraph (entry-SL) coloured(255,0,0) as "stoploss"graph (entry+SL) coloured(0,0,255) as "takeprofit"graph entry coloured(0,0,0) as "entry"I also set the graph to see how probuilder it calculates stop loss, entry and take profit and actually they are alright! (I also verified manually).
But then probacktest makes substantial mistakes on closing positions of 20 or 30 pips most of the times!
I’d like someone to verify and see some comments about.
I attach a screenshot with 2 examples of mistakes.
1° example: stop loss error
Graph levels:
1,1880 take profit
1,1824 entry
1,1768 stop loss
Probacktest enter buy correctly at 1,1824 but exit selling at 1,1740 that is 28 pips under where it should sell according to my stop loss that is 1,1768 and as you can see there’s no gaps around there.
2° example: take profit error
Graph levels:
1,1844 take profit
1,1787 entry
1,1730 stop loss
Probacktest enter buying correctly at 1,1787 but exit selling at 1,1822 that is 22 pips under to where it should sell according to my take profit that is 1,1844
I wait for some comments about, maybe I am mistaking or missing something.
Thanks a lot.
Max
01/29/2018 at 10:59 PM #6090601/29/2018 at 11:00 PM #60907All the calculations are done at the close of a candle so your SL will be the levels calculated at the candle one before the candle the position is closed in. Hover your mouse one candle back and I suspect the SL calculations will match the exit prices.
01/29/2018 at 11:19 PM #60908Thanks guys for the reply….
I have tested on some forex crosses, and many timeframes…the screenshots has been taken from EUR/USD timeframe 1 hour, with no spread and of tick by tick.
Vonasi, I also tried your advice but it’ doesn’t work the same.
Actually some trades works as I have set the graph, but are very few compared to all the other that fails of many pips.
If you have some moments take a look with probacktest.
Max
01/29/2018 at 11:40 PM #60910The price levels of stop loss and take profit shown on the graph are calculated on the “set up”candle that is when close[0] is highest than highest[30](high)[1] and therefore it’s prior to the entry being this at nextbaropen.
01/30/2018 at 12:14 AM #60913The SL will be recalculated at every candle that meets the conditions after a position has been opened – but the BUY instruction will be ignored due to DEFPARAM CumulateOrders = FALSE. You need to add an IF NOT ONMARKET condition if you want the SL to be kept at the level of the set up candle for the duration of the trade.
1 user thanked author for this post.
01/30/2018 at 7:39 AM #6092001/30/2018 at 8:36 AM #60931No problem Maximus78. It took me a while to realise that was what was happening when I first started writing strategies too.
…..and don’t forget that you can always press the ‘THANKS’ button on each post if think someone’s reply deserves it 🙂
1 user thanked author for this post.
01/30/2018 at 9:23 AM #60935Yes I actually use it but I thought it wasn’t strickly necessary to apply to only a Long strategy like this…
doing that i also used the instruction defparam cumulateorder false.
I have learned something new, still thanks!
Max
01/30/2018 at 9:57 AM #6093801/30/2018 at 1:10 PM #60965Hello madrosat,
you just have to add “if not onmarket” in the buy instructions to block the SL at the level of the set up candle for the duration of the trade,
if not the SL is recalculated at every candle that meets the conditions after a position has been opened.
So it goes like this:
12345678910111213defparam cumulateorders=falseentry=closeSL=entry-lowest[10](low)if not onmarket and entry>highest[30](high)[1]thenbuy 1 shares at marketset stop loss SLset target profit SLendifgraph (entry-SL) coloured(255,0,0) as "stoploss"graph (entry+SL) coloured(0,0,255) as "takeprofit"graph entry coloured(0,0,0) as "entry"01/30/2018 at 2:29 PM #60980369/5000Hello Maximus, Vonasi
I use when I’m long “if not longonmarket” the question I ask is that in case of long position the fact of putting” if not on market” in place of “if not longonmarket” changes something ???
The instruction longonmarket is taken at the opening of the candle following the entrance
I guess for ” if on market” it’s the same thing? yes, no?01/30/2018 at 5:24 PM #61006369/5000Hello Maximus, Vonasi I use when I’m long “if not longonmarket” the question I ask is that in case of long position the fact of putting” if not on market” in place of “if not longonmarket” changes something ??? The instruction longonmarket is taken at the opening of the candle following the entrance I guess for ” if on market” it’s the same thing? yes, no?Yes in this situation it does not matter if you use ONMARKET or LONGONMARKET the result is the same. ONMARKET checks for trades that are either long or short. LONGONMARKET only checks for long trades and SHORTONMARKET only checks for short trades.
01/31/2018 at 10:44 PM #61146Madrosat, as Vonasi said, in this case there’s no difference between if not onmarket and if not longonmarket because it’s a only long strategy.
There’s a difference when you use long and short strategies together.
If you use the command if not longonmarket with buy conditions and you are in a short trade, when the “buy conditions” are met, the system closes the short trade and immediately open the short trade, even if you didn’t hit stop loss or take profit, cause it takes in consideration only the fact that you are not longonmarket (actually you are shortonmarket).
If you use the command if not shortonmarket with sell conditions and you are in a long trade, when the “sell conditions” are met, the system closes the long trade and immediately open the short trade, even if you didn’t hit stop loss or take profit, cause it takes in consideration only the fact that you are not shortonmarket (actually you are longonmarket).
If you use if not on market, and you are in a long trade, when the “sell conditions” are met, the system will ignore it cause you are already “on market”, so the trade will be closed when stop loss or take profit will be hit.
The same happens when you are in a short trade and the system will ignore the “buy conditions” when they are met, so the trade will be closed when stop loss or take profit will be hit.
Maxx
1 user thanked author for this post.
02/01/2018 at 10:00 AM #61176 -
AuthorPosts
Find exclusive trading pro-tools on