Author: Copyright 2015, mrak297.
Price Data Components
Series array that contains close prices for each bar
0 Views
0 Downloads
0 Favorites
DXYv.3.1
//+------------------------------------------------------------------+
//|                                                      DXYv3.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  "DXY"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrDodgerBlue
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- indicator buffers
double         DXYBuffer[];
string         Pair[]={"EURUSD","USDJPY","GBPUSD","USDCAD","USDSEK","USDCHF"};
double         Weight[]={-0.576,0.136,-0.119,0.091,0.042,0.036};
double         usdx;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
   IndicatorShortName("DXY");
   SetIndexBuffer(0,DXYBuffer);
   IndicatorDigits(2);

   for(int i=0; i<6; 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[])
  {
   DXYBuffer[0]=dxy();
//---
   for(int i=1; i<Bars-1; i++)
     {
      usdx=dxyshift(time[i]);
      if(usdx!=EMPTY) DXYBuffer[i]=usdx;
      else DXYBuffer[i]=DXYBuffer[i-1];
     }
//---
   return(rates_total);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double dxy()
  {
   double id=50.14348112;

   for(int i=0; i<6; i++)
      id*=MathPow(SymbolInfoDouble(Pair[i],SYMBOL_BID),Weight[i]);
//---
   return(id);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double dxyshift(const datetime &bartime)
  {
   double idx=50.14348112;
   int shft;
//---
   for(int i=0; i<6; 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

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 ---