channels_v2.4

Download script
Author: Copyright � 2009, MetaQuotes Software Corp.
channels_v2.4

This tool is designed to automatically identify and project key price levels on your trading chart, specifically focusing on Support and Resistance zones across different timeframes. It helps traders visualize where the market might encounter significant "floors" or "ceilings" based on historical price action.

Core Logic and Functionality

Multi-Timeframe Analysis The script operates simultaneously on three different time intervals (defined by the user as period 1, 2, and 3). By calculating data for multiple periods at once, it provides a comprehensive view of market structure, ensuring that you aren't just looking at short-term noise but are also aware of larger trend boundaries.

Dynamic Peak and Valley Detection The script scans historical price data to find significant high and low points. Instead of simply picking any high or low, it looks for specific "structural" points:

  • Support Points: It identifies local bottoms where the price has reversed upward.
  • Resistance Points: It identifies local peaks where the price has reversed downward.

The logic specifically hunts for the most prominent of these points to ensure the lines drawn on your chart represent meaningful market boundaries rather than minor fluctuations.

Mathematical Projection Once the script identifies the two most relevant support and resistance points for a given period, it performs a mathematical calculation to project where those levels will land in the future.

  • It calculates the rate of change between identified historical points.
  • It then uses that trajectory to extend lines forward onto your current chart.
  • This allows you to see where the "expected" support and resistance might be located as price moves forward in time.

Visual Output The tool translates these calculations into clear visual elements on your chart:

  • Support & Resistance Lines: Drawn as trend lines to show the projected boundaries.
  • Midpoint Line: A dotted line is automatically calculated to represent the "equilibrium" or fair value between the support and resistance levels.
  • Dynamic Labeling: The script places text labels on the far right of the chart, showing you the exact numerical price of the projected upper (Resistance) and lower (Support) levels.
  • Visual Hierarchy: The thickness of the lines changes depending on the timeframe; larger timeframes (like the 1440 period) produce thicker, more prominent lines, while smaller timeframes produce thinner lines to maintain a clean chart appearance.

Summary for the Trader

Essentially, this script automates the tedious task of looking back at history to find significant turning points. It then "does the math" to project those levels into the future, giving you a clear visual map of where price might struggle to break through (Resistance) or hold firm (Support) across multiple timeframes simultaneously.

Price Data Components
Series array that contains the lowest prices of each barSeries array that contains the highest prices of each bar
10 Views
1 Downloads
0 Favorites
channels_v2.4
//+------------------------------------------------------------------+
//|                                                  _indicatren.mq4 |
//|                      Copyright © 2009, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_chart_window

//---- input parameters
extern int       period1=60;
extern int       period2=240;
extern int       period3=1440;

int tmin1, tmax1,tmin2, tmax2, period;
double max1, min1,max2, min2, up, down;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init() 
  {
//---- indicators
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   period=period1; del();
   period=period2; del();
   period=period3; del();
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int del()
{
   ObjectDelete("sup"+DoubleToStr(period,0));
   ObjectDelete("mid"+DoubleToStr(period,0));
   ObjectDelete("res"+DoubleToStr(period,0));
   ObjectDelete("up"+DoubleToStr(period,0));
   ObjectDelete("down"+DoubleToStr(period,0));
   return(0);
}


int main()
{
   int i, k, m;
   
   k=1; m=1;
  
   for(i=3; i<iBars(NULL, period)-3; i++)      
   {
      if (iLow(NULL, period,i-2)>iLow(NULL, period,i)&&iLow(NULL, period,i+2)>iLow(NULL, period,i)
      &&iLow(NULL, period,i-1)>=iLow(NULL, period,i)&&iLow(NULL, period,i+1)>iLow(NULL, period,i)&&k<3)
      if (k==1){ tmin1=i;  min1=iLow(NULL, period,i);      k=k+1;}
      else 
      if(i>tmin1+2){ tmin2=i;  min2=iLow(NULL, period,i);k=k+1;}
      
      if (k==3) break;
   }
   
   for(i=3; i<iBars(NULL, period)-3; i++)      
   {
      if (iHigh(NULL, period,i-2)<iHigh(NULL, period,i)&&iHigh(NULL, period,i+2)<iHigh(NULL, period,i)
      &&iHigh(NULL, period,i-1)<=iHigh(NULL, period,i)&&iHigh(NULL, period,i+1)<iHigh(NULL, period,i)&&m<3)
      if (m==1){ tmax1=i;  max1=iHigh(NULL, period,i);      m=m+1;}
      else 
      if(i>tmax1+2){ tmax2=i;  max2=iHigh(NULL, period,i);m=m+1;}
      
      if (m==3) break;
    }
     
   if ( MathAbs( (max1-max2)/(tmax1-tmax2) )>MathAbs( (min1-min2)/(tmin1-tmin2) ) )
   
   if (max1<max2)
   max1=max2+(min1-min2)/(tmin2-tmin1)*(tmax2-tmax1);
   else
   max2=max1+(min1-min2)/(tmin2-tmin1)*(tmax1-tmax2);
   
   else
   
   if (min1>min2)
   min1=min2-(max2-max1)/(tmax2-tmax1)*(tmin2-tmin1);
   else
   min2=min1-(max2-max1)/(tmax2-tmax1)*(tmin1-tmin2);
   
   
   up=max1+(max2-max1)/(tmax2-tmax1)*(0-tmax1);
   down=min1+(min2-min1)/(tmin2-tmin1)*(0-tmin1);
   
   
   set("sup"+DoubleToStr(period,0), OBJ_TREND,iTime(NULL, period,tmin2),min2,iTime(NULL, period1,0),down);  
   set("res"+DoubleToStr(period,0), OBJ_TREND,iTime(NULL, period,tmax2),max2,iTime(NULL, period1,0),up);
   
   set("mid"+DoubleToStr(period,0), OBJ_TREND,
   iTime(NULL, period,(tmin2+tmax2)/2),(min2+max2)/2,iTime(NULL, period1,0),(down+up)/2);
   ObjectSet("mid"+DoubleToStr(period,0),OBJPROP_STYLE,STYLE_DOT);
   ObjectSet("mid"+DoubleToStr(period,0),OBJPROP_COLOR, Black);
   
   if(period==period3)
   {
   ObjectSet("res"+DoubleToStr(period,0),OBJPROP_WIDTH,3);
   ObjectSet("sup"+DoubleToStr(period,0),OBJPROP_WIDTH,3);
   }
   
   if(period==period2)
   {
   ObjectSet("res"+DoubleToStr(period,0),OBJPROP_WIDTH,2);
   ObjectSet("sup"+DoubleToStr(period,0),OBJPROP_WIDTH,2);
   }
   
   ObjectSet("res"+DoubleToStr(period,0),OBJPROP_RAY,false);
   ObjectSet("mid"+DoubleToStr(period,0),OBJPROP_RAY,false);
   ObjectSet("sup"+DoubleToStr(period,0),OBJPROP_RAY,false);
   
   
   
   set("up"+DoubleToStr(period,0),OBJ_TEXT,Time[0],up, 0, 0);
   ObjectSetText("up"+DoubleToStr(period,0),"              "+ DoubleToStr(up, 4), 12, "Times New Roman", Blue);

   set("down"+DoubleToStr(period,0),OBJ_TEXT,Time[0],down,0, 0);
   ObjectSetText("down"+DoubleToStr(period,0),"              "+ DoubleToStr(down,4), 12, "Times New Roman", Red);
   
   return(0);
}

void set(string s,int object, datetime t1, double p1, datetime t2, double p2)
{
   if (ObjectFind(s) != 0) 
     {
      ObjectCreate(s,object,0,t1, p1, t2, p2);
     }
     else
     {
     ObjectDelete(s);
     ObjectCreate(s,object,0,t1, p1, t2, p2);
     }
   ObjectSet(s,OBJPROP_COLOR, Silver);
   return(0);
}

int start()
  {
   static datetime	LastTime;
   if(Time[0] == LastTime) return;
   
   period=period1;main();
   period=period2;main();
   period=period3;main();
   
   LastTime = Time[0];
   return(0);
  }
//+------------------------------------------------------------------+

Comments