Помогите разобраться с индикатором!!!!

 

Доброго времени суток уважаемые господа программисты! Столкнулся с такой проблемой. Хочу написать индикатор, вернее я его уже написал. Он отображается правильно, но больше не рисует. То есть при появлении новых баров индикатор не обновляет данные.

При установке индикатора на график он показывает все правильно.

Правильно


Но с появлением новых баров он не рисует

не рисует

При переключении тф все нормально, и потом опять не рисует

Вот его код:

//+------------------------------------------------------------------+
//|                                                         OCHL.mq4 |
//|                                                             Вдим |
//|                                       http://www.prostoforex.com |
//+------------------------------------------------------------------+
#property copyright "Вдим"
#property link      "http://www.prostoforex.com"
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_plots   4
//--- plot Open
#property indicator_label1  "Open"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrBlueViolet
#property indicator_style1  STYLE_SOLID
#property indicator_width1  2
//--- plot Close
#property indicator_label2  "Close"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrLightSlateGray
#property indicator_style2  STYLE_SOLID
#property indicator_width2  2
//--- plot High
#property indicator_label3  "High"
#property indicator_type3   DRAW_LINE
#property indicator_color3  clrBlue
#property indicator_style3  STYLE_SOLID
#property indicator_width3  2
//--- plot Low
#property indicator_label4  "Low"
#property indicator_type4   DRAW_LINE
#property indicator_color4  clrDeepPink
#property indicator_style4  STYLE_SOLID
#property indicator_width4  2

input int Per            = 5;

//--- indicator buffers
double         OpenBuffer[];
double         CloseBuffer[];
double         HighBuffer[];
double         LowBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,OpenBuffer);
   SetIndexBuffer(1,CloseBuffer);
   SetIndexBuffer(2,HighBuffer);
   SetIndexBuffer(3,LowBuffer);
   
   //SetIndexStyle(0,DRAW_LINE,0,2);
   //SetIndexStyle(1,DRAW_LINE,0,2);
   //SetIndexStyle(2,DRAW_LINE,0,2);
   //SetIndexStyle(3,DRAW_LINE,0,2);
   
//---
   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[])
{  
                int Counted_bars=IndicatorCounted()+1+Per; // Количество просчитанных баров 
                if(Counted_bars<0) return(-1);
                if(Counted_bars>0)Counted_bars--;
                int limit=Bars-Counted_bars;

                for(int i=0; i<limit; i++){ 
                 OpenBuffer[i]=(Open[i]-Open[i+Per])+(Close[i]-Close[i+Per])+(High[i]-(High[i+Per])+(Low[i]-Low[i+Per]));
                 

                } 
   

return(rates_total);
}
//+------------------------------------------------------------------+


Где здесь ошибка, и как ее исправить?

Заранее благодарен за ответы.

#s3gt_translate_tooltip_mini { display: none !important; }
 
Vadim Kazakevich:

Доброго времени суток уважаемые господа программисты! Столкнулся с такой проблемой. Хочу написать индикатор, вернее я его уже написал. Он отображается правильно, но больше не рисует. То есть при появлении новых баров индикатор не обновляет данные.

При установке индикатора на график он показывает все правильно.


Но с появлением новых баров он не рисует

При переключении тф все нормально, и потом опять не рисует

Вот его код:


Где здесь ошибка, и как ее исправить?

Заранее благодарен за ответы.

#s3gt_translate_tooltip_mini { display: none !important; }
//+------------------------------------------------------------------+
//|                                                         OCHL.mq4 |
//|                                                             Вдим |
//|                                       http://www.prostoforex.com |
//+------------------------------------------------------------------+
#property copyright "Вдим"
#property link      "http://www.prostoforex.com"
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_plots   4
//--- plot Open
#property indicator_label1  "Open"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrBlueViolet
#property indicator_style1  STYLE_SOLID
#property indicator_width1  2
//--- plot Close
#property indicator_label2  "Close"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrLightSlateGray
#property indicator_style2  STYLE_SOLID
#property indicator_width2  2
//--- plot High
#property indicator_label3  "High"
#property indicator_type3   DRAW_LINE
#property indicator_color3  clrBlue
#property indicator_style3  STYLE_SOLID
#property indicator_width3  2
//--- plot Low
#property indicator_label4  "Low"
#property indicator_type4   DRAW_LINE
#property indicator_color4  clrDeepPink
#property indicator_style4  STYLE_SOLID
#property indicator_width4  2

input int Per=5;

//--- indicator buffers
double         OpenBuffer[];
double         CloseBuffer[];
double         HighBuffer[];
double         LowBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,OpenBuffer);
   SetIndexBuffer(1,CloseBuffer);
   SetIndexBuffer(2,HighBuffer);
   SetIndexBuffer(3,LowBuffer);

//SetIndexStyle(0,DRAW_LINE,0,2);
//SetIndexStyle(1,DRAW_LINE,0,2);
//SetIndexStyle(2,DRAW_LINE,0,2);
//SetIndexStyle(3,DRAW_LINE,0,2);

//---
   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[])
  {
//                int Counted_bars=IndicatorCounted()+1+Per; // Количество просчитанных баров 
//                if(Counted_bars<0) return(-1);
//                if(Counted_bars>0)Counted_bars--;
//                int limit=Bars-Counted_bars;

   int limit=rates_total-prev_calculated;
   if(limit>1)
     {
      limit=rates_total-Per;
     }

   for(int i=0; i<limit; i++)
     {
      OpenBuffer[i]=(Open[i]-Open[i+Per])+(Close[i]-Close[i+Per])+(High[i]-(High[i+Per])+(Low[i]-Low[i+Per]));
     }

   return(rates_total);
  }
//+------------------------------------------------------------------+

Можно так сделать.

 
Victor Nikolaev:

Можно так сделать.

Спасибо! Помогло!

Но я так и не понял, что было не так. При компиляции ошибок нет, при установке на график тоже.

Может быть внесете ясность?

 
Vadim Kazakevich:

Спасибо! Помогло!

Но я так и не понял, что было не так. При компиляции ошибок нет, при установке на график тоже.

Может быть внесете ясность?

Был выход за пределы массива

Причина обращения: