channels_v2.5

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

This script is a technical analysis tool designed to automatically identify and project key price levels on your trading chart. It focuses on identifying historical "peaks" and "valleys" across three different timeframes simultaneously to help traders visualize potential areas of support and resistance.

Core Functionality

The logic operates by analyzing the price history of three specific periods (defaulted to 60, 240, and 1440 units). For each of these periods, the script performs the following steps:

1. Identifying Extremes The tool scans the historical data to find significant structural points:

  • Peaks: It looks for local high points where the price moved up and then down significantly.
  • Valleys: It identifies local low points where the price moved down and then bounced back up. It specifically seeks out the two most prominent peaks and two most prominent valleys for each timeframe.

2. Projection and Calculation Once these historical points are identified, the script uses a mathematical projection to estimate where those levels might sit in the current market:

  • Trend Extension: It calculates the "slope" of the movement between the identified historical points.
  • Future Forecasting: Based on that slope, it projects a line forward into the current price action. This allows you to see where a previous trend suggests the price "should" be heading or where it might find balance.

3. Visual Representation The script translates these complex calculations into easy-to-read visual elements on your chart:

  • Support and Resistance Lines: It draws visible lines representing the projected low (support) and high (resistance) levels.
  • Mid-Point Reference: A dotted line is automatically drawn to represent the "equilibrium" or halfway point between the support and resistance.
  • Horizontal Markers: It places specific horizontal markings at the current price level to show exactly where these projected values sit relative to today's price.
  • Dynamic Labeling: The script displays the exact numerical values of the upper and lower projected levels directly on the chart, color-coded in Blue (for the upper level) and Red (for the lower level).

User Experience Features

  • Multi-Timeframe Analysis: Because it runs three different periods at once, the chart provides a "layered" view of the market. You can see short-term, medium-term, and long-term price projections all in one place.
  • Visual Hierarchy: The script automatically adjusts the thickness of the lines based on the timeframe. For example, the largest timeframe (1440) uses thicker lines to signify its importance as a major structural level, while smaller timeframes use thinner lines for more granular detail.
  • Real-Time Updates: The logic is designed to refresh with every new price candle, ensuring that the projections and labels stay current as the market moves.
Price Data Components
Series array that contains the lowest prices of each barSeries array that contains the highest prices of each bar
13 Views
1 Downloads
0 Favorites
channels_v2.5
//+------------------------------------------------------------------+
//|                                                  _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));
   ObjectDelete("up_hor"+DoubleToStr(period,0));
   ObjectDelete("down_hor"+DoubleToStr(period,0));
   ObjectDelete("mid_hor"+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, Period(),0),down);  
   set("res"+DoubleToStr(period,0), OBJ_TREND,iTime(NULL, period,tmax2),max2,iTime(NULL, Period(),0),up);
   
   set("mid"+DoubleToStr(period,0), OBJ_TREND,
   iTime(NULL, period,(tmin2+tmax2)/2),(min2+max2)/2,iTime(NULL, Period(),0),(down+up)/2);
   ObjectSet("mid"+DoubleToStr(period,0),OBJPROP_STYLE,STYLE_DOT);
   ObjectSet("mid"+DoubleToStr(period,0),OBJPROP_COLOR, Black);
   
   set("mid_hor"+DoubleToStr(period,0), OBJ_TREND,Time[0],(down+up)/2, Time[0]+(Time[0]-Time[1]),(down+up)/2);
   ObjectSet("mid_hor"+DoubleToStr(period,0),OBJPROP_STYLE,STYLE_DOT);
   ObjectSet("mid_hor"+DoubleToStr(period,0),OBJPROP_COLOR, Black);
   
   set("up_hor"+DoubleToStr(period,0),OBJ_TREND,Time[0],up, Time[0]+(Time[0]-Time[1]), up);
   set("down_hor"+DoubleToStr(period,0),OBJ_TREND,Time[0],down,Time[0]+(Time[0]-Time[1]), down);
   
   ObjectSet("up_hor"+DoubleToStr(period,0),OBJPROP_COLOR, Blue);
   ObjectSet("down_hor"+DoubleToStr(period,0),OBJPROP_COLOR, Red);
   
   if(period==period3)
   {
   ObjectSet("res"+DoubleToStr(period,0),OBJPROP_WIDTH,3);
   ObjectSet("sup"+DoubleToStr(period,0),OBJPROP_WIDTH,3);
   ObjectSet("up_hor"+DoubleToStr(period,0),OBJPROP_WIDTH,3);
   ObjectSet("down_hor"+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("up_hor"+DoubleToStr(period,0),OBJPROP_WIDTH,2);
   ObjectSet("down_hor"+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