Download MetaTrader 5
To add comments, please log in or register
Do you know that MQL5 has structures?
mpr
63
mpr 2013.04.01 03:50 
I've been using code in MT4 that waits for a new Bar to open before the rest of the code is executed.  I've been trying to migrate this specific feature into my MT5 code, but without success.  Specifically, I'm getting hung up on the Time[0] variable that is no longer in MT5.  Can someone assist with this please!!??  Thank You!!!
extern bool CheckOncePerBar = true;

datetime CurrentTimeStamp;

int init()
  {
   CurrentTimeStamp = Time[0];
   return;                                     
  }

int start()
  {
   if(CheckOncePerBar == true)
      {
         int Barshift = 1;
         if(CurrentTimeStamp != Time[0])
            {
             //indicator and trading logic go here
            }
         else NewBar = false;
      }
   else
      {
         NewBar = true;
         Barshift = 0;
      }
  }
Jian Chen
Moderator
3464
Jian Chen 2013.04.01 04:31  

You may have a look at the "Migrating from MQL4 to MQL5" article (https://www.mql5.com/en/articles/81).

By searching "Time[" in that article, you may find how to implement "Time[]" feature in MQL5:

datetime Time[];
int count;   // number of elements to copy
ArraySetAsSeries(Time,true);
CopyTime(_Symbol,_Period,0,count,Time);

 Depending on how many elements you need to access the Time array, you may specify the value of "count".

Migrating from MQL4 to MQL5
Migrating from MQL4 to MQL5
  • 2010.05.17
  • Sergey Pavlov
  • www.mql5.com
This article is a quick guide to MQL4 language functions, it will help you to migrate your programs from MQL4 to MQL5. For each MQL4 function (except trading functions) the description and MQL5 implementation are presented, it allows you to reduce the conversion time significantly. For convenience, the MQL4 functions are divided into groups, similar to MQL4 Reference.
Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2013.04.01 11:15  
mpr:
I've been using code in MT4 that waits for a new Bar to open before the rest of the code is executed.  I've been trying to migrate this specific feature into my MT5 code, but without success.  Specifically, I'm getting hung up on the Time[0] variable that is no longer in MT5.  Can someone assist with this please!!??  Thank You!!!
Have a read of this . . .  https://www.mql5.com/en/forum/10841/436688#comment_436688
strange datetime assignment
strange datetime assignment
  • www.mql5.com
I tried to verify NewBar appearance with the following code from Samuels article "Step-By-Step Guide to writing an Expert Advisor in MQL5 for Beginners".
mpr
63
mpr 2013.04.01 13:41  
Thanks!!!  
/
To add comments, please log in or register