Price Channel_v1

Download script

This tool is designed to provide a clear visual representation of price boundaries and the central equilibrium point on your trading chart. By analyzing historical price action, it identifies the "outer limits" of movement over a specific timeframe, helping traders see the range in which the market is currently operating.

How the Logic Works

The script functions by scanning a predetermined number of past price candles (defined by the Channel Period). For every point on the chart, it looks back at this specific window of time to perform three primary calculations:

  • The Upper Boundary: The tool identifies the highest price reached within the specified period. This creates a visual "ceiling," representing the peak resistance for that timeframe.
  • The Lower Boundary: It simultaneously identifies the lowest price reached within that same period, creating a visual "floor" or support level.
  • The Middle Line: The tool calculates the exact midpoint between the high and low boundaries. This acts as an equilibrium line, showing where the fair value sits between the two extremes.

Key Visual Components

When you apply this to your chart, you will see three distinct lines:

  1. Up Channel: A blue line tracking the highest price peaks.
  2. Down Channel: A blue line tracking the lowest price troughs.
  3. Middle Channel: A blue line (rendered with a slightly different style) marking the center of the price action.

Practical Application

By using this logic, you can visually map out the "trading range." The space between the Upper and Lower channels defines the market's current volatility limits. When the price moves toward the outer lines, it indicates strength or weakness, while the Middle Channel serves as a reference point to determine whether the price is currently trading above or below its recent average.

The script handles all the heavy lifting of recalculating these highs, lows, and midpoints instantly as new price data arrives, allowing you to focus on identifying trends rather than manually calculating price levels.

Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
Price Channel_v1
//+------------------------------------------------------------------+
//|                                                Price Channel.mq4 |
//|                               Copyright © 2004, Poul_Trade_Forum |
//|                                                         Aborigen |
//|                                          http://forex.kbpauk.ru/ |
//+------------------------------------------------------------------+
#property link      "http://forex.kbpauk.ru/"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 DodgerBlue
#property indicator_color2 DodgerBlue
#property indicator_color3 DodgerBlue
//---- input parameters
extern int ChannelPeriod=14;
extern int Shift=0;
//---- buffers
double UpBuffer[];
double DnBuffer[];
double MdBuffer[];
double Up[],Dn[],Md[];

ArraySetAsSeries(Up,true);
ArraySetAsSeries(Dn,true);
ArraySetAsSeries(Md,true);

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- indicator line
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE,2);
   SetIndexBuffer(0,UpBuffer);
   SetIndexBuffer(1,DnBuffer);
   SetIndexBuffer(2,MdBuffer);
//---- name for DataWindow and indicator subwindow label
   short_name="Price Channel("+ChannelPeriod+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,"Up Channel");
   SetIndexLabel(1,"Down Channel");
   SetIndexLabel(2,"Middle Channel");
//----
   SetIndexDrawBegin(0,ChannelPeriod+Shift);
   SetIndexDrawBegin(1,ChannelPeriod+Shift);
   SetIndexDrawBegin(2,ChannelPeriod+Shift);

   SetIndexEmptyValue(0,0);
   SetIndexEmptyValue(1,0);
   SetIndexEmptyValue(2,0);

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Price Channel                                                         |
//+------------------------------------------------------------------+
int start()
  {
   int i,counted_bars=IndicatorCounted();
   int    k;
   double high,low,price;
//----
   if(Bars<=ChannelPeriod) return(0);
//---- initial zero
   if(counted_bars<1)
      for(i=1;i<=ChannelPeriod;i++) UpBuffer[Bars-i]=0.0;

ArrayResize(Up, Bars);
ArrayResize(Dn, Bars);
ArrayResize(Md, Bars);
//----
   i=Bars-ChannelPeriod-1;
   if(counted_bars>=ChannelPeriod) i=Bars-counted_bars;
   while(i>=0)
     {
       high=High[i]; low=Low[i]; k=i-1+ChannelPeriod;
      while(k>=i)
        {
         price=High[k];
         if(high<price) high=price;
         price=Low[k];
         if(low>price)  low=price;
         k--;
        } 
     Up[i]=high;
     Dn[i]=low;
     Md[i]=(high+low)/2;
     UpBuffer[i]=Up[i+Shift];
     DnBuffer[i]=Dn[i+Shift];
     MdBuffer[i]=Md[i+Shift];
      i--;
     }
   return(0);
  }
//+------------------------------------------------------------------+

Comments