WcciChart_v1
Download scriptThis technical script is designed as a specialized trading indicator for MetaTrader platforms. Its primary purpose is to analyze market momentum and identify the prevailing trend by utilizing a dual-layer approach involving the Commodity Channel Index (CCI) - a popular technical oscillator used to measure price deviations from an average.
Core Functional Logic
The tool operates by processing two different timeframes of market data simultaneously: a "Fast" period and a "Slow" period. By comparing these two, the script helps traders distinguish between immediate price fluctuations and broader market movements.
1. Momentum Tracking The indicator calculates two distinct CCI values. The Fast CCI reacts quickly to recent price changes, while the Slow CCI provides a more stabilized view of the market's direction. These are displayed as lines on your chart, allowing you to see the "velocity" of the price action.
2. Trend Confirmation via Histogram and Visual Cues Beyond just showing lines, the script incorporates a sophisticated filtering system to identify "true" trends:
- Histogram Analysis: The script creates a histogram based on the Slow CCI values to provide a visual representation of historical momentum.
- Trend Validation: To filter out market "noise" or minor fluctuations, the script looks back at the last 8 data points of the Slow CCI. It counts how many of these points are above or below zero.
- Signal Generation: A trend is only confirmed as an "Up Trend" if at least 6 out of the 8 points are positive. Conversely, it is confirmed as a "Down Trend" if at least 6 out of the 8 points are negative.
3. Visual Output When these conditions are met, the script dynamically highlights the trend using specific visual markers (Histograms and Lines). This allows a trader to see at a glance whether the market is in a confirmed bullish state (Up Trend) or a bearish state (Down Trend), effectively smoothing out the "choppy" movements that often occur in volatile markets.
Summary for the User
In simple terms, this tool acts as a trend filter. It takes raw price data, calculates its momentum using two different speeds, and then applies a voting system to ensure that a trend is actually significant before displaying it as a confirmed signal. It aims to help you stay on the right side of the market movement while ignoring small, insignificant price wiggles.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
#property copyright "(C)2005, Yuri Ershtad & Nirvanatiger"
#property link "http://www.metaquotes.net"
#property indicator_separate_window
#property indicator_buffers 7
#property indicator_color1 Blue
#property indicator_color2 Lime
#property indicator_color3 OrangeRed
#property indicator_color4 HotPink
#property indicator_color5 OrangeRed
#property indicator_color6 White
#property indicator_color7 White
#property indicator_level1 225
#property indicator_level2 100
#property indicator_level3 0
#property indicator_level4 -100
#property indicator_level5 -225
//////////////////////////////////////////////////////////////////////
// Ïàðåìåòû
//////////////////////////////////////////////////////////////////////
extern int fastPeriod = 6;
extern int slowPeriod = 14;
//////////////////////////////////////////////////////////////////////
// Áóôåðû äàííûõ
//////////////////////////////////////////////////////////////////////
double FastBuffer[]; // Áûñòðûé CCI
double SlowBuffer[]; // Ìåäëåííûé CCI
double HistBuffer[];
double UpTrBuffer[];
double DnTrBuffer[];
double UpTrBuffer2[];
double DnTrBuffer2[];
//////////////////////////////////////////////////////////////////////
// Èíèöèàëèçàöèÿ
//////////////////////////////////////////////////////////////////////
int init()
{
string short_name;
IndicatorBuffers(7);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
short_name="WoodiesCCI("+fastPeriod+","+slowPeriod+")";
IndicatorShortName(short_name);
// indicator lines ////////////////////////////////
SetIndexStyle(0, DRAW_HISTOGRAM);
SetIndexBuffer(0, HistBuffer);
SetIndexDrawBegin(0, slowPeriod);
SetIndexLabel(0,"SlowCCI histogram");
SetIndexEmptyValue(0, EMPTY_VALUE);
//////////////////////////////////////////////////
SetIndexStyle(1, DRAW_HISTOGRAM);
SetIndexBuffer(1, UpTrBuffer);
SetIndexDrawBegin(1, slowPeriod);
SetIndexLabel(1,"UpTrend histogram");
SetIndexEmptyValue(1, EMPTY_VALUE);
//////////////////////////////////////////////////
SetIndexStyle(2, DRAW_HISTOGRAM);
SetIndexBuffer(2, DnTrBuffer);
SetIndexDrawBegin(2, slowPeriod);
SetIndexLabel(2,"DnTrend histogram");
SetIndexEmptyValue(2, EMPTY_VALUE);
//////////////////////////////////////////////////
SetIndexStyle(3, DRAW_LINE,2,3);
SetIndexBuffer(3, SlowBuffer);
SetIndexDrawBegin(3, slowPeriod);
SetIndexLabel(3,"SlowCCI("+slowPeriod+")");
SetIndexEmptyValue(3, EMPTY_VALUE);
//////////////////////////////////////////////////
SetIndexStyle(4, DRAW_LINE);
SetIndexBuffer(4, FastBuffer);
SetIndexDrawBegin(4, slowPeriod);
SetIndexLabel(4,"FastCCI("+fastPeriod+")");
SetIndexEmptyValue(4, EMPTY_VALUE);
//////////////////////////////////////////////////
SetIndexStyle(5, DRAW_LINE, 1, 3);
SetIndexBuffer(5, UpTrBuffer2);
SetIndexDrawBegin(5, slowPeriod);
SetIndexLabel(5,"UpTrend line");
SetIndexEmptyValue(5, EMPTY_VALUE);
//////////////////////////////////////////////////
SetIndexStyle(6, DRAW_LINE, 1, 3);
SetIndexBuffer(6, DnTrBuffer2);
SetIndexDrawBegin(6, slowPeriod);
SetIndexLabel(6,"DnTrend line");
SetIndexEmptyValue(6, EMPTY_VALUE);
//////////////////////////////////////////////////
return(0);
}
//////////////////////////////////////////////////////////////////////
// Custor indicator deinitialization function
//////////////////////////////////////////////////////////////////////
int deinit()
{
// TODO: add your code here
return(0);
}
//////////////////////////////////////////////////////////////////////
// Custom indicator iteration function
//////////////////////////////////////////////////////////////////////
int start()
{
string symbolName;
int i, shift, checksum, counted_bars=IndicatorCounted();
double slowCCI=0.0;
if (Bars<slowPeriod) return(0);
// check for possible errors
if (counted_bars<0) return(-1);
// last counted bar will be recounted
if (counted_bars>0) counted_bars++;
int limit=Bars-counted_bars;
if (counted_bars<1 || checksum!=(fastPeriod+slowPeriod+Period()) || symbolName!=Symbol())
{
// Ïàðàìåòðû èçìåíåíû, ïðîâîäèì ðåèíèöèàëèçàöèþ
for(i=1; i<=slowPeriod; i++) FastBuffer[Bars-i]=EMPTY_VALUE; // Áûñòðûé CCI
for(i=1; i<=slowPeriod; i++) SlowBuffer[Bars-i]=EMPTY_VALUE; // Ìåäëåííûé CCI
for(i=1; i<=slowPeriod; i++) HistBuffer[Bars-i]=EMPTY_VALUE; // Ãèñòîãðàììà ìåäëåííîãî CCI
for(i=1; i<=slowPeriod; i++) UpTrBuffer[Bars-i]=EMPTY_VALUE; // Íàïðàâëåíèå òðåíäà
for(i=1; i<=slowPeriod; i++) DnTrBuffer[Bars-i]=EMPTY_VALUE; // Íàïðàâëåíèå òðåíäà
for(i=1; i<=slowPeriod; i++) UpTrBuffer2[Bars-i]=EMPTY_VALUE; // Íàïðàâëåíèå òðåíäà
for(i=1; i<=slowPeriod; i++) DnTrBuffer2[Bars-i]=EMPTY_VALUE; // Íàïðàâëåíèå òðåíäà
checksum = fastPeriod+slowPeriod+Period();
symbolName=Symbol();
limit=Bars-slowPeriod;
}
for (shift=limit; shift>=0; shift--)
{
FastBuffer[shift] = iCCI(NULL,0,fastPeriod,PRICE_TYPICAL,shift);
SlowBuffer[shift] = iCCI(NULL,0,slowPeriod,PRICE_TYPICAL,shift);
HistBuffer[shift] = SlowBuffer[shift];
UpTrBuffer[shift] = EMPTY_VALUE;
DnTrBuffer[shift] = EMPTY_VALUE;
UpTrBuffer2[shift] = EMPTY_VALUE;
DnTrBuffer2[shift] = EMPTY_VALUE;
// Çàïîëíåíèå ìàññèâà òî÷åê è îïðåäåëåíèå òðåíäà
int a, up=0, dn=0;
for (a=0;a<8;a++)
{
slowCCI=iCCI(NULL,0,slowPeriod,PRICE_TYPICAL,shift+a);
if (slowCCI>0) up++;
if (slowCCI<=0) dn++;
}
if (up>=6){
UpTrBuffer[shift]=SlowBuffer[shift];
UpTrBuffer2[shift]=SlowBuffer[shift];
}
if (dn>=6){
DnTrBuffer[shift]=SlowBuffer[shift];
DnTrBuffer2[shift]=SlowBuffer[shift];
}
}
return(0);
}
//////////////////////////////////////////////////////////////////////
Comments