Breakout system error backtest
Forums › ProRealTime English forum › ProOrder support › Breakout system error backtest
- This topic has 4 replies, 3 voices, and was last updated 6 years ago by
maximus78.
-
-
02/07/2019 at 10:17 PM #90787
Hello guys, I was trying a strategy and I realized that probacktest does not make the entries correctly.
I have simplified the strategy in order to understand where the setup errors are:
Forex, 1 hour chart
If the price of the 2nd candle (01:00) exceeds the highest of the first candle (00:00) of 1 pip, enter long.
If the price of the 2nd candle exceeds the minimum of first candle of 1 pip, enter short.
It automatically exits at open of the next candle.
The problem is that, when the 2nd candle exceeds both the previous high and low, probacktest enters both long and short, while I want it to enter only once, at the first break that occurs.
The code perfectly executes entries in separate long and short systems and even intradaybarindex = 0 is correct.
I attach the code, I cannot understand where I’m wrong … ..
Thanks in advance to everyone for the help!
1234567891011121314151617181920defparam cumulateorders=falseentrylong=highest[1](high)entryshort=lowest[1](low)if not onmarket and intradaybarindex=0 and entrylong thenbuy 1 shares at entrylong +(1*pointsize) stopendifif longonmarket thensell at marketendifif not onmarket and intradaybarindex=0 and entryshort thensellshort 1 shares at entryshort-(1*pointsize) stopendifif shortonmarket thenexitshort at marketendif02/07/2019 at 11:15 PM #90794You place two pending orders on the market and when one is hit the other is not cancelled until the candle closes – so if price moves against you and hits the other order within the same candle then you have two trades and the second one closes the first one. It is not possible to cancel an order before a candle has closed. You will need to use MTF and work in a faster time frame. Keep putting the orders to market at each candle close until one is hit and then stop putting the opposite order to market as soon as you are on market at a candle close. This will though obviously massively reduce the available data that you can back test on.
02/07/2019 at 11:29 PM #90796a) you can simply write lines 3-4 as, since you want to just scan ONE bar (that is the current bar):
12entrylong=highentryshort=lowif you also want to scan the previous bar you’ll have to use [2] within brackets:
12entrylong=highest[2](high)entryshort=lowest[2](low)while if you want to scan ONLY the previous bar you’ll have to write:
12entrylong=high[1]entryshort=low[1]b) you can remove and entrylong and and entryshort from lines 6 and 14, since they are always true (they cannot be 0).
c) since in line 7 you want to BUY 1 pip higher than current HIGH, be warned that if CLOSE is too near and does not meet the broker’s distance requirements, the order could be rejected or entered at market. This is also the case for line 15.
d) your orders will be placed when the first bar of the day (usually opening at 01:00 utc+1) closes and will be triggered if THAT high/low is broken, not that of the previous bar as I said above at point a)
e) there is no way to avoid pending orders from being triggered once they are placed. So if it happens that the range of the setup bar is narrow and they are both triggered… well you’l have to either:
- use at market orders, or
- use the MTF (Multiple Time Frame) support and launch your strategy from a lower TF (say 1 minute, but still they could be both triggered in this unlikely case).
EDIT: I was writing while Vonasi was posting
02/08/2019 at 12:09 AM #90802I typed faster Roberto!
I thought that I would ignore all the other little issues in the code as none of them stopped it working and even if they were not the most efficient way to code it they were not relevant to the main question. I thought that it might confuse things a little if I mentioned them so I didn’t – but you listed them all so I think we got it all totally covered between us!
1 user thanked author for this post.
02/08/2019 at 1:45 PM #90859Ah ok, I didn’t considered the fact of the orders cancelled only at closed candle, I thought that using “if not onmarket” and “if longonmarket” would erase the other order at once.
Yes the only way in this cases may be using the MTF.
Thanks so much Roberto and Vonasi!!
Maxx
-
AuthorPosts
Find exclusive trading pro-tools on