Discussion of article "Migrating from MQL4 to MQL5" - page 4

 
Interesting :

I started to doubt a lot about the functionality of this design. No matter how hard I tried to understand the logic of the block, I couldn't (and I tried hard)....

What is the doubt? It counts correctly.

//+------------------------------------------------------------------+
//|test.mq5 |
//+------------------------------------------------------------------+
#include <InitMQL4.mqh>
double   close[];
int      total,count;
datetime time[];
//+------------------------------------------------------------------+
//||
//+------------------------------------------------------------------+
void OnStart()
  {
   count=Bars(_Symbol,_Period);
   total=CopyClose(_Symbol,_Period,0,count,close);
   total=CopyTime(_Symbol,_Period,0,count,time);
   ArraySetAsSeries(time,true);
   ArraySetAsSeries(close,true);
   int N=7;
   int shift=iBarShiftMQL4(_Symbol,_Period,time[N]);
   Print("TIME",time[N],"BAR=",shift," CLOSE=",close[shift]);
  }
//+------------------------------------------------------------------+
int iBarShiftMQL4(string symbol,
                  int tf,
                  datetime time,
                  bool exact=false)
  {
   if(time<0) return(-1);
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   datetime Arr[],time1;
   CopyTime(symbol,timeframe,0,1,Arr);
   time1=Arr[0];
   if(CopyTime(symbol,timeframe,time,time1,Arr)>0)
      return(ArraySize(Arr)-1);
   else return(-1);
  }
//+------------------------------------------------------------------+
 
DC2008 :

What's the problem? He's counting correctly.

And now for the hocus-pocus


1. In MT4 we write this line and execute the code on H4

Print(iBarShift(Symbol(),Period(),1274356800,false)); //date 20.05.2010 12:00 pm

Then we do the same with MT5 and the string.

int shift=iBarShiftMQL4(_Symbol,_Period,StringToTime("20.05.2010 12:00"),false);

as a result we get 8.


2. After that we do exactly the same operation, but with D1.

As a result MT4 returns - 1 and MT5 returns 0.

Now who can tell me how much this implementation of iBarShiftMQL4 corresponds to the necessary...

int iBarShiftMQL4(string symbol,
                  int tf,
                  datetime time,
                  bool exact=false)
  {
   if(time<0) return(-1);
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   datetime Arr[],time1;
   CopyTime(symbol,timeframe,0,1,Arr);
   time1=Arr[0];
   if(CopyTime(symbol,timeframe,time,time1,Arr)>0)
      return(ArraySize(Arr)-1);
   else return(-1);
  }
 

Try this one:

int iBarShiftMQL4(string symbol,
                  int tf,
                  datetime time,
                  bool exact=false)
  {
   if(time<0) return(-1);
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   datetime Arr[],time1;
   CopyTime(symbol,timeframe,0,1,Arr);
   time1=Arr[0];
   if(CopyTime(symbol,timeframe,time,time1,Arr)>0)
     {
      if(ArraySize(Arr)>2) return(ArraySize(Arr)-1);
      if(time<time1) return(1);
      else return(0);
     }
   else return(-1);
  }
 

Again, have you read about the function you're writing about???

on mcl4 it is written exactly

double iClose( string symbol, int timeframe, int shift)
Returns the value of the closing price of the bar from the corresponding chart(symbol, timeframe) specified by the shift parameter. In case of an error, the function returns 0. To get more information about the error, call the GetLastError() function.
For the current chart, the information about closing prices is in the predefined Close[] array.

and you have....

return(-1);

what are the moderators looking at...

 

Thanks, CoreWinTT.

Fixed functions: iClose, iLow, iHigh, iOpen, iTime, iVolume. They return 0 instead of -1 in case of error.

 

and when will they be in the library???

so that they were at least

Because if you open it, the question arises, and the meaning of the above written????.

and also at least collect the functions for which all questions are solved and proceed to study errors in the rest.

 
bool  SetIndexBuffer(
   int                    index,         // buffer index
   double                 buffer[],      // array
   ENUM_INDEXBUFFER_TYPE  data_type      // what we're going to store
   );

the other day, someone suggested a clever means of creating an μl4 environment

by using arrays of

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])

but it will be difficult to use them because they have const state.

You can't create global buffers

because they must be declared with the help of

SetIndexBuffer

Associates the specified indicator buffer with a one-dimensional dynamic array of type double declared globally.

but only double type, and volumes and arrays of date-time type will not pass.

The only thing left is to initiate these arrays inside the mql4 module.

which is practically equal to rewriting the indicator....

 
CoreWinTT:

and when will they be in the library???

They already are.
 
it's empty and was empty and only a bunch of defines and nothing more....
 
CoreWinTT:

and when will they be in the library???

so that they were at least

Because if you open it, the question arises, and the meaning of the above written????.

and also at least collect the functions for which all questions are solved and proceed to study errors in the rest.

There are a lot of solutions on this topic in private libraries for a long time.

I, for example, have been using IsTesting() and similar things from the very beginning, also everything has been solved with date and time for a long time (of course, there are other solutions)....

Another thing is the presence of such "Outdated solutions" in MT5 itself...