Spread_Normalized

Download script
Author: Vangabestia 69

This tool is designed to help traders identify and analyze the relationship between two different currency markets. By calculating the "spread" (the price difference) between a primary pair and a secondary pair, it provides a visual representation of how these two markets move in relation to one another over time.

Core Functionality

The logic follows a three-step process to transform raw market data into a readable indicator:

1. Spread Calculation The script first looks at the closing prices of two chosen markets (for example, EURUSD and AUDUSD). Depending on your settings, it calculates the mathematical difference between these two prices. You can choose whether to measure a "Direct Correlation" or an "Inverted Correlation," which determines which price is subtracted from the other.

2. Statistical Smoothing Once the spread is established, the tool applies a Simple Moving Average (SMA). This smooths out the "noise" of the market, allowing you to see the underlying trend of the price difference rather than just the erratic jumps from minute to minute.

3. Normalization (The SpreadMod) This is the most advanced part of the script. Instead of showing you the raw price difference, the tool calculates a "Normalized" value. It does this by:

  • Measuring how far the current spread deviates from its moving average.
  • Calculating the standard deviation (the typical volatility) of that spread.
  • Dividing the difference by the volatility to produce a standardized score.

What This Means for the Trader

By normalizing the data, the script removes the specific price units of the currencies and focuses purely on the strength and direction of the divergence.

Instead of seeing a fluctuating price, you see a normalized value that indicates whether the relationship between the two markets is currently stretched unusually far from its norm. This helps in identifying potential "overextended" movements where one market might be leading the other significantly, potentially highlighting opportunities for mean-reversion trading or identifying shifts in market sentiment.

Price Data Components
Series array that contains close prices for each bar
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
4 Views
0 Downloads
0 Favorites
Spread_Normalized
//+------------------------------------------------------------------+
//|                                            Spread Normalized.mq4 |
//|                                                   Vangabestia 69 |
//|                           http://www.automatikforex.blogspot.com |
//+------------------------------------------------------------------+
#property copyright "Vangabestia 69"
#property link      "http://www.automatikforex.blogspot.com"

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
//---- input parameters
extern int MAPeriod = 20;
extern string FirstMarket = "EURUSD";
extern string SecondMarket = "AUDUSD";
extern bool MarketsDirectCorrelation = true;
//---- buffers
double SpreadMod[];
double Spread[];
double SPRSMA[];
double Cov[];
double sDev[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string Correlation = "Invert Correlation";
   if(MarketsDirectCorrelation == TRUE) 
       Correlation = "Direct Correlation";
   IndicatorShortName("SpreadMod(" + MAPeriod + "," + FirstMarket + "," + SecondMarket + "," + Correlation + ")");
   IndicatorDigits(Digits + 2);
   IndicatorBuffers(5);
   SetIndexBuffer(0, SpreadMod);
   SetIndexBuffer(1, Spread);
   SetIndexBuffer(2, SPRSMA);
   SetIndexBuffer(3, Cov);
   SetIndexBuffer(4, sDev);
   SetIndexStyle(0, DRAW_LINE);
   SetIndexLabel(0, "SpreadMod");
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int i, counted_bars = IndicatorCounted();
//---- check for possible errors
   if(counted_bars < 0) 
       return(-1);
//---- last counted bar will be recounted
   if(counted_bars > 0) 
       counted_bars--; 
   int limit = Bars - counted_bars;
   if(MarketsDirectCorrelation == TRUE)
  

     {
       for(i = 0; i < limit; i++)
           Spread[i] = iClose(SecondMarket, 0, i) - iClose(FirstMarket, 0, i);//Close[i];

     }
   else
     {
       for(i = 0; i < limit; i++)
           Spread[i] = iClose(FirstMarket, 0, i) - iClose(SecondMarket, 0, i);
     }
   for(i = limit - 1; i >= 0; i--)
     { //Spread[i] = iClose(SecondMarket, 0, i) - Close[i];
       SPRSMA[i] = iMAOnArray(Spread, 0, MAPeriod, 0, MODE_SMA, i);
       Cov[i]=(Spread[i])*(Spread[i]);
       sDev[i]=MathSqrt(Cov[i]/MAPeriod);
       SpreadMod[i] =-((Spread[i]-SPRSMA[i])/sDev[i]) ;
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments