FractalChannel_v4_v1

Download script
Author: Copyright � 2006, TrendLaboratory
FractalChannel_v4_v1

This tool is designed to provide a visual representation of market structure by identifying specific price boundaries and trends. It works by analyzing "fractals"—which are essentially significant local highs and lows in the price action—to construct dynamic channels on your trading chart.

How the Logic Works

1. Identifying Market Extremes (Fractals) The core logic relies on detecting structural peaks and valleys. Rather than just looking at every single price movement, the script scans for specific points where the market has turned. It looks for "fractal" patterns where a peak is higher than its immediate neighbors or a valley is lower than those around it. The sensitivity of these points can be adjusted, allowing you to choose between identifying major structural shifts or smaller, more frequent price fluctuations.

2. Dynamic Boundary Tracking Once the script identifies these significant highs and lows, it keeps a continuous record of them as they progress across the chart. It remembers the most recent "important" prices to ensure that the boundaries aren't just static lines; they evolve as the market moves.

Depending on the settings, the script can also include "raw" price data (the highest high or lowest low reached in a specific period) to ensure the boundaries stay wide enough to encompass all recent price action.

3. Channel Construction Based on these tracked highs and lows, the script calculates three distinct visual lines:

  • The Upper Boundary: This represents the ceiling of the current market structure. It is calculated by taking the highest point identified and applying a margin.
  • The Lower Boundary: This represents the floor of the market structure, calculated using the lowest point identified and the same margin.
  • The Middle Channel: The script automatically calculates the midpoint between the upper and lower boundaries.

Practical Application

By mapping out these three lines, the tool provides a visual "envelope" for price action. Traders can use these channels to visualize the current range of the market, identify where price is pushing against resistance (the ceiling), or see where it is finding support (the floor). The "Margin" setting allows users to customize how far inside these boundaries the lines sit, providing flexibility for different trading styles.

Miscellaneous
Implements a curve of type %1
10 Views
0 Downloads
0 Favorites
FractalChannel_v4_v1
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                            FractalChannel_v4.mq4 |
//|                                Copyright © 2006, TrendLaboratory |
//|            http://finance.groups.yahoo.com/group/TrendLaboratory |
//|                                   E-mail: igorad2003@yahoo.co.uk |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, TrendLaboratory"
#property link      "http://finance.groups.yahoo.com/group/TrendLaboratory"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 LightBlue
#property indicator_color2 Tomato
#property indicator_color3 Yellow
#property indicator_width1 2
#property indicator_width2 2
//---- input parameters
extern int     ChannelType = 1;
extern double  Margins     = 0;
extern int     Shift       = 0;
extern int     Mode        = 0;

//---- buffers
double UpBuffer[];
double DnBuffer[];
double MdBuffer[];
double smin[];
double smax[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- indicator line
   IndicatorBuffers(5);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE,2);
   SetIndexBuffer(0,UpBuffer);
   SetIndexBuffer(1,DnBuffer);
   SetIndexBuffer(2,MdBuffer);
   SetIndexBuffer(3,smin);
   SetIndexBuffer(4,smax);
//---- name for DataWindow and indicator subwindow label
   short_name="Fractal Channel("+ChannelType+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,"Up Channel");
   SetIndexLabel(1,"Down Channel");
   SetIndexLabel(2,"Middle Channel");

   SetIndexShift(0,Shift);
   SetIndexShift(1,Shift);
   SetIndexShift(2,Shift);
//----
   SetIndexDrawBegin(0,2*ChannelType);
   SetIndexDrawBegin(1,2*ChannelType);
   SetIndexDrawBegin(2,2*ChannelType);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| FractalChannel_v3.1                                                |
//+------------------------------------------------------------------+
int start()
{
int  	   shift,k,counted_bars=IndicatorCounted();
double   v1,v2,cond[100];
			
   if ( counted_bars > 0 )  int limit=Bars-counted_bars-1;
   if ( counted_bars < 0 )  return(0);
   if ( counted_bars ==0 )  limit=Bars-2*ChannelType-1; 
     
	for(shift=limit;shift>=0;shift--) 
   {	
	v1 = Fractals(0,ChannelType,shift);
	v2 = Fractals(1,ChannelType,shift);
	
	smax[shift]=smax[shift+1];			
	if ( v1>0 ) smax[shift]=v1; 
	if (Mode == 0)
	if (High[shift]>smax[shift]) smax[shift]=High[shift];
	smin[shift]=smin[shift+1];
	if ( v2>0 ) smin[shift]=v2; 
	if (Mode == 0)
	if (Low[shift]<smin[shift]) smin[shift]=Low[shift];
	
	if (shift==Bars-1-2*ChannelType) {smin[shift]=Low[shift];smax[shift]=High[shift];}
	
	UpBuffer[shift]=smax[shift]-(smax[shift]-smin[shift])*Margins;
	DnBuffer[shift]=smin[shift]+(smax[shift]-smin[shift])*Margins;
	MdBuffer[shift]=(UpBuffer[shift]+DnBuffer[shift])/2;
	}
return(0);
}

double Fractals(int Type, int Size, int i)
{
   int k=1;
	double v1, cond[100];
	
	while (k<=Size) 
	{
      if (Type==0) bool condition = High[i+Size+k]<=High[i+Size] && High[i+Size-k]<High[i+Size];
      else condition = Low[i+Size+k]>=Low[i+Size] && Low[i+Size-k]>Low[i+Size];
      
      if (condition) 
      {
      if (Type==0) cond[k]=High[i+Size]; else cond[k]=Low[i+Size];
	     if(k==1)
	     {v1=cond[k];k++;} 
	     else
	     if(cond[k-1]==cond[k]){v1=cond[k];k++;}else {v1=0; break;}
	     
      }     
      else
      {
      v1=0;
      break;
	   }
	}
return(v1);	
}  
//+------------------------------------------------------------------+

Comments