Индикатор индекса Евро

 

Добрый день!

Я скачал тут индикатор индекса евро, но когда его открываю, то получаю пустое окно. Хочу узнать в чём проблема:


//+------------------------------------------------------------------+

//|                                                      ECXv3.1.mq4 |

//|                                         Copyright 2015, mrak297. |

//|                                             https://www.mql5.com |

//+------------------------------------------------------------------+

#property copyright "Copyright 2015, mrak297."

#property link      "https://www.mql5.com"

#property version   "3.1"

#property strict

#property indicator_separate_window

#property indicator_buffers 1

#property indicator_plots   1

//--- plot Label1

#property indicator_label1  "ECX"

#property indicator_type1   DRAW_LINE

#property indicator_color1  clrLimeGreen

#property indicator_style1  STYLE_SOLID

#property indicator_width1  1

//--- indicator buffers

double         ECXBuffer[];

string         Pair[]={"EURUSD","EURJPY","EURGBP","EURSEK","EURCHF"};

double         Weight[]={0.3155,0.1891,0.3056,0.0785,0.1113};

double         eurx;

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

int OnInit()

  {

   IndicatorShortName("ECX");

   SetIndexBuffer(0,ECXBuffer);

   IndicatorDigits(2);

//---

   for(int i=0; i<5; i++)

     { SymbolSelect(Pair[i],true); }


   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

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[])

  {

   ECXBuffer[0]=ecx();

//---

   for(int i=1; i<Bars-1; i++)

     {

      eurx=ecxshift(time[i]);

      if(eurx!=EMPTY) ECXBuffer[i]=eurx;

      else ECXBuffer[i]=ECXBuffer[i-1];

     }

   return(rates_total);

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

double ecx()

  {

   double id=34.38805726;

//---

   for(int i=0; i<5; i++)

      id*=MathPow(SymbolInfoDouble(Pair[i],SYMBOL_BID),Weight[i]);

//---

   return(id);

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

double ecxshift(const datetime &bartime)

  {

   double idx=34.38805726;

   int shft;

//---

   for(int i=0; i<5; i++)

     {

      shft=iBarShift(Pair[i],0,bartime,true);

      if(shft!=EMPTY)

         idx*=MathPow(iClose(Pair[i],0,shft),Weight[i]);

      else return(EMPTY);

     }

//---

   return(idx);

  }

//+------------------------------------------------------------------+


Открой новые возможности в MetaTrader 5 с сообществом и сервисами MQL5
Открой новые возможности в MetaTrader 5 с сообществом и сервисами MQL5
  • www.mql5.com
Задавайте вопросы по техническому анализу, обсуждайте торговые системы и улучшайте свои навыки программирования торговых стратегий на языке MQL5. Общайтесь и обменивайтесь опытом на форуме с трейдерами всего мира и помогайте ответами новичкам — наше сообщество развивается вместе с вами. О неравной вероятности движения цены вверх или вниз...
 
  1. Пожалуйста, вставляйте код при помощи кнопки </> или Alt+S.
  2. Индикатор использует для анализа редкую пару - EURSEK. Если ДЦ ее не поддерживает, то все значения, получаемые от нее, будут равны нулю. А для расчета индекса используется умножение одного значения на другое. Если хотя бы одно из них 0, то и весь результат 0. Вставил в код проверки на 0, но это костыльное решение. По хорошему надо было бы еще в OnInit() исключить отсутствующие пары из списка.
#property strict
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1

//--- plot Label1
#property indicator_label1  "ECX"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrLimeGreen
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1

//--- indicator buffers
double         ECXBuffer[];
string         Pair[]= {"EURUSD","EURJPY","EURGBP","EURSEK","EURCHF"};
double         Weight[]= {0.3155,0.1891,0.3056,0.0785,0.1113};
double         eurx;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
{
   IndicatorShortName("ECX");
   SetIndexBuffer(0,ECXBuffer);
   IndicatorDigits(2);

   for(int i=0; i<5; i++)

     { SymbolSelect(Pair[i],true); }

   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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[])
{
   ECXBuffer[0]=ecx();

   for(int i=1; i < Bars - 1; i++)
   {
      eurx=ecxshift(time[i]);
      if(eurx!=EMPTY)
         ECXBuffer[i]=eurx;
      else
         ECXBuffer[i]=ECXBuffer[i-1];
     }

   return(rates_total);
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double ecx()
{
   double id=34.38805726;

   for(int i=0; i<5; i++)
   {
      double fBid = SymbolInfoDouble(Pair[i],SYMBOL_BID);
      if(fBid == 0)
         continue;

      id *= MathPow(fBid, Weight[i]);
   }

   return(id);
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double ecxshift(const datetime &bartime)
{
   double idx=34.38805726;
   int shft;
   for(int i=0; i<5; i++)
   {
      ResetLastError();
      shft=iBarShift(Pair[i],0,bartime,true);
      if(shft < 0 || GetLastError() != ERR_NO_ERROR)
         continue;

      if(shft!=EMPTY)
         idx*=MathPow(iClose(Pair[i],0,shft),Weight[i]);
      else
         return(EMPTY);
   }

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


 
//+------------------------------------------------------------------+
//|                                                      ECXv3.1.mq4 |
//|                                         Copyright 2015, mrak297. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, mrak297."
#property link      "https://www.mql5.com"
#property version   "3.1"
#property strict
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot ECX
#property indicator_label1  "ECX"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrLimeGreen
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- indicator buffers
double         ECXBuffer[];
string         Pair[]={"EURUSD","EURJPY","EURGBP","EURSEK","EURCHF"};
double         Weight[]={0.3155,0.1891,0.3056,0.0785,0.1113};
double         eurx;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
   IndicatorShortName("ECX");
   SetIndexBuffer(0,ECXBuffer);
   IndicatorDigits(2);
//---
   for(int i=0; i<5; i++)
     { SymbolSelect(Pair[i],true); }

   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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[])
  {
   ECXBuffer[0]=ecx();
//---
   for(int i=1; i<Bars-1; i++)
     {
      eurx=ecxshift(time[i]);
      if(eurx!=EMPTY) ECXBuffer[i]=eurx;
      else ECXBuffer[i]=ECXBuffer[i-1];
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double ecx()
  {
   double id=34.38805726;
//---
   for(int i=0; i<5; i++)
      id*=MathPow(SymbolInfoDouble(Pair[i],SYMBOL_BID),Weight[i]);
//---
   return(id);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double ecxshift(const datetime &bartime)
  {
   double idx=34.38805726;
   int shft;
//---
   for(int i=0; i<5; i++)
     {
      shft=iBarShift(Pair[i],0,bartime,true);
      if(shft!=EMPTY)
         idx*=MathPow(iClose(Pair[i],0,shft),Weight[i]);
      else return(EMPTY);
     }
//---
   return(idx);
  }
//+------------------------------------------------------------------+
Причина обращения: