Author: Copyright 2015, mrak297.
Price Data Components
Series array that contains close prices for each bar
0 Views
0 Downloads
0 Favorites
ECXv.3.1
//+------------------------------------------------------------------+
//|                                                      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);
  }
//+------------------------------------------------------------------+

Comments