MalomaChannel(1)
Download scriptThis script is designed to identify and visualize specific price structures on a trading chart by detecting "Fractals." In simple terms, it looks for significant peaks (highs) and valleys (lows) where the price reaches a point that is higher or lower than its immediate neighbors over a specific range of time.
How the Logic Works
1. Identifying Peaks and Valleys The core logic scans the price history to find specific structural points. Rather than just looking for any high or low price, the script looks for "Fractals"—points where the market reverses direction.
- Upper Channel (Highs): It identifies points where the price is significantly higher than the bars surrounding it.
- Lower Channel (Lows): It identifies points where the price is significantly lower than the bars surrounding it.
2. Multi-Range Analysis The script doesn't just look at one fixed window of time; it systematically checks several different "neighborhoods" to ensure accuracy. It evaluates the data across multiple spans:
- It checks 5-bar ranges, 6-bar ranges, 7-bar ranges, 8-bar ranges, and 9-bar ranges.
- By checking these varying widths, the script can identify both small, immediate price fluctuations and larger, more significant structural turns in the market trend.
3. Handling Price Equality The logic is sophisticated enough to handle "flat" tops or bottoms. For example, if two consecutive bars have the exact same high price but are both higher than the bars before and after them, the script recognizes this as a valid structural peak rather than ignoring it.
4. Visual Output Once the script identifies these significant highs and lows based on its multi-bar checks, it plots them on your chart:
- Red Lines/Markers: These represent the "Up Channel," highlighting the detected high points (peaks).
- Blue Lines/Markers: These represent the "Down Channel," highlighting the detected low points (valleys).
Summary for the User
Think of this script as an automated "scout." It scans the history of every candle to find where the market has reached a local maximum or minimum. By looking at various windows of time (from 5 to 9 bars wide), it ensures that it captures the most relevant price boundaries, helping you visualize the "ceiling" and "floor" of current market movements.
//+--------------------------------------+
//+ ----=== maloma`s`channel ===---- +
//+--------------------------------------+
#property copyright "Copyright © 2006, maloma"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue
//---- input parameters
//---- buffers
double dUpChannelBuffer[];
double dDownChannelBuffer[];
double HiPrice=0;
double LoPrice=0;
double CurHiPrice=0;
double CurLoPrice=0;
int otstup=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicator buffers mapping
SetIndexBuffer(0,dUpChannelBuffer);
SetIndexBuffer(1,dDownChannelBuffer);
//---- drawing settings
SetIndexStyle(0,DRAW_LINE);
SetIndexArrow(0,119);
SetIndexStyle(1,DRAW_LINE);
SetIndexArrow(1,119);
//----
SetIndexEmptyValue(0,0.0);
SetIndexEmptyValue(1,0.0);
//---- name for DataWindow
SetIndexLabel(0,"Channel Up");
SetIndexLabel(1,"Channel Down");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
//----
return(0);
}
int start()
{
int i,nCountedBars;
nCountedBars=IndicatorCounted();
//---- check for possible errors
if(nCountedBars<0) return(-1);
//---- last counted bar will be recounted
if(nCountedBars<=2)
i=Bars-nCountedBars-3;
if(nCountedBars>2)
{
nCountedBars--;
i=Bars-nCountedBars-1;
}
while(i>=2)
{
//----Up and Down Fractals
//----5 bars Fractal
if(High[i]>High[i+1] && High[i]>High[i+2] && High[i]>High[i-1] && High[i]>High[i-2])
{
HiPrice= High[i]+otstup*Point;
dUpChannelBuffer[i-3]= HiPrice;
} else dUpChannelBuffer[i-3]= HiPrice;
if(Low[i]<Low[i+1] && Low[i]<Low[i+2] && Low[i]<Low[i-1] && Low[i]<Low[i-2])
{
LoPrice= Low[i]-otstup*Point;
dDownChannelBuffer[i-3]= LoPrice;
i--;
continue;
} else dDownChannelBuffer[i-3]= LoPrice;
//----6 bars Fractal
if((Bars-i-1)>=3)
{
if(High[i]==High[i+1] && High[i]>High[i+2] && High[i]>High[i+3] && High[i]>High[i-1] && High[i]>High[i-2])
{
HiPrice= High[i]+otstup*Point;
dUpChannelBuffer[i-3]= HiPrice;
} else dUpChannelBuffer[i-3]= HiPrice;
if(Low[i]==Low[i+1] && Low[i]<Low[i+2] && Low[i]<Low[i+3] && Low[i]<Low[i-1] && Low[i]<Low[i-2])
{
LoPrice= Low[i]-otstup*Point;
dDownChannelBuffer[i-3]= LoPrice;
i--;
continue;
} else dDownChannelBuffer[i-3]= LoPrice;
}
//----7 bars Fractal
if((Bars-i-1)>=4)
{
if(High[i]>=High[i+1] && High[i]==High[i+2] && High[i]>High[i+3] && High[i]>High[i+4] && High[i]>High[i-1] &&
High[i]>High[i-2])
{
HiPrice= High[i]+otstup*Point;
dUpChannelBuffer[i-3]= HiPrice;
} else dUpChannelBuffer[i-3]= HiPrice;
if(Low[i]<=Low[i+1] && Low[i]==Low[i+2] && Low[i]<Low[i+3] && Low[i]<Low[i+4] && Low[i]<Low[i-1] &&
Low[i]<Low[i-2])
{
LoPrice= Low[i]-otstup*Point;
dDownChannelBuffer[i-3]= LoPrice;
i--;
continue;
} else dDownChannelBuffer[i-3]= LoPrice;
}
//----8 bars Fractal
if((Bars-i-1)>=5)
{
if(High[i]>=High[i+1] && High[i]==High[i+2] && High[i]==High[i+3] && High[i]>High[i+4] && High[i]>High[i+5] &&
High[i]>High[i-1] && High[i]>High[i-2])
{
HiPrice= High[i]+otstup*Point;
dUpChannelBuffer[i-3]= HiPrice;
} else dUpChannelBuffer[i-3]= HiPrice;
if(Low[i]<=Low[i+1] && Low[i]==Low[i+2] && Low[i]==Low[i+3] && Low[i]<Low[i+4] && Low[i]<Low[i+5] &&
Low[i]<Low[i-1] && Low[i]<Low[i-2])
{
LoPrice= Low[i]-otstup*Point;
dDownChannelBuffer[i-3]= LoPrice;
i--;
continue;
} else dDownChannelBuffer[i-3]= LoPrice;
}
//----9 bars Fractal
if((Bars-i-1)>=6)
{
if(High[i]>=High[i+1] && High[i]==High[i+2] && High[i]>=High[i+3] && High[i]==High[i+4] && High[i]>High[i+5] &&
High[i]>High[i+6] && High[i]>High[i-1] && High[i]>High[i-2])
{
HiPrice= High[i]+otstup*Point;
dUpChannelBuffer[i-3]= HiPrice;
} else dUpChannelBuffer[i-3]= HiPrice;
if(Low[i]<=Low[i+1] && Low[i]==Low[i+2] && Low[i]<=Low[i+3] && Low[i]==Low[i+4] && Low[i]<Low[i+5] &&
Low[i]<Low[i+6] && Low[i]<Low[i-1] && Low[i]<Low[i-2])
{
LoPrice= Low[i]-otstup*Point;
dDownChannelBuffer[i-3]= LoPrice;
i--;
continue;
} else dDownChannelBuffer[i-3]= LoPrice;
}
i--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments