Author: Raymond Toh
OsUSD

This script is a custom technical indicator designed for the MetaTrader 4 platform to help traders visualize the relative strength of the US Dollar (USD) against a basket of other major currencies. Instead of looking at a single currency pair, it synthesizes data from four different pairs to provide a broader "USD Index" perspective.

Core Functionality

The logic operates by calculating the movement of specific moving averages across four distinct currency pairs: EUR/USD, GBP/USD, USD/CHF, and USD/JPY. By analyzing these movements simultaneously, the script creates a composite score that represents the overall momentum of the US Dollar in the forex market.

How the Calculation Works

To arrive at the final index value, the script performs the following steps:

  • Moving Average Comparison: For each currency pair, the tool compares the current moving average position against its position from a previous point in time (defined by a user-adjustable shift). This helps determine if the currency is trending upward or downward.
  • Weighting and Scaling: Not all currencies are treated equally in the calculation. The script applies specific multipliers to each pair to ensure that the final index value accurately reflects market reality. For example, some pairs are scaled by 10,000 while others use different factors to balance their influence on the final result.
  • Directional Analysis: By adding or subtracting these weighted movements, the script produces a single numerical value. If the resulting number is positive, it suggests a specific market bias; if negative, it suggests the opposite.

Visual Representation

The indicator displays this data in a separate window below your main price chart using three distinct visual elements:

  1. Positive Momentum (Red Histogram): When the calculated index is above zero, the script displays a red histogram. This represents "Signal Up" strength.
  2. Negative Momentum (Blue Histogram): When the calculated index falls below zero, it displays a blue histogram, representing "Signal Down" strength.
  3. The USD Index Value: The actual numerical value of the composite index is plotted as the foundation for these signals, allowing you to see both the magnitude of the movement and its direction at a glance.

User Customization

The tool allows for flexibility through several adjustable parameters:

  • MA Period & Shift: You can define how many previous bars the moving average considers and how far back the "comparison" point sits.
  • Price Type: You can choose which price data (such as weighted close prices) the indicator should use for its calculations.
  • Smoothing Mode: You can toggle the type of moving average (e.g., Linear Weighted) to change how smoothly the index reacts to market volatility.
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
12 Views
0 Downloads
0 Favorites
OsUSD
//+------------------------------------------------------------------+
//|                                                        OsUSD.mq4 |
//|                                                      Raymond Toh |
//|                                           http://forex.eazel.com |
//+------------------------------------------------------------------+
#property copyright "Raymond Toh"
#property link      "http://forex.eazel.com"

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color2 Blue

double Signal_Up[];
double Signal_Down[];
double USD_Index[];

extern int MA_Period=12;
extern int MA_Shift=5;
extern int Price=6; //Weighted close price, (high+low+close+close)/4.
extern int Mode=3; //Linear weighted moving average.

int init()
  {
   
   IndicatorShortName("OsUSD("+MA_Period+","+MA_Shift+","+Price+","+Mode+")");
   SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,2);
   SetIndexBuffer(0,Signal_Up);
   SetIndexLabel(0, "Signal_Up"); 
   SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,2);
   SetIndexBuffer(1,Signal_Down);
   SetIndexLabel(1, "Signal_Down"); 
   SetIndexBuffer(2,USD_Index);
   SetIndexLabel(2, "USD"); 
   return(0);
  }
int deinit()
  {
   return(0);
  }

int start()
  {
     int limit;
     int counted_bars=IndicatorCounted();
     if(counted_bars<0) return(-1);
     if(counted_bars>0) counted_bars-=1;
     limit=Bars-counted_bars;
     

     for(int i=0; i<limit; i++)
       {
        USD_Index[i]=
            (iMA("EURUSD",0,MA_Period,0,Mode,Price,i+MA_Shift)-
            iMA("EURUSD",0,MA_Period,0,Mode,Price,i))*10000
            +
            (iMA("GBPUSD",0,MA_Period,0,Mode,Price,i+MA_Shift)-
            iMA("GBPUSD",0,MA_Period,0,Mode,Price,i))*10000
            +
            (iMA("USDCHF",0,MA_Period,0,Mode,Price,i)-
            iMA("USDCHF",0,MA_Period,0,Mode,Price,i+MA_Shift))*10000
            +
            (iMA("USDJPY",0,MA_Period,0,Mode,Price,i)-
            iMA("USDJPY",0,MA_Period,0,Mode,Price,i+MA_Shift))*100
            ;
            
            if (USD_Index[i]>= 0){ Signal_Up[i] = USD_Index[i]; Signal_Down[i] = 0; } 
            else { Signal_Down[i] = USD_Index[i]; Signal_Up[i] = 0; }
       }
    return(0);
  }
//+------------------------------------------------------------------+

Comments