Symbol_Index_MA_

Download script
Author: Advanced by Waddah Attar
Symbol_Index_MA_

This technical indicator is designed to provide traders with a consolidated "Currency Index" by aggregating the price movements of the major global currencies into a single visual value. Instead of monitoring multiple currency pairs individually, this script simplifies the market landscape by calculating a weighted average to represent the strength of a specific chosen currency against all others.

Core Functionality

1. Multi-Currency Data Aggregation The script monitors several primary currency pairs simultaneously (including USD, EUR, GBP, CHF, JPY, AUD, and CAD). It automatically identifies the most consistent amount of historical data available across all these pairs to ensure that the resulting calculation is stable and synchronized.

2. The Index Calculation The logic operates by performing a mathematical "pooling" of different currency values. It takes the closing prices of various major pairs and applies a geometric mean formula. This creates a unified base value (C_USD) which represents a balanced market position.

3. Dynamic Symbol Selection Depending on which specific currency the user chooses to track (e.g., USD, EUR, JPY, etc.), the script adjusts its final calculation:

  • For some currencies, it multiplies the base index by the relevant pair price.
  • For others, it divides the base index by the pair price. This ensures that regardless of which currency you select, the resulting line on your chart accurately reflects that specific currency's relative value compared to the rest of the market.

4. Visual Trends and Smoothing (Moving Averages) To make the data easier to read for human interpretation, the script includes an optional "Moving Average" feature. Rather than showing a jagged, fluctuating line that might be difficult to follow, it can apply two different smoothing layers (defined by user-set periods).

These smoothed lines help filter out "market noise," allowing traders to see the broader trend of a currency's strength or weakness more clearly over time.

5. Real-Time Reference Tracking The script also places a horizontal reference line on the chart. This serves as a visual anchor, showing the most recent calculated index value relative to the historical data, helping traders quickly identify how the current price position compares to previous highs and lows.

Price Data Components
Series array that contains close prices for each bar
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
7 Views
0 Downloads
0 Favorites
Symbol_Index_MA_
//+------------------------------------------------------------------+
//|                                             Symbol_Index_MA_.mq4 |
//|                              Copyright © 2006, Eng. Waddah Attar |
//|                                          waddahattar@hotmail.com |
//+------------------------------------------------------------------+
#property copyright "Advanced by Waddah Attar"
#property link      "waddahattar@hotmail.com"
//----
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 DarkOrange
#property indicator_color2 Red
#property indicator_color3 Blue
//----
extern string Use_This_Only = "USD,EUR,GBP,CHF,JPY,AUD,CAD";
extern string _____________ = "___________________________";
extern string MySymbol = "USD";
extern bool ShowMA = true;
extern int MA1_Period = 13;
extern int MA1_Mode = 0;
extern int MA2_Period = 5;
extern int MA2_Mode = 0;
//----
double Idx1[];
double Idx2[];
double Idx3[];
double v1[];
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorShortName("WA " + MySymbol + " Index (" + MA1_Period + ", " + 
                      MA2_Period + ")");
   SetIndexLabel(1, "WASymbol(" + MA1_Period + ")");
   SetIndexLabel(2, "WASymbol(" + MA2_Period + ")");      
//----
   SetIndexStyle(0, DRAW_LINE, 0, 1);
   SetIndexBuffer(0, Idx1);
//----
   SetIndexStyle(1, DRAW_LINE, 0, 2);
   SetIndexBuffer(1, Idx2);
//----
   SetIndexStyle(2, DRAW_LINE, 0, 1);
   SetIndexBuffer(2, Idx3);
//----
   ObjectsDeleteAll(1, OBJ_HLINE);
   ObjectsDeleteAll(2, OBJ_HLINE);
//----
   Print("USDCAD Bars = " , iBars("USDCAD", 0), " GBPUSD Bars = ", iBars("GBPUSD", 0), 
                                " AUDUSD Bars = " , iBars("AUDUSD", 0));
   Print("EURUSD Bars = " , iBars("EURUSD", 0), " USDCHF Bars = ", iBars("USDCHF", 0), 
                                " USDJPY Bars = " , iBars("USDJPY",0));
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void start()
  {
   int MinBars = iBars("EURUSD", 0);
   if(MinBars >= iBars("USDCHF", 0)) 
       MinBars = iBars("USDCHF", 0);
   if(MinBars >= iBars("USDJPY", 0)) 
       MinBars=iBars("USDJPY", 0);
   if(MinBars >= iBars("USDCAD", 0)) 
       MinBars=iBars("USDCAD", 0);
   if(MinBars >= iBars("GBPUSD", 0)) 
       MinBars=iBars("GBPUSD", 0);
   if(MinBars >= iBars("AUDUSD", 0))
       MinBars=iBars("AUDUSD", 0);
   ArrayResize (v1,MinBars); 
   double C_USD;
   for(int i = 0; i < MinBars; i++)
     {
       C_USD = MathPow(iClose("USDCHF", 0, i)*iClose("USDJPY", 0, i)*iClose("USDCAD", 0, i) / 
                       iClose("EURUSD", 0, i) / iClose("GBPUSD", 0, i) / 
                       iClose("AUDUSD", 0, i), 1. / 7.);
       if(MySymbol == "USD") 
           v1[i] = C_USD;
       if(MySymbol == "EUR")
           v1[i] = C_USD*iClose("EURUSD",0,i);
       if (MySymbol == "GBP")
           v1[i] = C_USD*iClose("GBPUSD",0,i);
       if(MySymbol == "AUD")
           v1[i] = C_USD*iClose("AUDUSD",0,i);
       if(MySymbol == "CHF")
           v1[i] = C_USD/iClose("USDCHF",0,i);
       if(MySymbol == "JPY")
           v1[i] = C_USD/iClose("USDJPY",0,i);
       if(MySymbol == "CAD")
           v1[i] = C_USD/iClose("USDCAD",0,i);
       int win_idx = WindowFind("WA " + MySymbol + " Index (" + MA1_Period + ", " + 
                      MA2_Period + ")");
       Idx1[i] = v1[i];
       if(ObjectCreate("HLINE" + MySymbol, OBJ_HLINE, win_idx, Time[0], Idx1[0]) == false)
         {
           ObjectSet("HLINE" + MySymbol, OBJPROP_PRICE1, Idx1[0]);
           ObjectSet("HLINE" + MySymbol, OBJPROP_COLOR, DimGray);
         }
     }
   if(ShowMA == true)
     {
       for(i = 0; i < MinBars - MA1_Period; i++)
         {
           Idx2[i] = iMAOnArray(Idx1, 0, MA1_Period, 0, MA1_Mode, i);
           Idx3[i] = iMAOnArray(Idx1, 0, MA2_Period, 0, MA2_Mode, i);
         }
     }
  }
//+------------------------------------------------------------------+

Comments