Will-Spread

Download script
Author: Copyright � 2006, Profitrader.
Will-Spread

The Will-Spread indicator is a specialized trading tool designed to measure the relationship between two different financial markets—for example, how the price of Gold moves in relation to another asset. Instead of looking at the prices of these assets individually, this script analyzes the "spread" or the relative distance between them to identify unique trading opportunities.

How the Logic Works

1. Establishing Market Correlation The tool begins by comparing the closing price of your primary chart against a secondary market (such as Gold). Depending on your settings, it calculates this relationship in one of two ways:

  • Direct Correlation: It determines how much one market moves relative to the other.
  • Inverted Correlation: It flips the calculation, which is useful for pairs that typically move in opposite directions.

2. Calculating the Spread Percentage By dividing one price by the other and converting it into a percentage, the script creates a "Spread" value. This allows you to see the proportional difference between the two assets, effectively smoothing out the differences in their actual dollar values so they can be compared accurately on a single scale.

3. Smoothing the Data (Moving Averages) To filter out "market noise" and erratic price jumps, the script applies two different types of Exponential Moving Averages (EMA) to that spread data:

  • Fast EMA: Reacts quickly to recent changes in the relationship between the two markets.
  • Slow EMA: Provides a broader, long-term view of the relationship trend.

4. Identifying the "Will-Spread" The final output (the red line on your chart) is the result of subtracting the Slow EMA from the Fast EMA. This represents the momentum of the spread.

What This Means for Traders

Essentially, this logic helps you visualize when the relationship between two markets is deviating from its normal behavior. When the "Will-Spread" line moves significantly, it suggests that one market is pulling away from the other at an unusual rate. Traders use this to identify potential "reversion to the mean" opportunities, where they bet that the spread will eventually return to its normal historical balance.

Price Data Components
Series array that contains close prices for each barSeries array that contains close prices for each bar
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
5 Views
0 Downloads
0 Favorites
Will-Spread
//+------------------------------------------------------------------+
//|                                                      Will-Spread |
//|                                       Copyright © Larry Williams |
//|                                    Coded/Verified by Profitrader |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Profitrader."
#property link      "profitrader@inbox.ru"
//----
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
//---- input parameters
extern int FastMAPeriod = 3;
extern int SlowMAPeriod = 15;
extern string SecondMarket = "GOLD";
extern bool MarketsDirectCorrelation = true;
//---- buffers
double WillSpread[];
double Spread[];
double FastEMA[];
double SlowEMA[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string Correlation = "Invert Correlation";
   if(MarketsDirectCorrelation == TRUE) 
       Correlation = "Direct Correlation";
   IndicatorShortName("Will-Spread(" + FastMAPeriod + "," + SlowMAPeriod + 
                      "," + SecondMarket + "," + Correlation + ")");
   IndicatorDigits(Digits + 2);
   IndicatorBuffers(4);
   SetIndexBuffer(0, WillSpread);
   SetIndexBuffer(1, Spread);
   SetIndexBuffer(2, FastEMA);
   SetIndexBuffer(3, SlowEMA);
   SetIndexStyle(0, DRAW_LINE);
   SetIndexLabel(0, "W-S");
   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) / Close[i]*100;
     }
   else
     {
       for(i = 0; i < limit; i++)
           Spread[i] = Close[i] / iClose(SecondMarket, 0, i)*100;
     }
   for(i = limit - 1; i >= 0; i--)
     {
       FastEMA[i] = iMAOnArray(Spread, 0, FastMAPeriod, 0, MODE_EMA, i);
       SlowEMA[i] = iMAOnArray(Spread, 0, SlowMAPeriod, 0, MODE_EMA, i);
       WillSpread[i] = FastEMA[i] - SlowEMA[i];
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments