Download MetaTrader 5
To add comments, please log in or register
Hundreds of articles will help you to create a trading robot. Come and read them!
Jiten
30
Jiten 2010.05.12 12:12 

hi,

I get the error Array out of rnage with the following code.

Please hlep me out of this.

//+------------------------------------------------------------------+
//|                                              RMA_Minor_shift.mq5 |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright   "2009, MetaQuotes Software Corp."
#property link        "http://www.mql5.com"
#property description "RMA Minor Shift"
//--- indicator settings
#property indicator_level1 40
#property indicator_level2 60

#property indicator_separate_window // indicator will be displayed in the separate subwindow

#property indicator_buffers 3       // buffers used
#property indicator_plots 2         // buffers displayed

#property indicator_color1 Black // we use 2 colors
#property indicator_type1 DRAW_LINE          // and special color style
#property indicator_color2 Red // we use 2 colors
#property indicator_type2 DRAW_LINE          // and special color style

//---- buffers
double Minor[];                 // buffer for values
double Minor_shift[];           // buffer for values
double RoC_Minor[];                 // buffer for values

                                    // indicator input parameters
int                  RSIPeriod      = 7;
int                  MAPeriod       = 7;
int                  shift_prd      = 5;

// variable to store indicator handle
int Handle_minor,MAHandle_minor;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
// set the indicator buffers
// set Values as a buffer for displaying
   SetIndexBuffer(0,RoC_Minor,          INDICATOR_DATA);
   SetIndexBuffer(1,Minor_shift,    INDICATOR_DATA);
//--- set accuracy
   IndicatorSetInteger(INDICATOR_DIGITS,2);
// Set beginning of Values buffer drawing
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,RSIPeriod);
// Shifting the plot
//PlotIndexSetInteger(0,PLOT_SHIFT,shift_prd);
// Set indicator name
   IndicatorSetString(INDICATOR_SHORTNAME,"RMA Minor shift");
  
   // Set the name of the plot lines
   PlotIndexSetString(0,PLOT_LABEL,"Minor");
   PlotIndexSetString(1,PLOT_LABEL,"Minor Shift by "+(string)shift_prd);
// Set empty value for Values buffer

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE);

   Handle_minor=iRSI(NULL,0,RSIPeriod,PRICE_CLOSE);
   MAHandle_minor=iMA(NULL,0,MAPeriod,0,MODE_EMA,Handle_minor);

// Set the indexation order for buffers (as series)
   ArraySetAsSeries(Minor,true);
   ArraySetAsSeries(Minor_shift,true);
   ArraySetAsSeries(RoC_Minor,true);

   return(0);
  }
// note that the function parameters can be renamed
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[])
  {
   int toCount=(int)MathMin(rates_total,rates_total-prev_calculated+1);
   //int toCount = rates_total - prev_calculated +  shift_prd;



    //Print("Array size",ArraySize(RoC_Minor));
   if(prev_calculated<0 || prev_calculated>rates_total)
     {
      // toCount = rates_total;
     }

   int copied= CopyBuffer(MAHandle_minor,0,0,toCount,Minor);
   if(copied == -1)
     {
      Print("Error while copying Minor shift. Error №",GetLastError());
      return 0;
     }
   for(int i=0;i<100;i++)
     {
     Minor_shift[i]=Minor[i+shift_prd];
     //Minor_shift[i]=Minor[i];
     }

    for(int i=0;i<100;i++)
     {
     RoC_Minor[i]=Minor[i]-Minor[i+shift_prd];
     } 
   return rates_total;
  }

// the function is not obligatory in a code
/*
void OnDeinit()
{}
*/
//+------------------------------------------------------------------+
Rashid Umarov
Admin
11710
Rashid Umarov 2010.05.12 13:11  
Please, format a source code properly, read article MQL5.community - User Memo

The   button of the object inserting menu is intended to insert the initial MQL code into the text of the message. An empty window to paste the code in appears as soon as you press this button. In order to finish code adding you should press the Insert button. To cancel the operation you should press the Cancel button. The example of inserting the code is given at the corresponding section.
Jiten
30
Jiten 2010.05.12 13:28  
Rosh:
Please, format a source code properly, read article MQL5.community - User Memo
//+------------------------------------------------------------------+
//|                                              RMA_Minor_shift.mq5 |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright   "2009, MetaQuotes Software Corp."
#property link        "http://www.mql5.com"
#property description "RMA Minor Shift"
//--- indicator settings
#property indicator_level1 40
#property indicator_level2 60

#property indicator_separate_window // indicator will be displayed in the separate subwindow

#property indicator_buffers 3       // buffers used
#property indicator_plots 2         // buffers displayed

#property indicator_color1 Black // we use 2 colors
#property indicator_type1 DRAW_LINE          // and special color style
#property indicator_color2 Red // we use 2 colors
#property indicator_type2 DRAW_LINE          // and special color style

//---- buffers
double Minor[];                 // buffer for values
double Minor_shift[];           // buffer for values
double RoC_Minor[];                 // buffer for values

                                    // indicator input parameters
int                  RSIPeriod      = 7;
int                  MAPeriod       = 7;
int                  shift_prd      = 5;

// variable to store indicator handle
int Handle_minor,MAHandle_minor;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
// set the indicator buffers
// set Values as a buffer for displaying
   SetIndexBuffer(0,RoC_Minor,          INDICATOR_DATA);
   SetIndexBuffer(1,Minor,    INDICATOR_DATA);
//--- set accuracy
   IndicatorSetInteger(INDICATOR_DIGITS,2);
// Set beginning of Values buffer drawing
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,RSIPeriod);
// Shifting the plot
//PlotIndexSetInteger(0,PLOT_SHIFT,shift_prd);
// Set indicator name
   IndicatorSetString(INDICATOR_SHORTNAME,"RMA Minor shift");
   
   // Set the name of the plot lines
   PlotIndexSetString(0,PLOT_LABEL,"Minor");
   PlotIndexSetString(1,PLOT_LABEL,"Minor Shift by "+(string)shift_prd);
// Set empty value for Values buffer

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE);

   Handle_minor=iRSI(NULL,0,RSIPeriod,PRICE_CLOSE);
   MAHandle_minor=iMA(NULL,0,MAPeriod,0,MODE_EMA,Handle_minor);

// Set the indexation order for buffers (as series)
   ArraySetAsSeries(Minor,true);
   ArraySetAsSeries(Minor_shift,true);
   ArraySetAsSeries(RoC_Minor,true);

   return(0);
  }
// note that the function parameters can be renamed
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[])
  {
   int toCount=(int)MathMin(rates_total,rates_total-prev_calculated+1);
  
   if(prev_calculated<0 || prev_calculated>rates_total)
     {
       toCount = rates_total;
     }

   int copied= CopyBuffer(MAHandle_minor,0,0,toCount,Minor);
   if(copied == -1)
     {
      Print("Error while copying Minor shift. Error №",GetLastError());
      return 0;
     }
    int pos = prev_calculated-1;
    Print(pos);
   for(int i=0;i<100;i++)
     {
     Minor_shift[i]=Minor[i];
     //Minor_shift[i]=Minor[i];
     } 

    for(int i=0;i<100;i++)
     {
     RoC_Minor[i]=Minor[i]-Minor[i+shift_prd];
     }  
   return rates_total;
  } 

// the function is not obligatory in a code
/*
void OnDeinit()
{}
*/
//+------------------------------------------------------------------+

Ilyas
1205
Ilyas 2010.05.12 14:23  
kjitender:

You should specify Minor_shift[] as indicator buffer calculation.

SetIndexBuffer(2,Minor_shift, INDICATOR_CALCULATIONS);


/
To add comments, please log in or register