indexing difference between mql4 and mql5.

 

Hi

I noticed that in MT4 the index [0] is the current bar(on the extreme RIGHT position).

But in MT5, the index [0] is the FIRST bar(on the extreme LEFT position).

When I tried to convert indicator from MT4 to MT5 the indexing made the converted indicator plots differently.

Is there any way to use the same indexing on MT5 as MT4?


Thanks

 
silverfall:

Hi

I noticed that in MT4 the index [0] is the current bar(on the extreme RIGHT position).

But in MT5, the index [0] is the FIRST bar(on the extreme LEFT position).

When I tried to convert indicator from MT4 to MT5 the indexing made the converted indicator plots differently.

Is there any way to use the same indexing on MT5 as MT4?


Thanks

https://www.mql5.com/en/docs/array/arraysetasseries

 
silverfall:

I noticed that in MT4 the index [0] is the current bar(on the extreme RIGHT position).

But in MT5, the index [0] is the FIRST bar(on the extreme LEFT position).

Both false.
  1. In MT4, only the predefined arrays and buffers are as-series by default.
  2. In MT5, there is no default direction. You must set the direction.
 
William Roeder:
Both false.
  1. In MT4, only the predefined arrays and buffers are as-series by default.
  2. In MT5, there is no default direction. You must set the direction.

In MT5, there is no default direction. You must set the direction.

How do I do that?

 
silverfall :


My example is based on ArrayIsSeries help.

I added the input parameter "AS_SERIES flag" - the flag value is displayed in the "Data WIndow")

Result:

The rightmost bar on the chart

Code:

//+------------------------------------------------------------------+
//|                                             ArraySetAsSeries.mq5 |
//|                              Copyright © 2013, Vladimir Karputov |
//|                                           http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2013, Vladimir Karputov"
#property link      "http://wmua.ru/slesar/"
#property version   "1.002"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//---- plot Numeration
#property indicator_label1  "Numeration"
#property indicator_type1   DRAW_LINE
#property indicator_color1  CLR_NONE
//--- input parametrs
input bool     InpArraySetAsSeries  = true;  // AS_SERIES flag
//--- indicator buffers
double         NumerationBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,NumerationBuffer,INDICATOR_DATA);
//--- set indexing for the buffer like in input parameter "AS_SERIES flag"
   ArraySetAsSeries(NumerationBuffer,InpArraySetAsSeries);
//--- set accuracy of showing in DataWindow
   IndicatorSetInteger(INDICATOR_DIGITS,0);
//--- how the name of the indicator array is displayed in DataWindow
   string text="flag false";
   if(InpArraySetAsSeries)
      text="flag true";
   PlotIndexSetString(0,PLOT_LABEL,"("+text+") "+"Bar #");
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {
//---  we'll store the time of the current zero bar opening
   static datetime currentBarTimeOpen=0;
//--- revert access to array time[] - do it like in timeseries
   ArraySetAsSeries(time,true);
//--- If time of zero bar differs from the stored one
   if(currentBarTimeOpen!=time[0])
     {
      //--- enumerate all bars from the current to the chart depth
      for(int i=rates_total-1; i>=0; i--)
         NumerationBuffer[i]=i;
      currentBarTimeOpen=time[0];
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

Documentation on MQL5: Array Functions / ArrayIsSeries
Documentation on MQL5: Array Functions / ArrayIsSeries
  • www.mql5.com
//| Custom indicator initialization function                         | //| Custom indicator iteration function                              |
Files:
 
William Roeder:
Both false.
  1. In MT4, only the predefined arrays and buffers are as-series by default.
  2. In MT5, there is no default direction. You must set the direction.
Your 2nd statement doesn't make any sense at all. "no default direction" ? really?  That's just ridicules.
 

Thanks man.


Vladimir Karputov:

My example is based on ArrayIsSeries help.

I added the input parameter "AS_SERIES flag" - the flag value is displayed in the "Data WIndow")

Result:

Code:

 
silverfall:
Your 2nd statement doesn't make any sense at all. "no default direction" ? really?  That's just ridicules.

Of course there is a default direction, but the documentation says it could be changed anytime, so you can't rely on it. That's the theory.

In practice, using mql5 the last 7 years the default direction was never changed and is "indexed not as serie".

 
Alain Verleyen:

Of course there is a default direction, but the documentation says it could be changed anytime, so you can't rely on it. That's the theory.

In practice, using mql5 the last 7 years the default direction was never changed and is "indexed not as serie".

Yes, your reply makes more sense.


Thanks.