Tick generation - Open bar only

 

I run this test using EURUSD, H1, Open prices only

void OnTick()
{   
   // current chart bar time
   datetime aSTime = 0;
   if(CopyTime(Symbol(),PERIOD_CURRENT,0,1,LTimeArr) == -1)
   {
      Print("CopyTime "+Symbol()+" error: ",GetLastError());
      return;
   }
   aSTime = LTimeArr[0];
   
   // other symbol time on the current tick time
   datetime aOTime = 0;
   string aOSymbol = "GBPUSD";
   if(CopyTime(aOSymbol,PERIOD_CURRENT,aSTime,1,LTimeArr) == -1)
   {
      Print("CopyTime "+aOSymbol+" error: ",GetLastError());
      return;
   }
   aOTime = LTimeArr[0];   
   
   Print("Time: ",Symbol(),": ",aSTime,", "+aOSymbol+": ",aOTime);
}

 And I get some results like this:

Time: EURUSD: 2010.05.31 23:00:00, GBPUSD: 2010.05.31 22:00:00
Time: EURUSD: 2010.05.31 22:00:00, GBPUSD: 2010.05.31 22:00:00
Time: EURUSD: 2010.05.31 21:00:00, GBPUSD: 2010.05.31 20:00:00

I was expecting to get for GBPUSD the same hours like EURUSD but hour 21 and 23 are not reported. The bar hours exist on GBPUSD chart.

The whole list printed shows also many discrepancies in times.

What do I do wrong ?

 Thank you.

Documentation on MQL5: Standard Constants, Enumerations and Structures / Indicator Constants / Price Constants
  • www.mql5.com
Standard Constants, Enumerations and Structures / Indicator Constants / Price Constants - Documentation on MQL5
 

For above I used the latest build 302

 

Anybody commenting on this ?

thank you. 

 

Bars on different symbols don't appear simultaneously simultaneously. What did you expect? Try this code

void OnTick()
{   
   // current chart bar time
   datetime aSTime = 0;
   if(CopyTime(Symbol(),PERIOD_CURRENT,0,3,LTimeArr) == -1)
   {
      Print("CopyTime "+Symbol()+" error: ",GetLastError());
      return;
   }
   aSTime = LTimeArr[0];
   
   // other symbol time on the current tick time
   datetime aOTime = 0;
   string aOSymbol = "GBPUSD";
   if(CopyTime(aOSymbol,PERIOD_CURRENT,aSTime,3,LTimeArr) == -1)
   {
      Print("CopyTime "+aOSymbol+" error: ",GetLastError());
      return;
   }
   else
   {
    for(int i=0;i<3;i++) Print("Time: ",aOSymbol,": ",LTimeArr[i]);
   }
   aOTime = LTimeArr[0];   
   
   Print("Time: ",Symbol(),": ",aSTime,", "+aOSymbol+": ",aOTime);
}

 
Rosh:

Bars on different symbols don't appear simultaneously simultaneously. What did you expect? Try this code


Why not ?

when the gong beats 12 o'clock on EURUSD, shouldnt it beat 12 o'clock on GBPUSD also ? why it says it is 11 hour on GBPUSD ?

I understand that might be data missing in some cases, but on higher timeframes there are few cases when a full bar time is missing, so the tester would report a hour back.

 
New bar appears with new tick regardless when "gong beats 12 o'clock". You can check it yourself. Also you should read article Limitations and Verifications in Expert Advisors

To get the time of opening of the last bar, you should use the SeriesInfoInteger() function with specified name of symbol, timeframe and the SERIES_LASTBAR_DATE property. By constant comparing of the time of opening of the current bar with the one of the bar stored in a variable, you can easily detect the moment when a new bar appears. It allows to create the custom function isNewBar() that can look as following:

//+------------------------------------------------------------------+
//| Return true if a new bar appears for the symbol/period pair      |
//+------------------------------------------------------------------+
bool isNewBar()
  {
//--- remember the time of opening of the last bar in the static variable
   static datetime last_time=0;
//--- current time
   datetime lastbar_time=SeriesInfoInteger(Symbol(),Period(),SERIES_LASTBAR_DATE);

//--- if it is the first call of the function
   if(last_time==0)
     {
      //--- set time and exit
      last_time=lastbar_time;
      return(false);
     }

//--- if the time is different
   if(last_time!=lastbar_time)
     {
      //--- memorize time and return true
      last_time=lastbar_time;
      return(true);
     }
//--- if we pass to this line then the bar is not new, return false
   return(false);
  }

An example of using the function is given in the attached Expert Advisor CheckLastBar.mq5.

The messages of the CheckLastBar Expert Advisor about appearing of new bars on M1 timeframe.

The messages of the CheckLastBar Expert Advisor about appearing of new bars on M1 timeframe.

 
Rosh:
New bar appears with new tick regardless when "gong beats 12 o'clock". You can check it yourself. Also you should read article Limitations and Verifications in Expert Advisors

Hi Rosh,

I dont need to detect a new bar.

Please, look at the output above again and explain me why the hour 22 on GBPUSD is reported twice ? once when EURUSD is hour 22 and once when EURUSD is 23 ? Why  GBPUSD hour 21 is missing  but GBP 20 hour appears ? and why hour EURUSD 22 and hour GBPUSD 22 appears synchronized on the same tick ? but not 21 and 23 like EURUSD ? 

I have not found in docs explaining this behaviour. 

Time: EURUSD: 2010.05.31 23:00:00, GBPUSD: 2010.05.31 22:00:00
Time: EURUSD: 2010.05.31 22:00:00, GBPUSD: 2010.05.31 22:00:00
Time: EURUSD: 2010.05.31 21:00:00, GBPUSD: 2010.05.31 20:00:00

If I run your first code above to try

... 

CopyTime(aOSymbol,PERIOD_CURRENT,aSTime,3,LTimeArr) 

for(int i=0;i<3;i++) Print("Time: ",aOSymbol,": ",LTimeArr[i]);

etc, I am able to find the hour 21 in the LTimeArr[3], but another question appears : Why should I CopyTime with 3 bars and not 200

CopyTime(aOSymbol,PERIOD_CURRENT,aSTime,200,LTimeArr)  to look for the 'shit' missing GBPUSD hour 21 and 23 ?

Thank you.

 

 

Hey,

 It appears the last build 313 has not solved this problem also. What are you doing out there ? I posted about this in Service desk also, and no answer in the last week or more.

Dont you understand ? When we test Open prices only, multiple symbols at once, H1 timeframe, for example, when the tick 'gong' the hour 13 on EURUSD, it must gong the same hour on GBPUSD and other pairs.

For your information, I am testing the same tick synchronization on the Dukaskopy's JForex platform. They use Java.

And the question is, why their platform generate correct times on pairs like below ? Tested 4 pairs, open prices only on H1 bar.

And another question is, why I was able to check this in less than 2 hours on their JForex platform and not in MQL5 in more than 1 month now ?

AUD/JPY Time: 2010/8/9 17:0:0.0 HLOC: 78.71/78.57/78.655/78.625
USD/JPY Time: 2010/8/9 17:0:0.0 HLOC: 85.865/85.8/85.86/85.82
EUR/USD Time: 2010/8/9 17:0:0.0 HLOC: 1.3236/1.32235/1.32285/1.32265
AUD/USD Time: 2010/8/9 17:0:0.0 HLOC: 0.91675/0.9155/0.91615/0.9162


AUD/JPY Time: 2010/8/9 16:0:0.0 HLOC: 78.755/78.6/78.74/78.66
USD/JPY Time: 2010/8/9 16:0:0.0 HLOC: 85.9/85.83/85.885/85.86
EUR/USD Time: 2010/8/9 16:0:0.0 HLOC: 1.3245/1.3216/1.324/1.3228
AUD/USD Time: 2010/8/9 16:0:0.0 HLOC: 0.917/0.9154/0.91685/0.91615


AUD/JPY Time: 2010/8/9 15:0:0.0 HLOC: 78.745/78.48/78.53/78.74
USD/JPY Time: 2010/8/9 15:0:0.0 HLOC: 85.905/85.72/85.78/85.885
EUR/USD Time: 2010/8/9 15:0:0.0 HLOC: 1.3252/1.3234/1.3245/1.32405
AUD/USD Time: 2010/8/9 15:0:0.0 HLOC: 0.91685/0.9153/0.91545/0.91685


AUD/JPY Time: 2010/8/9 14:0:0.0 HLOC: 78.715/78.465/78.61/78.53
USD/JPY Time: 2010/8/9 14:0:0.0 HLOC: 85.775/85.645/85.675/85.765
EUR/USD Time: 2010/8/9 14:0:0.0 HLOC: 1.3255/1.3232/1.3242/1.3245
AUD/USD Time: 2010/8/9 14:0:0.0 HLOC: 0.91815/0.9153/0.9175/0.9154

 Java code used on their platform:

    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar)
    {
        if(period != Period.ONE_HOUR)
            return;
           
        long atime = bidBar.getTime();
        Calendar aDate = Calendar.getInstance();
        aDate.setTimeZone(TimeZone.getTimeZone("GMT+0"));
        aDate.setTimeInMillis(atime);
        console.getOut().println(instrument+" Time: "+aDate.get(aDate.YEAR)+"/"+(aDate.get(aDate.MONTH)+1)+"/"+aDate.get(aDate.DAY_OF_MONTH)+" "+aDate.get(aDate.HOUR_OF_DAY)+":"+aDate.get(aDate.MINUTE)+":"+aDate.get(aDate.SECOND)+"."+aDate.get(aDate.MILLISECOND)+" HLOC: "+bidBar.getHigh()+"/"+bidBar.getLow()+"/"+bidBar.getOpen()+"/"+bidBar.getClose());       
    } 

Documentation on MQL5: Standard Constants, Enumerations and Structures / Indicator Constants / Price Constants
  • www.mql5.com
Standard Constants, Enumerations and Structures / Indicator Constants / Price Constants - Documentation on MQL5
 

Hi, I'm running into the exact same problem with my (first) multi-currency strategy.

IMHO opinion the root cause of the problem is that apparently support of multi-currency traders has not been fully developed in MQL5 yet.
It would be better if an EA could subcribe to multiple(!) tick streams, through the "Observer"/"Publish-Subscribe" design pattern!

I'm going to put this through to the Service Desk too.

Cheers!

 

Yep, 2 months work on MQL5 platform -> results ZERO for multistrategy concept

8 hours work on JForex -> results FULL = SOLVED for multistrategy concept

voila! 

 
tektronic:

Yep, 2 months work on MQL5 platform -> results ZERO for multistrategy concept

8 hours work on JForex -> results FULL = SOLVED for multistrategy concept

voila! 

Hi Tektronic,

thanks for the JForex pointer. I definitely will be looking into JForex as it is platform-indepent. My main platform is Mac. Moreover, Java is an existing full-blown object-oriented language and doesn't have so many nasty limitations in the language itself as MQL5 currently has. (see my other postings here on OO in MQL5). May I suggest to MetaQuotes to just write a C++ framework/library for MQL5 and use standard C++ as the programming language? Thank you very much in advance!

That said, not all is lost yet. As my strategy is based on crossings in the previous bar I have decided to alter my code in such a way that if the tick received is not for the pair I'm trading, I will check the time of the bar of the incoming tick and use that time to get the information from the previous bar of the pai I'm interested in (which now will be either the index 0 or 1, but you can't tell in advance) and determine whether a cross appeared.

I'm intending to let the EURUSD pair (with its ticks) drive my submission for ATC2010 , as I expect most activity in the EURUSD pair. Nevertheless, during the Asian session I also expect problems when trading USDJPY on EURUSD ticks. I did a quick test. If I drive my EURUSD strategy on USDGBP ticks I get 86% of my possible profit. If I drive my USDGBP strategy on EURUSD ticks I get 96%.

Nevertheless, this 'ticks issue' is a royal PITA and I'm very frustrated because of it, as I have spent considerable time on finding efficient strategies for all(!) 12 pairs, only to find out now, that my combined EA is not performing as expected and that there's apparently no way to solve this.

Still I'm very much open to smart suggestions from other developers or MetaQuotes.

Cheers!

Reason: