Optimization inconsistency

 

Hi and thanks for the help

I am relatively new to Forex, but am a software developer, so most EA concepts I grasp. I wrote a simple stochastic EA which I am now back testing. A few points:

  • I coded a check into the start() function to ensure the EA only opens/closes trades once per bar. I did this because I read that when a EA runs on a live chart the processing mode is always "every tick", and I needed max one trade opened per bar.
if (Bars == ThisBarTrade ) {
   return(0);
}
   
ThisBarTrade = Bars;
  • Consequently I am now backtesting the EA in "Every Tick" mode, to simulate a live environment. Results are as expected: trades are only opened or closed every hour on the hour on a 1H chart. I get a good return from the EA, curve-fitting notwithstanding (I'll address that when I get to the walk-forward optimization).
  • However when I run the backtest in "Open prices only" in order to speed up the testing, I get very bad results. In fact, no combination of parameters yields a positive return. I'm not sure if this is relevant, but looking at the Results tab on an individual test (open prices only), trades are now all happening at 1 minute before the hour, i.e, 09:59 instead of at the bar opening time of 10:00.
So my question is this: If the EA is coded to only trade once per bar, why is there a material difference between running backtest in tick mode or open price mode?
 

Welcome to mql4.com forum,

Your way to check for once per bar isn't reliable, you have to use Time/iTime. See what has been discussed in the past.

About your results, are you sure the only difference between your tests is Every tick/Open price ?

 

Hi angevoyageur, thanks for the reply.

I'll make the Time adjustment as you suggest.

As for the results, yes that is the only change. I run the test in Tick mode, get a good result, change the mode to open prices, and get all losses.

Having done some more digging since I posted this question, one cause for this springs to mind. Is it possible that in Open Prices mode, my stops are not being hit? The EA opens trades with a tight SL, and also manually closes trades when certain conditions are met, irrespective of profit/loss.

 
Ravish98:

Hi angevoyageur, thanks for the reply.

I'll make the Time adjustment as you suggest.

As for the results, yes that is the only change. I run the test in Tick mode, get a good result, change the mode to open prices, and get all losses.

Having done some more digging since I posted this question, one cause for this springs to mind. Is it possible that in Open Prices mode, my stops are not being hit? The EA opens trades with a tight SL, and also manually closes trades when certain conditions are met, irrespective of profit/loss.

Maybe, difficult to say without seeing the code.
Reason: