instrument3

Author: Me
Price Data Components
Series array that contains close prices for each bar
0 Views
0 Downloads
0 Favorites
instrument3
//+------------------------------------------------------------------+
//|                                                      Indicator3  |
//|                        original version by Mike Zhitnev was used |
//|                                       http://www.mql5.com        |
//+------------------------------------------------------------------+
#property copyright "Me"
#property link      ""

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red
#property indicator_style1 STYLE_DOT

//--- input parameters
extern string Instrument="EURUSD"; //any instrument or one of standard indexes - USD, EUR, JPY, CHF, NZD, GBP
extern double Ratio = 0.01; //ratio by which index is multiplied to fit the graph. Not needed for other instruments, point values are used.
extern bool Inverted=false; //invert value
extern string SyncPeriod="auto"; //period of sync with graph: H=each hour, D=each day, W=on Mondays, MN=1st day of each month, Y=on the January 1st, nosync or auto

int N1;
double T1[]; //---- buffers
string Instr;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   SetIndexBuffer(0,T1);
   SetIndexLabel(0,Instrument);
   IndicatorDigits(2);
   N1=1;
   Instr=Instrument;
   if(Instr=="USD" || Instr=="EUR" || Instr=="GBP" || Instr=="CHF" || Instr=="JPY" || Instr=="NZD")
      Instr="USDCHF";
   else Ratio=Point/MarketInfo(Instrument,MODE_POINT);

   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
double _MathPow(double a,double b)
  {
   if(a)
      return MathPow(a,b);
   return 1;
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double _myClose(int i)
  {
   if(Instrument=="USD")
      return 50.14348112*_MathPow(iClose("EURUSD",0,i),-0.576)*_MathPow(iClose("USDJPY",0,i),0.136)*_MathPow(iClose("GBPUSD",0,i),-0.119)*_MathPow(iClose("USDCAD",0,i),0.091)*_MathPow(iClose("USDSEK",0,i),0.042)*_MathPow(iClose("USDCHF",0,i),0.036);
   if(Instrument=="EUR")//ECX, EURX or E
      return 34.38805726*_MathPow(iClose("EURUSD",0,i),0.3155)*_MathPow(iClose("EURGBP",0,i),0.3056)*_MathPow(iClose("EURJPY",0,i),0.1891)*_MathPow(iClose("EURCHF",0,i),0.1113)*_MathPow(iClose("EURSEK",0,i),0.0785);
   if(Instrument=="GBP")
      return 34.38805726*_MathPow(iClose("GBPUSD",0,i),0.3155)*_MathPow(iClose("EURGBP",0,i),-0.3056)*_MathPow(iClose("GBPJPY",0,i),0.1891)*_MathPow(iClose("GBPCHF",0,i),0.1113)*_MathPow(iClose("GBPSEK",0,i),0.0785);
   if(Instrument=="CHF")
      return 34.38805726*_MathPow(iClose("USDCHF",0,i),-0.3155)*_MathPow(iClose("EURCHF",0,i),-0.3056)*_MathPow(iClose("CHFJPY",0,i),0.1891)*_MathPow(iClose("GBPCHF",0,i),-0.1113)*_MathPow(iClose("NZDCHF",0,i),0.0785);
   if(Instrument=="JPY")
      return 34.38805726*_MathPow(iClose("USDJPY",0,i),-0.3155)*_MathPow(iClose("EURJPY",0,i),-0.3056)*_MathPow(iClose("CHFJPY",0,i),-0.1891)*_MathPow(iClose("GBPJPY",0,i),-0.1113)*_MathPow(iClose("AUDJPY",0,i),-0.0785);
   if(Instrument=="NZD") //numbers from new zealand trade turnover by country: http://www.rbnz.govt.nz/research_and_publications/reserve_bank_bulletin/2013/2013dec76_4rosboroughshareef.pdf
      return 34.38805726*_MathPow(iClose("NZDUSD",0,i),0.189)*_MathPow(iClose("EURNZD",0,i),-0.094)*_MathPow(iClose("GBPNZD",0,i),-0.409)*_MathPow(iClose("NZDJPY",0,i),-0.056)*_MathPow(iClose("NZDSGD",0,i),-0.057);
   return iClose(Instrument,0,i);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double myClose(int i)
  {
   if(Inverted)
      return 1/_myClose(i)*Ratio;
   else
      return _myClose(i)*Ratio;
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double myDelta(double Delta,int I,int I2)
  {
   if(SyncPeriod=="no" || SyncPeriod=="nosync") return Delta;
//H,D,W,MN
   if((SyncPeriod=="auto" && Period()==PERIOD_M1 || SyncPeriod=="H") && TimeHour(Time[I])!=TimeHour(Time[I+1]))
      Delta=myClose(I2)-Open[I];
   if((SyncPeriod=="auto" && Period()>PERIOD_M1 && Period()<=PERIOD_H1 || SyncPeriod=="D") && TimeDay(Time[I])!=TimeDay(Time[I+1]))
      Delta=myClose(I2)-Open[I];
   if((SyncPeriod=="auto" && Period()>PERIOD_H1 && Period()<=PERIOD_D1 || SyncPeriod=="W") && TimeDayOfWeek(Time[I])==1)//on Monday
      Delta=myClose(I2)-Open[I];
   if((SyncPeriod=="auto" && Period()>PERIOD_D1 && Period()<=PERIOD_MN1 || SyncPeriod=="Y") && TimeDayOfYear(Time[I])==1)//on the 1st of January
      Delta=myClose(I2)-Open[I];
   if(SyncPeriod=="MN" && TimeDay(Time[I])==1)
      Delta=myClose(I2)-Open[I];
   return Delta;
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {

   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars;
   int imax=N1;
   if(counted_bars==0) limit-=1+imax;

   int I0=limit;

   int I=I0;
   double Delta=0;
   while(I>=0)
     {
      int Index=iBarShift(Instr,0,Time[I]);
      Delta= myDelta(Delta,I,Index);
      T1[I]=myClose(Index)-Delta;
      I--;
     }
   return 0;
  }
//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---