Нужна помощь индикатор не рисует

 

Здравствуйте. Нужна помощь в поиске логических ошибок (ошибок и предупреждений при компиляции нет).

должно получится как на скриншоте.


вот составленный мною код, но на экран он ничего не выводит, почему то.

вот код индикатора.

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
#property indicator_type1   DRAW_NONE
// Входные параметры
input int  ExtDepth        = 12;
input int  ExtDeviation    = 5;
input int  ExtBackstep     = 3;
input bool ShowUpperTrend  = true;
input bool ShowLowerTrend  = true;
input int  RayForwardBars  = 30;
input color UpperColor     = clrSkyBlue;
input color LowerColor     = clrSalmon;
// Фиктивный буфер для компиляции
double dummyBuffer[];
int OnInit()
{
   SetIndexBuffer(0, dummyBuffer, INDICATOR_DATA);
   return INIT_SUCCEEDED;
}
void OnDeinit(const int reason)
{
   ObjectDelete(0, "UpperTrend");
   ObjectDelete(0, "LowerTrend");
}
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 foundMax = 0, foundMin = 0;
   int maxIndex1 = -1, maxIndex2 = -1;
   int minIndex1 = -1, minIndex2 = -1;
   double zz;
   for (int i = 0; i < rates_total && (foundMax < 2 || foundMin < 2); i++)
   {
      zz = iCustom(_Symbol, _Period, "Examples\\ZigZag", ExtDepth, ExtDeviation, ExtBackstep, 0, i);
      if (zz != 0.0)
      {
         if (MathAbs(zz - high[i]) < _Point * 10) // максимум
         {
            if (foundMax == 0) { maxIndex1 = i; foundMax++; }
            else if (foundMax == 1) { maxIndex2 = i; foundMax++; }
         }
         else if (MathAbs(zz - low[i]) < _Point * 10) // минимум
         {
            if (foundMin == 0) { minIndex1 = i; foundMin++; }
            else if (foundMin == 1) { minIndex2 = i; foundMin++; }
         }      }   }
   // Построение верхней линии по максимумам
   if (foundMax == 2 && ShowUpperTrend)
   {
      datetime t1 = time[maxIndex2];
      datetime t2 = time[maxIndex1];
      double p1 = high[maxIndex2];
      double p2 = high[maxIndex1];
      DrawTrendLine("UpperTrend", t1, p1, t2, p2, UpperColor);
   }
   // Построение нижней линии по минимумам
   if (foundMin == 2 && ShowLowerTrend)
   {
      datetime t1 = time[minIndex2];
      datetime t2 = time[minIndex1];
      double p1 = low[minIndex2];
      double p2 = low[minIndex1];
      DrawTrendLine("LowerTrend", t1, p1, t2, p2, LowerColor);
   }
   return rates_total;
}
void DrawTrendLine(string name, datetime t1, double p1, datetime t2, double p2, color clr)
{
   if (ObjectFind(0, name) != -1)
      ObjectDelete(0, name);
   if (ObjectCreate(0, name, OBJ_TREND, 0, t1, p1, t2, p2))
   {
      ObjectSetInteger(0, name, OBJPROP_COLOR, clr);
      ObjectSetInteger(0, name, OBJPROP_WIDTH, 2);
      ObjectSetInteger(0, name, OBJPROP_RAY_RIGHT, true);
   }}
 
Igor Nagorniuk:

Здравствуйте. Нужна помощь в поиске логических ошибок (ошибок и предупреждений при компиляции нет).

должно получится как на скриншоте.


вот составленный мною код, но на экран он ничего не выводит, почему то.

вот код индикатора.

стандартно - добавить ChartRedraw(), без него автоматом не нарисуется, точнее нарисуется но потом когда-нибудь

 
Maxim Kuznetsov #:

стандартно - добавить ChartRedraw(), без него автоматом не нарисуется, точнее нарисуется но потом когда-нибудь

добавил ChartRedraw() не рисуется. Однако, спасибо тебе: 1. за помощь: 2. При редактирование кода нашел пару недочётов (подправил цвета). 

вот код, который получился у меня

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_plots   3
//
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrSkyBlue
#property indicator_style1 STYLE_SOLID
#property indicator_width1 2
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrSalmon
#property indicator_style2 STYLE_SOLID
#property indicator_width2 2
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrYellow
#property indicator_style3 STYLE_SOLID
#property indicator_width3 2
//--- Входные параметры
input int    ExtDepth        = 12;
input int    ExtDeviation    = 5;
input int    ExtBackstep     = 3;
input bool   ShowUpperTrend  = true;
input bool   ShowLowerTrend  = true;
input int    RayForwardBars  = 30;
input color  UpperColor      = clrSkyBlue;
input color  LowerColor      = clrSalmon;
input color  MiddleColor     = clrYellow;
//--- Индикаторные буферы
double UpperBuffer[];
double LowerBuffer[];
double MiddleBuffer[];

//+------------------------------------------------------------------+
int OnInit()
{
   SetIndexBuffer(0, UpperBuffer, INDICATOR_DATA);
   SetIndexBuffer(1, LowerBuffer, INDICATOR_DATA);
   SetIndexBuffer(2, MiddleBuffer, INDICATOR_DATA);
   IndicatorSetInteger(INDICATOR_DIGITS, _Digits);
   PlotIndexSetString(0, PLOT_LABEL, "Upper Trend");
   PlotIndexSetString(1, PLOT_LABEL, "Lower Trend");
   PlotIndexSetString(2, PLOT_LABEL, "Middle Trend");
   return INIT_SUCCEEDED;
}
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   ObjectDelete(0, "UpperTrend");
   ObjectDelete(0, "LowerTrend");
}
//+------------------------------------------------------------------+
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 foundMax = 0, foundMin = 0;
   int maxIndex1 = -1, maxIndex2 = -1;
   int minIndex1 = -1, minIndex2 = -1;
   double zz;
   ArraySetAsSeries(UpperBuffer, true);
   ArraySetAsSeries(LowerBuffer, true);
   ArraySetAsSeries(MiddleBuffer, true);
   // Поиск максимумов и минимумов
   for (int i = 0; i < rates_total && (foundMax < 2 || foundMin < 2); i++)
   {
      zz = iCustom(_Symbol, _Period, "Examples\\ZigZag", ExtDepth, ExtDeviation, ExtBackstep, 0, i);
      if (zz != 0.0)
      {
         if (MathAbs(zz - high[i]) < _Point * 10) // максимум
         {
            if (foundMax == 0) { maxIndex1 = i; foundMax++; }
            else if (foundMax == 1) { maxIndex2 = i; foundMax++; }
         }
         else if (MathAbs(zz - low[i]) < _Point * 10) // минимум
         {
            if (foundMin == 0) { minIndex1 = i; foundMin++; }
            else if (foundMin == 1) { minIndex2 = i; foundMin++; }
         }      }   }
   if (foundMax == 2 && foundMin == 2)
   {
      // Экстремумы (пары точек)
      double p1 = high[maxIndex2];
      double p2 = high[maxIndex1];
      double p3 = low[minIndex2];
      double p4 = low[minIndex1];
      // Убедимся, что линии продолжаются
      for (int i = 0; i < rates_total; i++)
      {
         // Вычисление верхней линии тренда (продолжение линии)
         UpperBuffer[i] = p1 + (time[i] - time[maxIndex2]) * (p2 - p1) / (time[maxIndex1] - time[maxIndex2]);
         // Вычисление нижней линии тренда (продолжение линии)
         LowerBuffer[i] = p3 + (time[i] - time[minIndex2]) * (p4 - p3) / (time[minIndex1] - time[minIndex2]);
         // Средняя линия канала
         MiddleBuffer[i] = (UpperBuffer[i] + LowerBuffer[i]) / 2;
      }   }
   else
   {
      for (int i = 0; i < rates_total; i++)
      {
         UpperBuffer[i] = EMPTY_VALUE;
         LowerBuffer[i] = EMPTY_VALUE;
         MiddleBuffer[i] = EMPTY_VALUE;
      }  } 
   // Перерисовка графика
   ChartRedraw();
   return rates_total;
}