Backtesting with Open[0] and Close[0]

 

My EA uses Open[0] and Close[0] on the M1 chart and then compares the two values to determine whether it was a bull or bear candle.


For some reason the backtester returns the same value for these two operators. The same is true for iOpen(.....,0) and iClose(......,0)


How do you resolve that?

 
FXtrader2008:

My EA uses Open[0] and Close[0] on the M1 chart and then compares the two values to determine whether it was a bull or bear candle.


For some reason the backtester returns the same value for these two operators. The same is true for iOpen(.....,0) and iClose(......,0)


How do you resolve that?



Hi,

Why not use Open[1] and Close[1] ? Close[0] price is the current price which is going up and down before the candle is really closed. So it may look it's a bearish candle at first but then reverse and close as a bullish one.

 

robofx,


Thanks for the feedback. The fact of the matter is I need to clarify what I am doing. My EA launches a buy trade if the current price is 2 PIPs higher than the current open, and the previous candle must be bullish. Those are the last two trade rules in my set of trade rules. There are several other trade rules that need to be satisfied before these two rules apply.


The problem that I encounter in the backtester does not occur in forward testing. You are quite right, that I need to use Open[1] and Close[1] to determine whether the previous bar was bullish, however, the backtester apparently cannot distinguish any difference in value between Open[0] and High[0], and as a result, the last rule I have for opening a trade is never satisfied in the backtester --- 5 months --- no trades.

 
FXtrader2008:

robofx,


Thanks for the feedback. The fact of the matter is I need to clarify what I am doing. My EA launches a buy trade if the current price is 2 PIPs higher than the current open, and the previous candle must be bullish. Those are the last two trade rules in my set of trade rules. There are several other trade rules that need to be satisfied before these two rules apply.


The problem that I encounter in the backtester does not occur in forward testing. You are quite right, that I need to use Open[1] and Close[1] to determine whether the previous bar was bullish, however, the backtester apparently cannot distinguish any difference in value between Open[0] and High[0], and as a result, the last rule I have for opening a trade is never satisfied in the backtester --- 5 months --- no trades.



I've just checked that with this simple line if(Close[0]>Open[0]) Print("Bullish candle"); and it's working ok. Seems your problem is elsewhere.. check all your other trading rules.

 
robofx.org:

I've just checked that with this simple line if(Close[0]>Open[0]) Print("Bullish candle"); and it's working ok.....

robox,


Thanks for taking the time to run a check in the backtester. You are quite right.


I expanded on that code by checking for Bear candles and also when there is no change. What I discovered is....


The backtester checked that expanded series of operators 1 to 5 times per minute, and it does distinguish a difference.


Now I have an algorithmic challenge on my hands . . . . the sleuthing fun continues . . . .


The problem emanates from the fact my forward testing EA and my backtesting EA are not the same. My EA requires info from the M15, M5, and M1 charts. As a result it will not run in the backtester without adjustments. I have to create my own M5 and M15 indicators by first finding the OHLC for five consecutive minutes and likewise for 15 consecutive minutes and then generate my own indicator values for the aggregated data. . . . . an additional 300+ lines of code just to do that (my coding format is very generous with space --- it could probably be done in 100 lines or less).


I made a bad assumption in producing the M5 & M15 data generator, I had assumed that the backtester would look at one line of M1 data just one time and distinguish a difference between Open[0] and Close[0], or for that matter Open[0] and the other data points for that minute: High[0], etc. However, the backtester looks at the same line of M1 data more than one time --- the first time it looks at the line of data Open[0], High[0], Low[0], and Close[0] are all equal (that's where my error lies --- because I assumed it looked at the line only time and moved on). I have a time checker in my code that allows the EA to read a line of M1 data only one time and then move on --- I'll have to fix that aspect.


Cheers