Array out of range

 

hello

Why do I get this error message on Test?

This is my code

#property copyright "Prototypage"
#property link      "None"
#property version   "1.00"

#include <MyTools.mqh>

#property indicator_chart_window
#property indicator_buffers 5
#property indicator_plots   3
//--- plot Fast
#property indicator_label1  "Fast"
#property indicator_type1   DRAW_COLOR_LINE
#property indicator_color1  Red, Green
#property indicator_style1  STYLE_SOLID
#property indicator_width1  3
//--- plot Medium
#property indicator_label2  "Medium"
#property indicator_type2   DRAW_LINE
#property indicator_color2  Red
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//--- plot Slow
#property indicator_label3  "Slow"
#property indicator_type3   DRAW_LINE
#property indicator_color3  Red
#property indicator_style3  STYLE_SOLID
#property indicator_width3  1

//--- indicator buffers
double         FastBuffer[];
double         MediumBuffer[];
double         SlowBuffer[];
double         Orientation[];
double         Test[];

input int MaFast = 5;
input int MaMedium = 12;
input int MaSlow = 20;

int FastHandle;
int SlowHandle;
int MediumHandle;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   PlotIndexSetString ( 0, PLOT_LABEL, "Fast");
   PlotIndexSetString ( 1, PLOT_LABEL, "Medium");
   PlotIndexSetString ( 2, PLOT_LABEL, "Slow");

   SetIndexBuffer( 0, FastBuffer, INDICATOR_DATA);
   SetIndexBuffer( 1, Orientation, INDICATOR_COLOR_INDEX); /// GRRRRR!!!!!!
   SetIndexBuffer( 2, MediumBuffer, INDICATOR_DATA);
   SetIndexBuffer( 3, SlowBuffer, INDICATOR_DATA);
    
   FastHandle = iMA( NULL, 0, MaFast, 0, MODE_EMA, PRICE_CLOSE);
   SlowHandle = iMA( NULL, 0, MaSlow, 0, MODE_EMA, PRICE_CLOSE);
   MediumHandle = iMA( NULL, 0, MaMedium, 0, MODE_EMA, PRICE_CLOSE);
   
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| 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[])
  {
//---
   CopyBuffer(FastHandle, 0, 0, rates_total, FastBuffer);
   CopyBuffer(SlowHandle, 0, 0, rates_total, SlowBuffer);
   CopyBuffer(MediumHandle, 0, 0, rates_total, MediumBuffer);
   
   for ( int i = prev_calculated+1; i < rates_total; i++){
   /*Obligation de faire une boucle pour parcourir le buffer pour mettre
   à jour notre tableau orienation. On essaye de le faire pour la dernière période*/
      Orientation[i] = BufferParcoursOrienation ( FastBuffer[i-1], FastBuffer[i]);
      Test[i] = BufferParcoursOrienation ( FastBuffer[i-1], FastBuffer[i]);
   };   
   
//--- return value of prev_calculated for next call
   return(rates_total);
  };
//+------------------------------------------------------------------+

I do not understand why it's works for Orientation[i] = BufferParcoursOrienation ( FastBuffer[i-1], FastBuffer[i]);

and don't work for  Test[i] = BufferParcoursOrienation ( FastBuffer[i-1], FastBuffer[i]);???

 

I tried to follow the values with print, they are well.

Please advise.

Best Regards 

 
William210:

I do not understand why it's works for Orientation[i] = BufferParcoursOrienation ( FastBuffer[i-1], FastBuffer[i]);

and don't work for  Test[i] = BufferParcoursOrienation ( FastBuffer[i-1], FastBuffer[i]);???

 


You have missed one line

 SetIndexBuffer( 4, Tester, INDICATOR_CALCULATIONS);
 See also SetIndexBuffer
 

 William,

What makes the array Orientation[] to resize automatically is the instruction SetIndexBuffer( 1, Orientation, INDICATOR_COLOR_INDEX).

In the case of the array Test[], there is no such instruction, therefore, it is not resizing.

Regards,

Jin 

 

Hello

Ok, I will try to add your comment in my code.

Thanks a lot.

Best Regards 

Reason: