Indexes_v9L

Download script
Author: Copyright � 2009, Xupypr
Indexes_v9L

Overview of the Currency Index Tool

This script functions as a comprehensive tracking dashboard designed to monitor the relative performance of major currencies against the US Dollar (USD). Rather than looking at individual price movements in isolation, it synthesizes data from multiple currency pairs to provide a bird's-eye view of market trends.

Core Functionality

1. Multi-Currency Monitoring The script automatically tracks a specific basket of symbols including AUDUSD, EURUSD, GBPUSD, NZDUSD, USDCAD, USDCHF, and USDJPY. By analyzing these pairs simultaneously, it calculates a unified "Index" that reflects the overall strength or weakness of various currencies relative to the Dollar.

2. Dynamic Baseline Calculation Users can choose how the tool determines its starting point (the 0% reference mark). The logic allows for three distinct behaviors:

  • Current Bar: Resets the baseline to the current live price.
  • Previous Higher Timeframe: Sets the baseline based on the start of a larger time period (e.g., if you are viewing a 1-hour chart, it may use the start of the daily candle).
  • Custom Date/Time: Allows the user to define a specific point in history as the fixed reference mark.

3. Visual Data Representation The tool populates a separate window on your trading platform with several visual elements:

  • Histograms: These show the real-time fluctuation of the indices for various currencies, helping you see which are trending upward or downward.
  • Highs and Lows: The script tracks and displays the maximum and minimum levels reached during the current tracking period.
  • On-Screen Labels: It dynamically prints the name of each currency along with its current index value directly on the chart, providing instant information without needing to click through multiple windows.

4. Alert System and Tracking Steps To help traders identify significant movements without constantly watching the screen, the script includes a "Step Size" logic:

  • It monitors the movement of the currency indices.
  • If a currency moves by a specific amount (defined by the user), the tool recognizes this as a significant milestone.
  • Notifications: If enabled, the tool can trigger an alert when a currency hits these predetermined milestones, providing an automated way to stay informed about major trend shifts.

Summary for the User

Essentially, this script acts as a "Market Pulse" monitor. It strips away the noise of individual price ticks and gives you a structured, visual representation of how different global currencies are performing against the Dollar from a specific starting point in time. It is designed to help traders identify broad market sentiment and receive notifications when specific performance thresholds are crossed.

Price Data Components
Series array that contains close prices for each barSeries array that contains open time of each barSeries array that contains open prices of each bar
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
12 Views
0 Downloads
0 Favorites
Indexes_v9L
//+------------------------------------------------------------------+
//|                                                  Indexes_v9L.mq4 |
//|                                         Copyright © 2009, Xupypr |
//|                              http://www.mql4.com/ru/users/Xupypr |
//|                                             Âåðñèÿ îò 27.05.2009 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, Xupypr"
#property link      "http://www.mql4.com/ru/users/Xupypr"

#property indicator_separate_window
#property indicator_buffers 5
#property indicator_level1 0
#property indicator_color1 SteelBlue
#property indicator_color2 SteelBlue
#property indicator_color3 OrangeRed
#property indicator_color5 Silver
#property indicator_width1 3
#property indicator_width2 3
#property indicator_width3 3
//---- input parameters
extern string Start_Time="2008.08.04 00:00"; // òî÷êà îò÷¸òà (â íåé âñå èíäåêñû ðàâíû 0%)
extern int    Choice_Start_Point=1;          // âûáîð òî÷êè îò÷¸òà: 1-ïî òåêóùåìó áàðó, 2-ïî áàðó ñòàðøåãî ÒÔ, 3-ïî çàäàííîìó âðåìåíè
extern bool   Use_Alert=false;               // èñïîëüçîâàòü îïîâåùåíèå
extern double Step_Size=0.1;                 // äåëåíèå øêàëû, ïðè èçìåíåíèè èíäåêñà íà äàííóþ âåëè÷èíó ñðàáîòàåò ñèãíàë
extern int    Pos=0;                         // ïîëîæåíèå ãèñòîãðàììû íà âðåìåííîé øêàëå
//---- indicator buffers
double Index[],Max[],Min[],Balance[],Prev[];
double StepAlert[8];
string Currency[8]={"USD","EUR","GBP","JPY","CHF","AUD","CAD","NZD"};
string Symbols[7]={"AUDUSD","EURUSD","GBPUSD","NZDUSD","USDCAD","USDCHF","USDJPY"};

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
 SetIndexBuffer(0,Max);
 SetIndexStyle(0,DRAW_HISTOGRAM);
 SetIndexLabel(0,"Maximum");
 SetIndexEmptyValue(0,0.0);
 SetIndexBuffer(1,Min);
 SetIndexStyle(1,DRAW_HISTOGRAM);
 SetIndexLabel(1,"Minimum");
 SetIndexEmptyValue(1,0.0);
 SetIndexBuffer(2,Index);
 SetIndexStyle(2,DRAW_HISTOGRAM);
 SetIndexLabel(2,"Index");
 SetIndexBuffer(3,Balance);
 SetIndexStyle(3,DRAW_SECTION);
 SetIndexLabel(3,"Balance");
 SetIndexEmptyValue(3,0.0);
 SetIndexBuffer(4,Prev);
 SetIndexStyle(4,DRAW_ARROW);
 SetIndexArrow(4,119);
 SetIndexLabel(4,"Previous");
 IndicatorDigits(2);
 return(0);
}
//+------------------------------------------------------------------+
//|  Custom indicator deinitialization function                      |
//+------------------------------------------------------------------+
int deinit()
{
 for (int i=0;i<8;i++) ObjectDelete(Currency[i]+Pos);
 ObjectDelete("Name"+Pos);
 return(0);
}
//+------------------------------------------------------------------+
//| Indexes foreign exchange                                         |
//+------------------------------------------------------------------+
int start()
{
 int    i,window,shiftbar[7];
 bool   wait=false;
 double change,indexUSD,sprice[7];
 static datetime timebar;
  
 indexUSD=1.0;
 for (i=0;i<7;i++)
 {
  shiftbar[i]=iBarShift(Symbols[i],0,Time[0],true);
  if (shiftbar[i]==-1) wait=true;
  sprice[i]=StartPrice(i);
  if (sprice[i]==-1) wait=true;
  change=iClose(Symbols[i],0,shiftbar[i])/sprice[i];
  if (change!=0)
  {
   if (StringSubstr(Symbols[i],0,3)==Currency[0]) indexUSD*=change;
   if (StringSubstr(Symbols[i],3,3)==Currency[0]) indexUSD/=change;
  } 
 }
 if (wait) return(0);
 if (timebar!=Time[0])
 {
  timebar=Time[0];
  switch (Choice_Start_Point)
  {
   case 1:
   {
    ArrayInitialize(Index,EMPTY_VALUE);
    ArrayInitialize(Max,0.0);
    ArrayInitialize(Min,0.0);
    ArrayInitialize(Balance,0.0);
    ArrayInitialize(StepAlert,0.0);
    ArrayInitialize(Prev,EMPTY_VALUE);
   } break;
   case 2:
   {
    if (Time[0]==iTime(NULL,UpPeriod(),0))
    {
     ArrayInitialize(Index,EMPTY_VALUE);
     ArrayInitialize(Max,0.0);
     ArrayInitialize(Min,0.0);
     ArrayInitialize(Balance,0.0);
     ArrayInitialize(StepAlert,0.0);
     ArrayInitialize(Prev,EMPTY_VALUE);
    }
   }
   default:
   {
    for (i=0;i<8;i++)
    {
     Index[i+10*Pos]=Index[i+1+10*Pos];
     Max[i+10*Pos]=Max[i+1+10*Pos];
     Min[i+10*Pos]=Min[i+1+10*Pos];
     Prev[i+10*Pos]=Prev[i+1+10*Pos];
    }
    Index[8+10*Pos]=EMPTY_VALUE;
    Max[8+10*Pos]=0.0;
    Min[8+10*Pos]=0.0;
    Balance[9+10*Pos]=0.0;
    Balance[10+10*Pos]=0.0;
    Prev[8+10*Pos]=EMPTY_VALUE;
   }
  } 
 }
 indexUSD=100*MathPow(indexUSD,0.125);
 Index[7+10*Pos]=indexUSD-100.0;
 Index[6+10*Pos]=indexUSD*(iClose(Symbols[1],0,shiftbar[1])/sprice[1])-100.0;
 Index[5+10*Pos]=indexUSD*(iClose(Symbols[2],0,shiftbar[2])/sprice[2])-100.0;
 Index[4+10*Pos]=indexUSD/(iClose(Symbols[6],0,shiftbar[6])/sprice[6])-100.0;
 Index[3+10*Pos]=indexUSD/(iClose(Symbols[5],0,shiftbar[5])/sprice[5])-100.0;
 Index[2+10*Pos]=indexUSD*(iClose(Symbols[0],0,shiftbar[0])/sprice[0])-100.0;
 Index[1+10*Pos]=indexUSD/(iClose(Symbols[4],0,shiftbar[4])/sprice[4])-100.0;
 Index[0+10*Pos]=indexUSD*(iClose(Symbols[3],0,shiftbar[3])/sprice[3])-100.0;
 for (i=0;i<8;i++)
 {
  if (Index[i+10*Pos]>StepAlert[i]+Step_Size || Index[i+10*Pos]<StepAlert[i]-Step_Size)
  {
   Prev[i+10*Pos]=StepAlert[i];
   if (Index[i+10*Pos]>0) StepAlert[i]=MathFloor(Index[i+10*Pos]/Step_Size)*Step_Size;
   else StepAlert[i]=MathCeil(Index[i+10*Pos]/Step_Size)*Step_Size;
   if (Use_Alert) Alert("Èíäåêñ ",Currency[7-i]," äîñòèã îòìåòêè ",StepAlert[i]);
  }
  if (Index[i+10*Pos]>Max[i+10*Pos]) Max[i+10*Pos]=Index[i+10*Pos];
  if (Index[i+10*Pos]<Min[i+10*Pos]) Min[i+10*Pos]=Index[i+10*Pos];
  Balance[8+10*Pos]=MathMax(Max[ArrayMaximum(Max)],MathAbs(Min[ArrayMinimum(Min)]));
  Balance[9+10*Pos]=Balance[8+10*Pos]*(-1);
  if (ObjectFind(Currency[i]+Pos)==-1)
  {
   window=WindowFind(WindowExpertName());
   ObjectCreate(Currency[i]+Pos,OBJ_TEXT,window,Time[7-i+10*Pos],0);
   ObjectSetText(Currency[i]+Pos,Currency[i]+"   "+DoubleToStr(Index[7-i+10*Pos],2),8,"Arial",Gray);
   ObjectSet(Currency[i]+Pos,OBJPROP_ANGLE,90.0);
  }
  else
  {
   ObjectSet(Currency[i]+Pos,OBJPROP_TIME1,Time[7-i+10*Pos]);
   ObjectSet(Currency[i]+Pos,OBJPROP_PRICE1,0);
   ObjectSetText(Currency[i]+Pos,Currency[i]+"   "+DoubleToStr(Index[7-i+10*Pos],2),8,"Arial",Gray);
  }
 }
 if (ObjectFind("Name"+Pos)==-1)
 {
  window=WindowFind(WindowExpertName());
  ObjectCreate("Name"+Pos,OBJ_TEXT,window,Time[8+10*Pos],0);
  switch (Choice_Start_Point)
  {
   case 1: ObjectSetText("Name"+Pos,"Ïî òåêóùåìó ÒÔ: "+PeriodToStr(Period()),8,"Arial",Gray); break;
   case 2: ObjectSetText("Name"+Pos,"Ïî ñòàðøåìó ÒÔ: "+PeriodToStr(UpPeriod()),8,"Arial",Gray); break;
   default: ObjectSetText("Name"+Pos,"Ïî âðåìåíè: "+Start_Time,8,"Arial",Gray);
  }
  ObjectSet("Name"+Pos,OBJPROP_ANGLE,90.0);
 }
 else
 {
  ObjectSet("Name"+Pos,OBJPROP_TIME1,Time[8+10*Pos]);
  ObjectSet("Name"+Pos,OBJPROP_PRICE1,0);
  switch (Choice_Start_Point)
  {
   case 1: ObjectSetText("Name"+Pos,"Ïî òåêóùåìó ÒÔ: "+PeriodToStr(Period()),8,"Arial",Gray); break;
   case 2: ObjectSetText("Name"+Pos,"Ïî ñòàðøåìó ÒÔ: "+PeriodToStr(UpPeriod()),8,"Arial",Gray); break;
   default: ObjectSetText("Name"+Pos,"Ïî âðåìåíè: "+Start_Time,8,"Arial",Gray);
  }
 }
 return(0);
}

double StartPrice(int n)
{
 double sp,bar;
 switch (Choice_Start_Point)
 {
  case 1:  sp=iOpen(Symbols[n],0,iBarShift(Symbols[n],0,Time[0])); break;
  case 2:
  {
    bar=iBarShift(Symbols[n],UpPeriod(),Time[0],true);
    if (bar==-1) return(-1);
    else sp=iOpen(Symbols[n],UpPeriod(),bar);
  } break;
  default: sp=iOpen(Symbols[n],0,iBarShift(Symbols[n],0,StrToTime(Start_Time)));
 }
 return(sp);
}

int UpPeriod()
{
 int p;
 switch (Period())
 {
  case PERIOD_M1:  p=PERIOD_M5;  break;
  case PERIOD_M5:  p=PERIOD_M15; break;
  case PERIOD_M15: p=PERIOD_M30; break;
  case PERIOD_M30: p=PERIOD_H1;  break;
  case PERIOD_H1:  p=PERIOD_H4;  break;
  case PERIOD_H4:  p=PERIOD_D1;  break;
  case PERIOD_D1:  p=PERIOD_W1;  break;
  case PERIOD_W1:  p=PERIOD_MN1; break;
  case PERIOD_MN1: p=PERIOD_MN1;
 }
 return(p);
}

string PeriodToStr(int period)
{
 string p;
 switch (period)
 {
  case PERIOD_M1:  p="M1";  break;
  case PERIOD_M5:  p="M5";  break;
  case PERIOD_M15: p="M15"; break;
  case PERIOD_M30: p="M30"; break;
  case PERIOD_H1:  p="H1";  break;
  case PERIOD_H4:  p="H4";  break;
  case PERIOD_D1:  p="D1";  break;
  case PERIOD_W1:  p="W1";  break;
  case PERIOD_MN1: p="MN1";
 }
 return(p);
}
//+------------------------------------------------------------------+

Comments