How do I make an EA to trade exactly the same on "open bars" and "Every real tick" settings on history?

 

How do I make an EA to trade exactly the same on "open bars" and "Every real tick" settings on history?


I did create a function that only allows the EA to trade on the first tick

if (iVolume(Symbol(),PERIOD_M15,0 )!= 1)return;


But I get a diffrent equity graph than when setting the settings to "Every tick based on real ticks" than "Open prices only".


Can someone explain what is going on here. I thought the history of open bars was the first tick of each bar recorded?

Real ticks history

Open bars history

The Fundamentals of Testing in MetaTrader 5
The Fundamentals of Testing in MetaTrader 5
  • www.mql5.com
The idea of ​​automated trading is appealing by the fact that the trading robot can work non-stop for 24 hours a day, seven days a week. The robot does not get tired, doubtful or scared, it's is totally free from any psychological problems. It is sufficient enough to clearly formalize the trading rules and implement them in the algorithms, and...
 
Cristian Eriksson: iVolume(Symbol(),PERIOD_M15)==1
For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart,) volume is unreliable (miss ticks,) Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.

I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
          New candle - MQL4 programming forum #3 2014.04.04

 

Thank you! They look much more similar now. Still not exactly, but that might come down to price history errors?

Open prices

Every tick based of real ticks

void OnTick()
  {
  if(TradeFrequenzy==WilliamCandle && !NewWilliamCandle(TF))
    return;
  }

bool NewWilliamCandle(ENUM_TIMEFRAMES TimeFr)
  {
  static datetime timeCur; 
  datetime timePre = timeCur; 
  timeCur=iTime(Symbol(),TimeFr,0);
  bool isNewBar = timeCur != timePre;
  return(isNewBar);
  }
 

Cristian, I am trying to solve the same problem, having a discrepancy between test results. My EA operates on bar 1 however "Every Tick" generates terrible results.

In the example above, what is TradeFrequenzy and WilliamCandle?

Thank you!

 
Plamen Zhivkov Kozhuharov #: Cristian, I am trying to solve the same problem, having a discrepancy between test results. My EA operates on bar 1 however "Every Tick" generates terrible results. In the example above, what is TradeFrequenzy and WilliamCandle? Thank you!

The only way to make a strategy behave the same on both "Open Prices" and "Every Tick", is to have the positions both open and close on the opening of the bar. That means that positions can't be allowed to exit at a Stop-Loss or a Take-Profit. The position needs to also closed at the open price of a bar only.

Reason: