Download MetaTrader 5
To add comments, please log in or register
Develop trading robots to order. Make profit with Freelance service!
Damien Olanier
128
Damien Olanier 2010.08.24 13:13 

Hello,

i have this error in the mt5 client with my indicator... and i'm not able to find the error. 

Compilation is ok in the editor.

In my indicator i want to find the Highest Price in a Monthly chart. Here is the calculation code :


#property indicator_chart_window
#property indicator_buffers 3
#property indicator_plots   3
//--- plot High
#property indicator_label1  "High"
#property indicator_type1   DRAW_LINE
#property indicator_color1  Lime
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot Low
#property indicator_label2  "Low"
#property indicator_type2   DRAW_LINE
#property indicator_color2  Red
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//--- plot Mean
#property indicator_label3  "Mean"
#property indicator_type3   DRAW_LINE
#property indicator_color3  Aqua
#property indicator_style3  STYLE_SOLID
#property indicator_width3  1
//--- indicator buffers
double         High[];
double         Low[];
double         Mean[];
//--- constants
double BarHigh=0;
int totbars;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,High,INDICATOR_DATA);
   SetIndexBuffer(1,Low,INDICATOR_DATA);
   SetIndexBuffer(2,Mean,INDICATOR_DATA);
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Get Low for specified bar index                                  |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Get the High for specified bar index                             |
//+------------------------------------------------------------------+
double iHigh(string symbol)
  {
   totbars=Bars(symbol,PERIOD_MN1);
   ArraySetAsSeries(High,true);
   int copied=CopyHigh(symbol,PERIOD_MN1,0,totbars,High);
   if ( copied>0 )
     {
      BarHigh=High[0];
      for ( int i=0;i<ArraySize(High);i++)
         if ( High[i+1]>High[i] )
           BarHigh=High[i+1];
     }
        Print("Array",ArraySize(High));
           Print("Highest bar value from previous ",totbars," bars is ",BarHigh);
   return(BarHigh);
  }
//+------------------------------------------------------------------+
//| 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[])
  {
   iHigh(Symbol());
//---
//--- return value of prev_calculated for next call
   return(rates_total);
  }


Thanks for advance,

Dam.  :)


Edit : thought i'm in the wrong forum section. Maybe an admin could move my post in Technical Ind. section please? I'm sorry it's my first post in the mql5 forum.

Ilyas
1205
Ilyas 2010.08.24 13:26  
expression (i+1 ) can be greater than size of array iHigh

Damien Olanier
128
Damien Olanier 2010.08.24 13:30  
mql5:
expression (i+1 ) can be greater than size of array iHigh

Ok thanks! I will work on that.  :)
/
To add comments, please log in or register