ExpectedHiLo

Download script
ExpectedHiLo

This tool is designed to help traders understand market behavior by analyzing historical price volatility and comparing it against current trends. Instead of looking at simple price movement, the script focuses on calculating "Expected Volumes"—a representation of how much price range a specific time period usually covers based on past data.

How the Logic Works

The indicator functions by performing a deep dive into your historical price history to establish a baseline for what is considered "normal" activity. Here is the step-by-step logic:

1. Historical Data Gathering The script looks back at a specific number of historical observations (defined by the user). It scans through previous days to find price movements that occurred at the exact same hour of the day as the current candle. For example, if it is currently 2:00 PM, the script identifies what happened at 2:00 PM on all previous days included in the historical sample.

2. Calculating the "Average" Range For every one of those past time slots identified, the script measures the distance between the highest price and the lowest price (the range). It then adds all of these ranges together and calculates an average. This gives you a mathematical "expectation" of how much the price typically fluctuates during this specific time of day.

3. Visual Comparison The tool then presents this information on your chart in two distinct ways:

  • The Expected Range (Histogram): This represents the historical average. It shows you what the "normal" volatility looks like for the current time based on past behavior.
  • The Actual Range (Line): This tracks the real-time volatility of the current candle (the difference between the current high and low).

Practical Application

By comparing the actual price movement against the expected historical average, a trader can visually identify anomalies. If the actual range is significantly larger or smaller than the expected histogram, it suggests that the market is behaving differently than usual—potentially indicating a breakout, an exhaustion of momentum, or a period of unusual consolidation.

Miscellaneous
Implements a curve of type %1
8 Views
0 Downloads
0 Favorites
ExpectedHiLo
//+------------------------------------------------------------------+
//|                                             Expected Volumes.mq4 |
//|                                     Copyright © 2007, Amir Aliev |
//|                                       http://finmat.blogspot.com |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2007, Amir Aliev"
#property  link      "http://finmat.blogspot.com"
 
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_color2 Yellow

#property indicator_width1 2
#property indicator_width2 1
//---- input parameters
extern int hist_steps = 100;      // Number of observations
extern int span = 1;              // Days to step back each time 
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
int sum;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- indicators
   SetIndexStyle(0, DRAW_HISTOGRAM);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1, DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);
   
//----
   short_name = "Expected Hi-Lo(" + hist_steps + ")";
   IndicatorShortName(short_name);
   SetIndexLabel(0, short_name);
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars = IndicatorCounted();
   int rest = Bars - counted_bars;
   int j, k, u;
//----   
      
   while(rest >= 0)
   {
      if(Bars - rest < span * 23 * hist_steps) 
      {
         ExtMapBuffer1[rest] = 0;     
         rest--; 
         continue;                                   
      }
      sum = 0;
      j = 0;
      k = 0;
      u = 0;
      while(j < hist_steps && k < Bars) 
      {
         if(TimeHour(Time[rest+k]) == TimeHour(Time[rest]))
         {
            u++;
            if(u == span)
            {
               u = 0;
               j++;
               sum += (High[rest + k]-Low[rest + k])/Point; 
            }
            k += 23;
         }
         k++;
      }
      ExtMapBuffer1[rest] = sum / hist_steps;     
      ExtMapBuffer2[rest] = (High[rest]-Low[rest])/Point;
      rest--;                                    
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments