SHI_Channel_Colour_Talk

Author: Copyright � 2004, Shurka & Kevin
SHI_Channel_Colour_Talk

This script is designed to automatically identify and visualize market trends by constructing a dynamic price channel on a trading chart. It focuses on identifying significant structural points in price action to determine the current direction and momentum of the market.

Core Logic and Functionality

1. Structural Identification (Fractals) The tool begins by scanning recent historical price data to locate "fractals"—essentially specific peaks (highs) and troughs (lows). Instead of reacting to every minor price flicker, it uses a specific look-back window (which varies automatically based on the timeframe you are viewing) to ensure it identifies significant turning points.

2. Channel Construction Once it finds two significant structural points (a high and a low), it calculates the trajectory between them:

  • The Slope: It determines the rate of change (the "angle") between these two points. This tells the script whether the trend is moving aggressively upward, downward, or sideways.
  • The Width: It measures the vertical distance between the projected boundaries of the movement.

3. Projection and Visuals Based on the identified slope, the script draws three distinct visual elements on your chart:

  • Upper and Lower Boundaries: These represent the outer limits of the current price channel.
  • Midline: A dotted center line that represents the "fair value" or average path of the trend.
  • Dynamic Extension: The script projects these lines forward into the future (based on a user-defined number of bars) so you can see where the trend is likely to lead if current momentum persists.

4. Dynamic Adjustments The logic is designed to be reactive. It constantly monitors the most recent price action to see if it is breaking out of or staying within the established channel. If the price violates the boundaries, the script adjusts its calculations to account for the new market behavior.

5. Market Intelligence (Comments & Alerts) Beyond just drawing lines, the script performs "health checks" on the trend:

  • Size Analysis: It calculates if the channel is widening (expanding volatility) or narrowing (contracting volatility).
  • Directional Shifts: It monitors for changes in the slope's direction (e.g., moving from a downward tilt to an upward tilt).
  • On-Screen Feedback: It provides real-time data in the corner of your screen, displaying the current channel size and the specific angle of the slope.

Summary for the User

In essence, this tool filters out the "noise" of the market to show you the underlying structure. It identifies where the price has been, calculates the velocity and width of that movement, and projects that path forward, while providing real-time updates on whether that trend is gaining strength (widening) or losing steam (narrowing).

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

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red
double ExtMapBuffer1[];
//---- input parameters
extern int       AllBars=240;
extern int       BarsForFract=0;
extern int       ChannelAlert=50;
extern int       SlopeAlert=25;
extern bool      ChannelTalk=true;
int CurrentBar=0;
int alertTag;
double Step=0;
int B1=-1,B2=-1;
int UpDown=0;
double P1=0,P2=0,PP=0;
double OldChannelWidth,OldSlopeAngle;
int i=0,AB=300,BFF=0;
int ishift=0;
double iprice=0;
datetime T1,T2;
int firsttime=0;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,164);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexEmptyValue(0,0.0);
//----
	
	
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }

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

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   
   string symbolTxt;
   string WhatTxt;
if (Symbol()=="EURUSD") { symbolTxt = "Euro Dollar"; }
if (Symbol()=="EURJPY") { symbolTxt = "Euro Yen "; }
if (Symbol()=="EURAUD") { symbolTxt = "Euro Aussie "; }
if (Symbol()=="EURCAD") { symbolTxt = "Euro Canadian"; }
if (Symbol()=="EURCHF") { symbolTxt = "Euro Swiss"; }
if (Symbol()=="GBPUSD") { symbolTxt = "Cable Dollar"; }
if (Symbol()=="GBPJPY") { symbolTxt = "Cable Yen "; }
if (Symbol()=="GBPCHF") { symbolTxt = "Cable Swiss"; }
if (Symbol()=="AUDUSD") { symbolTxt = "Aussie"; }
if (Symbol()=="USDCHF") { symbolTxt = "Swiss Dollar"; }
if (Symbol()=="USDCAD") { symbolTxt = "Canada"; }
if (Symbol()=="USDJPY") { symbolTxt = "Yen Dollar"; } 
if (Symbol()=="CHFJPY") { symbolTxt = "Swiss Yen "; }
if (Symbol()=="GOLD")   { symbolTxt = "Gold"; }
   
//---- 
	if ((AllBars==0) || (Bars<AllBars)) AB=Bars; else AB=AllBars; //AB-êîëè÷åñòâî îáñ÷èòûâàåìûõ áàðîâ
	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))
	{
		//UpDown=1 çíà÷èò ïåðâûé ôðàêòàë íàéäåí ñâåðõó, UpDown=-1 çíà÷èò ïåðâûé ôðàêòàë
		//íàéäåí ñíèçó, UpDown=0 çíà÷èò ôðàêòàë åù¸ íå íàéäåí.
		//Â1 è Â2 - íîìåðà áàðîâ ñ ôðàêòàëàìè, ÷åðåç íèõ ñòðîèì îïîðíóþ ëèíèþ.
		//Ð1 è Ð2 - ñîîòâåòñòâåííî öåíû ÷åðåç êîòîðûå áóäåì ëèíèþ ïðîâîäèòü

		if((UpDown<1) && (CurrentBar==Lowest(Symbol(),Period(),MODE_LOW,BFF*2+1,CurrentBar-BFF))) 
		{
			if(UpDown==0) { UpDown=-1; B1=CurrentBar; P1=Low[B1]; }
			else { B2=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; P1=High[B1]; }
			else { B2=CurrentBar; P2=High[B2]; }
		}
		CurrentBar++;
	}
	if((B1==-1) || (B2==-1)) {DelObj(); return(-1);} // Çíà÷èò íå íàøëè ôðàêòàëîâ ñðåäè 300 áàðîâ 8-)
	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;}
	}
	//Òåïåðü ïåðåñòàâèì êîíå÷íóþ öåíó è áàð íà ÀÂ, ÷òîáû ëèíèè êàíàëà ðèñîâàëèñü ïîäëèííåå
	P2=P1+AB*Step;
	T1=Time[B1]; T2=Time[AB];

	//Åñëè íå áûëî ïåðåñå÷åíèÿ êàíàëà, òî 0, èíà÷å ñòàâèì ïñèñó.
	if(iprice!=0) ExtMapBuffer1[ishift]=iprice;
	DelObj();
	
	double ChannelWidth=MathAbs(PP - P1)/Point;
	double SlopeAngle=MathFloor((-Step/Point)*100);
	ObjectCreate("TL1",OBJ_TREND,0,T2,PP+Step*AB,T1,PP);
	// Channel is Green if width is greater than ChannelAlert (Default 50), otherwise it is Red
      if(ChannelWidth >= ChannelAlert) {ObjectSet("TL1",OBJPROP_COLOR,Blue);}
	      else {ObjectSet("TL1",OBJPROP_COLOR,Blue); }
		ObjectSet("TL1",OBJPROP_WIDTH,2); 
		ObjectSet("TL1",OBJPROP_STYLE,STYLE_SOLID); 
	ObjectCreate("TL2",OBJ_TREND,0,T2,P2,T1,P1); 	
		if(ChannelWidth >= ChannelAlert) {ObjectSet("TL2",OBJPROP_COLOR,Blue); }
   	  else{ObjectSet("TL2",OBJPROP_COLOR,Blue);}
      ObjectSet("TL2",OBJPROP_WIDTH,2); 
		ObjectSet("TL2",OBJPROP_STYLE,STYLE_SOLID); 
	   ObjectCreate("MIDL",OBJ_TREND,0,T2,(P2+PP+Step*AB)/2,T1,(P1+PP)/2);
	 // Mid line is Green if Slope is greater than SlopeAlert (Default 25), otherwise it is Red
		if(ChannelWidth >= ChannelAlert && MathAbs(SlopeAngle) >= SlopeAlert) {ObjectSet("MIDL",OBJPROP_COLOR,Blue); }
		   else{ObjectSet("MIDL",OBJPROP_COLOR,Blue);}
		ObjectSet("MIDL",OBJPROP_WIDTH,1); 
		ObjectSet("MIDL",OBJPROP_STYLE,STYLE_DOT); 
		WhatTxt="Change";
		if (OldChannelWidth<ChannelWidth) WhatTxt="is widening";
		if (OldChannelWidth>ChannelWidth) WhatTxt="is narrowing";
		if (OldSlopeAngle<0 && SlopeAngle>0 )WhatTxt="Changed direction to up";
		if (OldSlopeAngle>0 && SlopeAngle<0 )WhatTxt="Changed direction to down";
		
		
		if(firsttime && ChannelTalk && alertTag != Time[0]&& OldChannelWidth!=ChannelWidth || OldSlopeAngle!=SlopeAngle)
		{
	//Alert("Shi Channel Change");
		//SpeechText("chee channel"+ WhatTxt+" "+symbolTxt);
                  alertTag = Time[0];
                  
		}
		
			
		
		
		OldChannelWidth=ChannelWidth;
		OldSlopeAngle=SlopeAngle;
		firsttime=firsttime+1;
		Comment(" Channel size = ", DoubleToStr(ChannelWidth,0), " Slope = ", DoubleToStr(SlopeAngle,0));
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments