DollarIndex
Download scriptThis script is designed to provide traders with a specialized visual tool that tracks the overall strength of the US Dollar (USD) relative to a basket of major global currencies. Instead of looking at just one currency pair, it synthesizes information from seven different markets to create a single, unified "Dollar Index" value.
How the Logic Works
The core objective of this script is to aggregate market movements into one comprehensive view. It monitors the following currency pairs: EURUSD, GBPUSD, USDJPY, USDCHF, AUDUSD, USDCAD, and NZDUSD.
To calculate the index value, the logic follows these specific steps for every historical bar on your chart:
1. Calculating Individual Price Movement The script looks at each of the seven currency pairs and determines how much the price moved from its opening point to its closing point for that specific timeframe. This allows it to see if the currency is trending up or down independently.
2. Volume Weighting Recognizing that not all price movements are equal, the script incorporates "Volume." It takes the price movement of each pair and multiplies it by the trading volume. This means that a large price move on a high-volume pair will have a more significant impact on the final index than a smaller move on a lower-volume pair.
3. Directional Analysis (The USD Focus) The script then identifies the role of the US Dollar in each specific pair:
- If the USD is the base currency (the first part of the pair, like in USDCAD), it adds that value to the total index.
- If the USD is the quote currency (the second part of the pair, like in EURUSD), it subtracts that value from the total index.
4. Final Calculation and Visualization By adding the positive movements and subtracting the negative ones based on their weighted volume, the script produces a single "net" number. This number represents the combined momentum of the US Dollar across all seven markets.
Summary for the Trader
The resulting line on your chart serves as a "pulse" for the US Dollar. Rather than making decisions based on a single pair, this tool allows you to see where the broad market is leaning. When the index moves significantly in one direction, it indicates a consensus among multiple global currencies regarding the strength or weakness of the USD at that moment.
//+------------------------------------------------------------------+
//| DollarIndex.mq4 |
//| Copyright © 2010, Shon Shampain |
//| http://www.zencowsgomu.com |
//| |
//| Visit http://www.zencowsgomu.com, an oasis of sanity |
//| for currency traders. |
//| |
//| Original out-of-the-box thinking, ideas, indicators, |
//| educational EAs and more. |
//| |
//| Home of the consistent T4 Forex trading signal. |
//| Backtesting profitably since 1-1-2002. |
//+------------------------------------------------------------------+
#property copyright "Shon Shampain"
#property link "http://www.zencowsgomu.com"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Aqua
extern bool tenths = true;
int NUM_PAIRS = 7;
string currencies [7];
double mult [7];
double Index [];
int init()
{
currencies[0] = "EURUSD";
currencies[1] = "GBPUSD";
currencies[2] = "USDJPY";
currencies[3] = "USDCHF";
currencies[4] = "AUDUSD";
currencies[5] = "USDCAD";
currencies[6] = "NZDUSD";
for (int z = 0; z < NUM_PAIRS; z++)
{
int d = MarketInfo(currencies[z], MODE_DIGITS);
if (tenths) d -= 1;
mult[z] = 1.0;
for (int x = 0; x < d; x++)
mult[z] *= 10.0;
}
SetIndexBuffer(0, Index);
SetLevelValue(0, 0.0);
SetLevelStyle(STYLE_DOT, 1, Silver);
return(0);
}
int deinit()
{
return(0);
}
int start()
{
int counted_bars;
int i;
int z;
double value;
counted_bars = IndicatorCounted();
i = Bars - counted_bars - 1;
while(i>=0)
{
value = 0.0;
for (z = 0; z < NUM_PAIRS; z++)
{
bool short_usd = (StringFind(StringSubstr(currencies[z], 3), "USD") != -1);
double pips = (iClose(currencies[z], Period(), i) - iOpen(currencies[z], Period(), i)) * mult[z];
double weighted_pips = pips * iVolume(currencies[z], Period(), i);
if (short_usd) value -= weighted_pips;
else value += weighted_pips;
}
Index[i] = value;
i--;
}
return(0);
}
Comments