Spread Analyzer

Download script
Author: Copyright � 2009, Obaidah & GodfreyH
Spread Analyzer

Overview

The Spread Analyzer is a technical tool designed to help traders identify specific areas of strength and weakness within a financial market. Rather than acting as a direct "buy" or "sell" signal, it serves as an analytical assistant that interprets price action by comparing the size of current market movements against historical averages. It specifically focuses on "Spread"—the distance between the high and low points of a price bar—to help determine how aggressively the market is moving.

How the Logic Works

The script processes data by looking at several key factors simultaneously:

1. Spread Comparison The tool calculates the current spread of a price bar and compares it to a rolling average of previous bars. It categorizes these movements into different intensity levels:

  • It identifies "high volatility" moments when the current spread is significantly larger than the recent average (e.g., 3 times larger).
  • It categorizes smaller variations to help the trader see if the market is expanding or contracting in size.

2. Price Change Analysis The logic looks at the "body" of the price bars (the distance between the opening and closing price). It calculates an average change for the preceding period to determine if the current movement is unusually large or small compared to what has happened recently.

3. Closing Strength (Positioning) The script analyzes where the price ends relative to where it started during a specific move:

  • For upward moves, it checks if the price finished near the top (strong bullish momentum) or in the middle (weak/uncertain momentum).
  • For downward moves, it checks if the price finished near the bottom (strong bearish momentum) or in the middle.

4. Volume Context The tool tracks previous volume data, allowing traders to cross-reference the size of a spread with the amount of trading activity occurring at that moment.

Practical Application for Traders

By combining these factors, the indicator helps you visualize:

  • Momentum: Is the price moving significantly further than usual?
  • Exhaustion: Is the price still moving strongly, or is it "tired" and closing in the middle of its range?
  • Volatility: Is the market currently experiencing a squeeze (small spreads) or an expansion (large spreads)?

Important Usage Notes

  • Confirmation is Key: The logic is designed to be used alongside other indicators. It provides the "why" behind a move, but should not be used in isolation to make trades.
  • Warm-up Period: Because the script relies on a historical average of previous bars, the data at the very beginning of a new trading session (the first 13 bars) is considered unreliable and should be ignored until the tool has enough data to form an accurate average.
9 Views
0 Downloads
0 Favorites
Spread Analyzer
//+------------------------------------------------------------------+
//|                        Spread Analyzer.mq4                       |
//|               Copyright © 2009, Obaidah & GodfreyH               |
//|                         clefts@hotmail.com                       |
//|                         godfreyh@gmail.com                       |
//|                                                                  |
//|   This Indicator works as assistant to Volume Spread Analyzer    |
//|Volume and Spread in order to identify weakness and strength spots|
//|                                                                  |
//|                             WARNING!                             |
//| Signs provided by this technical indicator cannot be considered  |
//| As entry signals unless there's at least 1 more indicator shows  |
//|   The same signal, This indicator is well-designed to help you   |
//|         Deciding your entery points and you exit points.         |
//|  Please notice that this indicator uses the average for the last |
//|             13 bars, so, ANY signal in the first 13 bars         |
//|                  Of any season open is NOT liable.               |
//|                                                                  |
//| This indicator is to remain open source for further developments |
//|   The programmers are NOT responsible about any losing trades    |
//| Taken based on this indicator, Do learn about volume and spread  |
//|         Analysis before you use this indicator seriuosly         |
//|                                                                  |
//| In order to know how does this indicator provides signal and how |
//|      Strong such a signal is please read Master The Markets      |
//+------------------------------------------------------------------+

#property copyright "Copyright © 2009, Obaidah & GodfreyH"
#property link      "clefts@hotmail.com"
#property link      "godfreyh@gmail.com"

extern int Lb=8;

double Spread[],Spread1[],SpreadAverage[], Change[],ChangeAve[],ClosePart[],BarType[], PrevVol[];

#property indicator_chart_window
#property  indicator_buffers 7

// Custom indicator initialization function

int init()
{

   IndicatorBuffers(7);
   
   SetIndexStyle(0,DRAW_NONE);
   SetIndexStyle(1,DRAW_NONE);
   SetIndexStyle(2,DRAW_NONE);
   SetIndexStyle(3,DRAW_NONE);
   SetIndexStyle(4,DRAW_NONE);
   SetIndexStyle(5,DRAW_NONE);
   SetIndexStyle(6,DRAW_NONE);
   
   SetIndexDrawBegin(0,Lb);
   SetIndexDrawBegin(1,Lb);
   SetIndexDrawBegin(2,Lb);
   SetIndexDrawBegin(3,Lb);
   SetIndexDrawBegin(4,Lb);
   SetIndexDrawBegin(5,Lb);
   SetIndexDrawBegin(6,Lb);
   
   SetIndexBuffer(0,Spread);
   SetIndexBuffer(1,Spread1);
   SetIndexBuffer(2,SpreadAverage);
   SetIndexBuffer(3,ChangeAve);
   SetIndexBuffer(4,PrevVol);
   SetIndexBuffer(5,BarType);
   SetIndexBuffer(6,ClosePart);
   
   IndicatorDigits(0);
   
   IndicatorShortName("Volume And Spread Analyzer");
   
   return(0);
}

// Custom indicator deinitialization function

int deinit()
{
   return(0);
}

// Custom indicator iteration function

int start()
{
   int countedBars = IndicatorCounted();
   int limit;
   if(countedBars > 0)
       countedBars--;
   limit=Bars-countedBars;
   int i,j;
   for(i=0; i<limit; i++) {
      Spread[i]=High[i] - Low[i];
      SpreadAverage[i]=0;
      for(j=i+Lb;j>i;j--)
         SpreadAverage[i]+=iHigh(Symbol(),0,j) - iLow(Symbol(),0,j);
         
      SpreadAverage[i]/=Lb;
      Spread1[i]=0;
      PrevVol[i]=Volume[i+2];
      if(Spread[i] > 3*SpreadAverage[i])
         Spread1[i]=4;
      else {
      if(Spread[i] > 1.9*SpreadAverage[i])
         Spread1[i]=3;
      else {
         if(Spread[i] > 1.6*SpreadAverage[i])
            Spread1[i]=2;
         else {
            if(Spread[i] > 1.3*SpreadAverage[i])
               Spread1[i]=1;
            else {
               if(Spread[i] < 0.60*SpreadAverage[i])
                  Spread1[i]=-1;
            }
         }
      }
      }
      ChangeAve[i]=0;
      for(j=i+Lb;j>i;j--) {
         if(iOpen(Symbol(),0,i) < iClose(Symbol(),0,i)) // Check if its a bullish bar.
            ChangeAve[i]+=iClose(Symbol(),0,j) - iOpen(Symbol(),0,j);
         else
            ChangeAve[i]+=iOpen(Symbol(),0,j) - iClose(Symbol(),0,j);
      }
      ChangeAve[i]/=Lb;
      if(iOpen(Symbol(),0,i) < iClose(Symbol(),0,i)) {
         Change[i]=iClose(Symbol(),0,i) - iOpen(Symbol(),0,i);
         BarType[i]=1.0; // One if its an up-bar
      }
      else {
         if(iOpen(Symbol(),0,i) > iClose(Symbol(),0,i)) {
            Change[i]=iOpen(Symbol(),0,i) - iClose(Symbol(),0,i);
            BarType[i]=2.0; // 2 If its a down-bar
         }
      }
      ClosePart[i]=0;
      if(BarType[i] == 1) {
      // 2 means highs, 1 means middle, 0 means lows (in case of up-bars)
         if(Close[i] >= High[i]-Spread[i]*0.30)
            ClosePart[i]=2;
         else
            if(Close[i] > High[i]-Spread[i]*0.60)
               ClosePart[i]=1;
      }
      else {
         if(BarType[i] == 2) {
         //2 means lows, 1 means middle, 0 means highs (in case of down-bars)
            if(Close[i] < High[i]-Spread[i]*0.60)
               ClosePart[i]=2;
            else
               if(Close[i] < High[i]-Spread[i]*0.30)
                  ClosePart[i]=1;
         }
      }
   }
   return(0);
}

Comments