SHI_Channel_true_v2

Download script
Author: Copyright � 2004, Shurka & Kevin
SHI_Channel_true_v2

This script is designed as a technical analysis tool for the MetaTrader platform, specifically engineered to identify and visualize market trends by calculating dynamic price channels. Rather than relying on simple moving averages, it utilizes a structural approach to determine the geometry of the current market movement.

Core Logic Overview

The script functions by identifying significant historical "swing points"—the highest highs and lowest lows—within a specific timeframe. It uses these anchor points to establish a linear trajectory, effectively drawing a trend corridor that represents the prevailing price direction.

Key Functional Steps:

  • Dynamic Range Analysis: The tool automatically adjusts its sensitivity based on the chart's timeframe (e.g., it looks at different amounts of historical data for a 1-minute chart versus a 4-hour chart). This ensures that the "noise" of short-term price fluctuations does not distort the long-term trend analysis.
  • Anchor Point Identification: The logic searches backwards through recent price action to find two primary extremes. By locating these peaks and valleys, the script establishes the "slope" of the market.
  • Trend Geometry Calculation: Once the primary points are found, the script calculates a consistent "Step" (the rate of change). It then projects this slope forward into the future.
  • Support and Resistance Mapping: The script calculates two distinct trend lines based on these findings:
    1. A primary boundary line that tracks the main trend direction.
    2. A secondary parallel boundary line (a "channel") that creates a corridor for price action.
  • Midpoint Projection: In addition to the outer boundaries, the script calculates and displays a dotted centerline. This represents the "equilibrium" of the current trend, helping traders identify where the price is sitting relative to its upper and lower limits.

Visual Output

The tool communicates this data by drawing three specific objects on your chart:

  • Primary Trend Line: A solid line highlighting the dominant direction of the market.
  • Parallel Channel Line: A second solid line that creates a visual "tunnel" or channel for price movement.
  • Median Line: A dotted line marking the center point between the two boundaries, serving as a neutral zone for trend strength.

In summary, this script automates the manual process of drawing trend channels, providing a clear visual representation of market momentum, direction, and expected price boundaries based on historical structural extremes.

Miscellaneous
Implements a curve of type %1
6 Views
0 Downloads
0 Favorites
SHI_Channel_true_v2
//+------------------------------------------------------------------+
//|                                             SHI_Channel_true.mq4 |
//|                                 Copyright © 2004, Shurka & Kevin |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, Shurka & Kevin"
#property link      ""

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 White

double ExtMapBuffer1[];
double UpLabel[];
//---- input parameters
extern int       AllBars=240;
extern int       BarsForFract=0;
extern int       TLineWidth=1;
extern int       AWidth=2;
extern int       XWidth=3;

int CurrentBar=0;
int iB1=0,iB2=0,ii=0;
int iB4=0,iB3=0;
double Step=0;
int B1=-1,B2=-1;
int UpDown=0;
double P1=0,P2=0,PP=0;
int i=0,AB=300,BFF=0;
int ishift=0;
double iprice=0;
datetime T1,T2;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_ARROW,STYLE_SOLID,AWidth);
   SetIndexArrow(0,164);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexEmptyValue(0,0.0);
   
   SetIndexStyle(1,DRAW_ARROW,STYLE_SOLID,XWidth);
   SetIndexArrow(1,251);
   SetIndexBuffer(1,UpLabel);
   SetIndexEmptyValue(1,0.0);
//----

	
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   ObjectDelete("TL1");
	ObjectDelete("TL2");
	ObjectDelete("MIDL");
//----
   return(0);
  }

void DelObj()
{
	ObjectDelete("TL1");
	ObjectDelete("TL2");
	ObjectDelete("MIDL");
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//---- 
	int r;
	for (r=0;r<=Bars;r++){
	  UpLabel[r]=0;
	}
	if ((AllBars==0) || (Bars<AllBars)) AB=Bars; else AB=AllBars;
	if (BarsForFract>0) 
		BFF=BarsForFract; 
	else
	{
		switch (Period())
		{
			case 1: BFF=12; break;
			case 5: BFF=48; break;
			case 15: BFF=24; break;
			case 30: BFF=24; break;
			case 60: BFF=12; break;
			case 240: BFF=15; break;
			case 1440: BFF=10; break;
			case 10080: BFF=6; break;
			default: DelObj(); return(-1); break;
		}
	}
	CurrentBar=2;
	B1=-1; B2=-1; UpDown=0;
	while(((B1==-1) || (B2==-1)) && (CurrentBar<AB))
	{
		if((UpDown<1) && (CurrentBar==Lowest(Symbol(),Period(),MODE_LOW,BFF*2+1,CurrentBar-BFF))) 
		{
			if(UpDown==0) { UpDown=-1; B1=CurrentBar; iB1=CurrentBar; P1=Low[B1]; }
			else { B2=CurrentBar; iB3=CurrentBar; P2=Low[B2];}
		}
		if((UpDown>-1) && (CurrentBar==Highest(Symbol(),Period(),MODE_HIGH,BFF*2+1,CurrentBar-BFF))) 
		{
			if(UpDown==0) { UpDown=1; B1=CurrentBar; iB1=CurrentBar; P1=High[B1]; }
			else { B2=CurrentBar; iB4=CurrentBar; P2=High[B2]; }
		}
		CurrentBar++;
	}
	if((B1==-1) || (B2==-1)) {DelObj(); return(-1);}
	Step=(P2-P1)/(B2-B1);
	P1=P1-B1*Step; B1=0;
	ishift=0; iprice=0;
	if(UpDown==1)
	{ 
		PP=Low[2]-2*Step;
		for(i=3;i<=B2;i++) 
		{
			if(Low[i]<PP+Step*i) { PP=Low[i]-i*Step; }
		}
		if(Low[0]<PP) {ishift=0; iprice=PP;}
		if(Low[1]<PP+Step) {ishift=1; iprice=PP+Step;}
		if(High[0]>P1) {ishift=0; iprice=P1;}
		if(High[1]>P1+Step) {ishift=1; iprice=P1+Step;}
	} 
	else
	{ 
		PP=High[2]-2*Step;
		for(i=3;i<=B2;i++) 
		{
			if(High[i]>PP+Step*i) { PP=High[i]-i*Step;}
		}
		if(Low[0]<P1) {ishift=0; iprice=P1;}
		if(Low[1]<P1+Step) {ishift=1; iprice=P1+Step;}
		if(High[0]>PP) {ishift=0; iprice=PP;}
		if(High[1]>PP+Step) {ishift=1; iprice=PP+Step;}
	}
	
	     UpLabel[iB4]=High[iB4]+4*Point;
        UpLabel[iB3]=Low[iB3]-4*Point;
      
	P2=P1+AB*Step;
	T1=Time[B1]; T2=Time[AB];

	if(iprice!=0) ExtMapBuffer1[ishift]=iprice;
	DelObj();
	ObjectCreate("TL1",OBJ_TREND,0,T2,PP+Step*AB,T1,PP); 
		ObjectSet("TL1",OBJPROP_COLOR,Lime); 
		ObjectSet("TL1",OBJPROP_WIDTH,TLineWidth); 
		ObjectSet("TL1",OBJPROP_STYLE,STYLE_SOLID); 
	ObjectCreate("TL2",OBJ_TREND,0,T2,P2,T1,P1); 
		ObjectSet("TL2",OBJPROP_COLOR,Lime); 
		ObjectSet("TL2",OBJPROP_WIDTH,TLineWidth); 
		ObjectSet("TL2",OBJPROP_STYLE,STYLE_SOLID); 
	ObjectCreate("MIDL",OBJ_TREND,0,T2,(P2+PP+Step*AB)/2,T1,(P1+PP)/2);
		ObjectSet("MIDL",OBJPROP_COLOR,Lime); 
		ObjectSet("MIDL",OBJPROP_WIDTH,1); 
		ObjectSet("MIDL",OBJPROP_STYLE,STYLE_DOT);
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments