DoubleCCI
Download scriptThis tool is a specialized technical analysis indicator designed to help traders visualize market momentum and identify potential entry points by analyzing two different "layers" of market movement simultaneously.
Core Logic Overview
The script operates by calculating the Commodity Channel Index (CCI)—a standard momentum oscillator—at two distinct speeds or scales. By overlaying these two calculations, the tool allows you to distinguish between the broader market trend and shorter-term price fluctuations.
Key Components of the Logic:
1. Dual-Layer Analysis (Trend vs. Entry)
- The Trend Layer: This represents the "big picture." It uses a longer look-back period to identify the primary direction of the market. On your chart, this is displayed as a visual histogram that shows whether the overall momentum is positive or negative.
- The Entry Layer: This represents the "fine detail." It uses a much shorter look-back period to capture rapid price changes. This helps traders see immediate reactions in the price that might be too small to appear on the main trend line but are significant for timing an entry.
2. Smart Timeframe Adaptation One of the primary features of this script is its ability to automatically adjust its internal settings based on which chart you are currently viewing.
- If you switch to a fast, volatile timeframe (like a 1-minute chart), the tool automatically narrows its focus to capture quick movements.
- If you switch to a slow, stable timeframe (like a Daily or Weekly chart), the tool expands its perspective to prioritize long-term stability.
- This ensures that the "Trend" and "Entry" signals remain mathematically appropriate regardless of whether you are scalping for small gains or swing trading for large moves.
3. Visual Representation The indicator populates a separate window on your platform with several visual cues:
- Histograms: These provide a clear, immediate view of the Trend CCI, showing upward and downward momentum relative to a center line.
- Reference Lines: The tool places specific horizontal levels (such as 50, 100, 150, 200 and their negative counterparts) to help you identify "overbought" or "oversold" conditions.
4. Automated Alert System The script includes a notification logic designed to filter out noise. Instead of alerting on every small movement, it monitors for specific "Zero Cross" events. It will trigger an alert only when:
- Both the Trend and the Entry indicators cross below zero simultaneously (potentially signaling a downward shift).
- Both the Trend and the Entry indicators cross above zero simultaneously (potentially signaling an upward shift).
This double-confirmation logic is intended to help traders avoid "fakeouts" by ensuring that both the immediate momentum and the broader trend are moving in the same direction before a signal is recognized.
//+------------------------------------------------------------------+
//| DoubleCCI.mq4 |
//| Copyright © 2005, Jason Robinson (jnrtrading). |
//| http://www.jnrtrading.co.uk |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Jason Robinson (jnrtrading)."
#property link "http://www.jnrtrading.co.uk"
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 Lime
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 Black
#property indicator_level1 50
#property indicator_level2 100
#property indicator_level3 150
#property indicator_level4 200
#property indicator_level5 -200
#property indicator_level6 -150
#property indicator_level7 -100
#property indicator_level8 -50
//---- input parameters
extern int TrendCCI_Period = 50;
extern int EntryCCI_Period = 14;
extern bool Zero_Cross_Alert;
extern bool Automatic_Timeframe_Setting;
extern int M1_TrendCCI_Period = 50;
extern int M1_EntryCCI_Period = 14;
extern int M5_TrendCCI_Period = 50;
extern int M5_EntryCCI_Period = 14;
extern int M15_TrendCCI_Period = 14;
extern int M15_EntryCCI_Period = 6;
extern int M30_TrendCCI_Period = 14;
extern int M30_EntryCCI_Period = 6;
extern int H1_TrendCCI_Period = 14;
extern int H1_EntryCCI_Period = 6;
extern int H4_TrendCCI_Period = 14;
extern int H4_EntryCCI_Period = 6;
extern int D1_TrendCCI_Period = 14;
extern int D1_EntryCCI_Period = 6;
extern int W1_TrendCCI_Period = 14;
extern int W1_EntryCCI_Period = 6;
extern int MN_TrendCCI_Period = 14;
extern int MN_EntryCCI_Period = 6;
double TrendCCIBuffer[];
double CCIHistogramUpBuffer[];
double CCIHistogramDownBuffer[];
double EntryCCIBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(2, DRAW_LINE, STYLE_SOLID, 2);
SetIndexBuffer(2, TrendCCIBuffer);
SetIndexLabel(2, "TrendCCI");
SetIndexStyle(0, DRAW_HISTOGRAM, 0, 3);
SetIndexBuffer(0, CCIHistogramUpBuffer);
SetIndexStyle(1, DRAW_HISTOGRAM, 0, 3);
SetIndexBuffer(1, CCIHistogramDownBuffer);
SetIndexStyle(3, DRAW_LINE, STYLE_SOLID, 2);
SetIndexBuffer(3, EntryCCIBuffer);
SetIndexLabel(3, "EntryCCI");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start() {
int limit, i, trendCCI, entryCCI;
static datetime prevtime = 0;
int counted_bars = IndicatorCounted();
//---- check for possible errors
if(counted_bars < 0) return(-1);
//---- last counted bar will be recounted
if(counted_bars > 0) counted_bars--;
limit=Bars-counted_bars;
if (Automatic_Timeframe_Setting == true) {
switch(Period()) {
case 1: trendCCI = M1_TrendCCI_Period; entryCCI = M1_EntryCCI_Period; break;
case 5: trendCCI = M5_TrendCCI_Period; entryCCI = M5_EntryCCI_Period; break;
case 15: trendCCI = M15_TrendCCI_Period; entryCCI = M15_EntryCCI_Period; break;
case 30: trendCCI = M30_TrendCCI_Period; entryCCI = M30_EntryCCI_Period; break;
case 60: trendCCI = H1_TrendCCI_Period; entryCCI = H1_EntryCCI_Period; break;
case 240: trendCCI = H4_TrendCCI_Period; entryCCI = H4_EntryCCI_Period; break;
case 1440: trendCCI = D1_TrendCCI_Period; entryCCI = D1_EntryCCI_Period; break;
case 10080: trendCCI = W1_TrendCCI_Period; entryCCI = W1_EntryCCI_Period; break;
case 43200: trendCCI = MN_TrendCCI_Period; entryCCI = MN_EntryCCI_Period; break;
}
}
else {
trendCCI = TrendCCI_Period;
entryCCI = EntryCCI_Period;
}
IndicatorShortName("(TrendCCI: " + trendCCI + ", EntryCCI: " + entryCCI + ") ");
for(i = 0; i <= limit; i++) {
TrendCCIBuffer[i] = iCCI(NULL, 0, trendCCI, PRICE_TYPICAL, i);
if (TrendCCIBuffer[i] >= 0 )
CCIHistogramUpBuffer[i] = TrendCCIBuffer[i];
else
CCIHistogramUpBuffer[i] = 0;
if (TrendCCIBuffer[i] < 0 )
CCIHistogramDownBuffer[i] = TrendCCIBuffer[i];
else
CCIHistogramDownBuffer[i]=0;
EntryCCIBuffer[i] = iCCI(NULL, 0, entryCCI, PRICE_TYPICAL, i);
}
if (Zero_Cross_Alert == true) {
if (prevtime == Time[0]) {
return(0);
}
else {
if(EntryCCIBuffer[0] < 0) {
if((TrendCCIBuffer[0] < 0) && (TrendCCIBuffer[1] >= 0)) {
Alert(Symbol(), " M", Period(), " Trend & Entry CCI Have both crossed below zero");
}
}
else if(EntryCCIBuffer[0] > 0) {
if((TrendCCIBuffer[0] > 0) && (TrendCCIBuffer[1] <= 0)) {
Alert(Symbol(), " M", Period(), " Trend & Entry CCI Have both crossed above zero");
}
}
prevtime = Time[0];
}
}
ObjectCreate("ZeroLine", OBJ_HLINE, WindowFind("(TrendCCI: \" + trendCCI + \", EntryCCI: \" + entryCCI + \") "), 0, 0);
//----
//----
return(0);
}
//+------------------------------------------------------------------+
Comments