The CCI Filter is a visual trading tool designed to help market participants identify and categorize the prevailing strength of a currency pair's trend. Rather than just showing raw numerical data, this script translates complex momentum movements into four distinct "market zones," making it easier for traders to decide whether the current environment favors an upward or downward move.
How the Logic Works
The tool operates by analyzing a specific momentum indicator (the Commodity Channel Index) over a user-defined period. It looks at where the market's price action sits relative to its recent average to determine four different types of movement:
- Strong Upward Trend: When the market shows significant upward momentum, the script highlights this as a primary bullish signal.
- Mild Upward Trend: When the price is moving up but lacks high-intensity momentum, the tool identifies it as a "mild" bullish environment.
- Strong Downward Trend: Conversely, when the market experiences sharp selling pressure, the script flags a primary bearish signal.
- Mild Downward Trend: When the price is drifting downward without extreme force, the tool categorizes this as a "mild" bearish environment.
Visual Representation
The indicator provides a clear, color-coded histogram in a separate window on your trading platform. By converting these four different market states into specific visual bars, it allows you to see at a glance:
- Trend Direction: Whether the bias is currently leaning toward "Up" or "Down."
- Momentum Intensity: Whether that move is aggressive (Strong) or more gradual (Mild).
Practical Application
For a trader, this tool acts as a filter. By observing which colored bars are active, you can quickly determine the "mood" of the market. It helps eliminate guesswork by providing a structured view of price momentum, allowing you to align your trades with the prevailing trend rather than trying to fight against the current flow of the market.
//+------------------------------------------------------------------+
//| CCIFilter.mq4 |
//| Copyright © 2006, Forex-TSD.com |
//| Written by nnjeim |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Forex-TSD.com "
#property link "http://www.forex-tsd.com/"
#property indicator_separate_window
#property indicator_minimum -0.05
#property indicator_maximum 1.05
#property indicator_buffers 4
#property indicator_color1 MediumBlue
#property indicator_color2 Crimson
#property indicator_color3 LightBlue
#property indicator_color4 Orange
//---- input parameters
extern int PeriodCCI=50;
//---- indicator buffers
double UpBuffer1[];
double DnBuffer1[];
double UpBuffer2[];
double DnBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- indicator line
SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,2);
SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,2);
SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,2);
SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID,2);
SetIndexBuffer(0,UpBuffer1);
SetIndexBuffer(1,DnBuffer1);
SetIndexBuffer(2,UpBuffer2);
SetIndexBuffer(3,DnBuffer2);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
//---- name for DataWindow and indicator subwindow label
short_name="CCI Filter("+PeriodCCI+")";
IndicatorShortName(short_name);
SetIndexLabel(0,"UpTrend");
SetIndexLabel(1,"DownTrend");
SetIndexLabel(2,"Mild UpTrend");
SetIndexLabel(3,"Mild DownTrend");
//----
SetIndexDrawBegin(0,PeriodCCI);
SetIndexDrawBegin(1,PeriodCCI);
SetIndexDrawBegin(2,PeriodCCI);
SetIndexDrawBegin(3,PeriodCCI);
//----
return(0);
}
//+------------------------------------------------------------------+
//| CCIFilter |
//+------------------------------------------------------------------+
int start()
{
int shift,trend;
double CCI0;
for(shift=Bars-PeriodCCI-1;shift>=0;shift--)
{
CCI0=iCCI(NULL,0,PeriodCCI,PRICE_CLOSE,shift);
if (CCI0>0 && CCI0<100) trend=1;
if (CCI0>100) trend=2;
if (CCI0<0 && CCI0>-100) trend=-1;
if (CCI0<-100) trend=-2;
if (trend==1)
{
UpBuffer1[shift]=0;
UpBuffer2[shift]=1;
DnBuffer1[shift]=0;
DnBuffer2[shift]=0;
}
if (trend==2)
{
UpBuffer1[shift]=1;
UpBuffer2[shift]=0;
DnBuffer1[shift]=0;
DnBuffer2[shift]=0;
}
if (trend==-1)
{
UpBuffer1[shift]=0;
UpBuffer2[shift]=0;
DnBuffer1[shift]=0;
DnBuffer2[shift]=1;
}
if (trend==-2)
{
UpBuffer1[shift]=0;
UpBuffer2[shift]=0;
DnBuffer1[shift]=1;
DnBuffer2[shift]=0;
}
}
return(0);
}
Comments