Author: Copyright � 2010, Ilya Filatov
2MoHLC

The 2 Medians of High-Low Channels is a technical analysis tool designed to provide traders with a visual representation of market equilibrium based on two different time horizons. Instead of relying on single price points, this indicator identifies the "middle ground" of price action across varying periods.

Core Logic Overview

The script operates by scanning historical price data to identify the highest and lowest points reached within two specific look-back windows (defined by the user as Period 1 and Period 2). For each period, it calculates a median value—the exact halfway point between that period's high and low.

By calculating these medians, the tool highlights where the market "balances" itself over different durations.

How It Works

  1. Dual-Period Analysis: The indicator simultaneously tracks two different timeframes. For example, if you set the periods to 24 and 48, the script will look at the price movement of the last 24 candles and the last 48 candles at once.
  2. High/Low Identification: For each timeframe, the logic scans the data to find the absolute highest peak and the absolute lowest valley.
  3. Median Calculation: It takes those two extremes (the High and the Low) and calculates the average. This results in a single "median" price for each period.
  4. Visual Representation: The script plots these two medians on your chart. Because there are two different median values, they create a visual "cloud" or shaded area between them.

Practical Application

  • Identifying Equilibrium: The space between the two colored lines represents the current zone of market balance. When price is inside this cloud, the market may be in a period of consolidation or indecision.
  • Trend Context: By observing how the "cloud" shifts or expands over time, traders can get a sense of whether the market's equilibrium is moving upward, downward, or remaining steady.
  • Dynamic Range: Because it uses high and low values rather than just closing prices, the indicator is more sensitive to the actual volatility and reach of the price movements during those specific periods.
12 Views
0 Downloads
0 Favorites
2MoHLC
//+------------------------------------------------------------------+ 
//|                   2 Medians of High-Low Channels      2MoHLC.mq5 | 
//|                                   Copyright © 2010, Ilya Filatov | 
//|                                               ilya-filatov@ya.ru | 
//+------------------------------------------------------------------+ 
#property copyright "Copyright © 2010, Ilya Filatov"
#property link "ilya-filatov@ya.ru"
#property description "2 Medians of High-Low Channels"
//---- indicator version number
#property version   "1.00"
//---- drawing the indicator in the main window
#property indicator_chart_window
//---- number of indicator buffers 2
#property indicator_buffers 2 
//---- one plot is used
#property indicator_plots   1
//+-----------------------------------+
//|  Parameters of indicator drawing  |
//+-----------------------------------+
//---- drawing the indicator as a colored cloud
#property indicator_type1   DRAW_FILLING
//---- the following colors are used for the indicator
#property indicator_color1  clrDeepSkyBlue,clrHotPink
//---- displaying the indicator label
#property indicator_label1  "2MoHLC"

//+-----------------------------------+
//|  Input parameters of the indicator|
//+-----------------------------------+
input int Period1=24; //Period 1
input int Period2=48; //Period 2
input int Shift=0; //Horizontal shift of the indicator in bars 
//+-----------------------------------+

//---- declaration of the integer variables for the start of data calculation
int  min_rates_total;
//---- declaration of dynamic arrays that further 
//---- will be used as indicator buffers
double Ext1Buffer[];
double Ext2Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
//---- Initialization of variables of the start of data calculation
   min_rates_total=MathMax(Period1,Period2);
   
//---- set dynamic array as an indicator buffer
   SetIndexBuffer(0,Ext1Buffer,INDICATOR_DATA);
//---- indexing elements in the buffer as in timeseries
   ArraySetAsSeries(Ext1Buffer,true);
   
//---- set dynamic array as an indicator buffer
   SetIndexBuffer(1,Ext2Buffer,INDICATOR_DATA);
//---- indexing elements in the buffer as in timeseries
   ArraySetAsSeries(Ext2Buffer,true);
      
//---- performing the shift of beginning of indicator drawing
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);
//---- setting the indicator values that won't be visible on a chart
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
//---- horizontal shift of the indicator
   PlotIndexSetInteger(0,PLOT_SHIFT,Shift);

//--- creation of the name to be displayed in a separate sub-window and in a pop up help
   IndicatorSetString(INDICATOR_SHORTNAME,"2MoHLC("+string(Period1)+","+string(Period2)+")");
//---- determination of accuracy of displaying the indicator values
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//---- end of initialization
  }
//+------------------------------------------------------------------+  
//| Custom indicator iteration function                              | 
//+------------------------------------------------------------------+  
int OnCalculate(
                const int rates_total,    // amount of history in bars at the current tick
                const int prev_calculated,// amount of history in bars at the previous tick
                const datetime &Time[],
                const double &Open[],
                const double &High[],
                const double &Low[],
                const double &Close[],
                const long &Tick_Volume[],
                const long &Volume[],
                const int &Spread[]
                )
  {
//---- checking the number of bars to be enough for calculation
   if(rates_total<min_rates_total) return(0);

//---- declaration of variables with a floating point  
   double HH,LL;
//---- Declaration of integer variables
   int limit;

//---- Calculate the "limit" starting number for loop of bars recalculation
   if(prev_calculated>rates_total || prev_calculated<=0)// checking for the first start of calculation of an indicator
        limit=rates_total-min_rates_total-1; // starting index for calculation of all bars
   else limit=rates_total-prev_calculated;  // starting index for calculation of new bars only

//---- indexing elements in arrays as timeseries  
   ArraySetAsSeries(High,true);
   ArraySetAsSeries(Low,true);   
   
//---- main cycle of calculation of the indicator
   for(int bar=limit; bar>=0; bar--)
     {
      HH=High[ArrayMaximum(High,bar,Period1)];
      LL=Low [ArrayMinimum(Low, bar,Period1)];
      Ext1Buffer[bar]=(HH+LL)/2.0;      
      //---
      HH=High[ArrayMaximum(High,bar,Period2)];
      LL=Low [ArrayMinimum(Low, bar,Period2)];
      Ext2Buffer[bar]=(HH+LL)/2.0;
     }
//----    
   return(rates_total);
  }
//+------------------------------------------------------------------+

Comments