PChannel_WITH SHIFT

Download script
PChannel_WITH SHIFT

This technical tool is designed to provide a visual map of market price boundaries by identifying specific historical highs and lows. Rather than reacting to every minor fluctuation in the live market, the script focuses on established price extremes over a set period to help define the current "trading range."

Core Mechanics

The logic operates by scanning the price history to identify three distinct layers of data:

  • The Upper Boundary: The tool looks back at a specific number of previous candles (defined by the user) and identifies the highest price reached during that window. This acts as a visual ceiling for the current price movement.
  • The Lower Boundary: Similarly, the tool scans the same historical window to find the lowest price reached. This serves as a visual floor for the market.
  • The Midpoint: By calculating the exact average between the identified upper and lower boundaries, the script generates a center line.

How It Works on Your Chart

To ensure the lines are smooth and not overly sensitive to "noise" (random, tiny price flickers), the script includes a slight delay or "shift." This means the boundaries displayed on your current candle are based on the high and low extremes of the period immediately preceding it.

Practical Application

For a trader, this logic creates a "channel" effect. By observing where the price sits in relation to these three lines, you can better visualize:

  1. The Range: The total space between the upper and lower boundaries.
  2. Relative Position: Whether the price is currently hugging the ceiling (resistance), the floor (support), or trading in the middle of the established zone.
  3. Structural Trends: How these boundaries move over time as new highs and lows are formed.
Miscellaneous
Implements a curve of type %1
11 Views
0 Downloads
0 Favorites
PChannel_WITH SHIFT
//+------------------------------------------------------------------+
//|                                                   PChannel_m.mq4 |
//+------------------------------------------------------------------+

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 DodgerBlue
#property indicator_color2 DodgerBlue
#property indicator_color3 DodgerBlue
//---- input parameters
extern int Range=14;
extern int Shift=5;
//---- buffers
double UpBuffer[];
double DnBuffer[];
double MdBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- indicator line
   SetIndexStyle(0,DRAW_LINE,1,2);
   SetIndexStyle(1,DRAW_LINE,1,2);
   SetIndexStyle(2,DRAW_LINE,2);
   SetIndexBuffer(0,UpBuffer);
   SetIndexBuffer(1,DnBuffer);
   SetIndexBuffer(2,MdBuffer);
//---- name for DataWindow and indicator subwindow label
   short_name="PriceChannel("+Range+")";
                                        
   IndicatorShortName(short_name);
                                  
   SetIndexLabel(0,"Up Channel");
                                  
   SetIndexLabel(1,"Down Channel");
                                   
   SetIndexLabel(2,"Middle Channel");
                                     
//----
   SetIndexDrawBegin(0,Range + Shift);
   SetIndexDrawBegin(1,Range + Shift);
   SetIndexDrawBegin(2,Range + Shift);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| PriceChannel                                                     |
//+------------------------------------------------------------------+
int start()
  {
   int i;

//----
   
   for(i=Bars-1;i>=0;i--)
   {
      UpBuffer[i]=High[Highest(NULL,0,MODE_HIGH,Range,i + Shift)];
      DnBuffer[i]=Low[Lowest(NULL,0,MODE_LOW,Range,i + Shift)];
      MdBuffer[i]=(UpBuffer[i + Shift]+DnBuffer[i + Shift])/2;
   }
   return(0);
  }
//+------------------------------------------------------------------+

Comments