TripleCCI_Woodies
Download scriptThis technical script is designed as a sophisticated visual tool for MetaTrader users to analyze market trends and identify potential trading opportunities by combining three different versions of the Commodity Channel Index (CCI) into a single display.
Core Concept: Multi-Layered Analysis
Instead of relying on a single indicator, this tool creates a layered perspective of market momentum. It processes three distinct "speeds" of data simultaneously:
- Trend CCI: Designed to identify the broader market direction over a long period.
- Entry CCI: Acts as a medium-term signal to help find potential points of interest.
- Turbo CCI: A high-speed indicator that reacts quickly to immediate price fluctuations.
Key Features and Logic
1. Dynamic Timeframe Adaptation The script includes an intelligent "Automatic Timeframe Setting." When enabled, the tool automatically adjusts its calculation periods based on the chart you are viewing (e.g., switching from M1 to H4). This ensures that the sensitivity of the indicators remains consistent with the specific time scale of your analysis, allowing for a smoother transition between day trading and long-term investing.
2. Trend Identification & Visualization The logic goes beyond simply showing lines; it categorizes market behavior into visual states:
- Trend Detection: The script tracks how long the main trend stays above or below the zero line. If a trend persists for a specific duration, it highlights the "Trend Up" or "Trend Down" status.
- Neutral Zones: When the market is fluctuating without a clear direction, the tool identifies this as a "No Trend" state.
- Time Bar Logic: The script tracks when a trend has reached a significant maturity point, marking specific "Time Bars" to help traders understand the strength and duration of a current move.
3. Visual Output The indicator populates a separate window with several different visual elements:
- Histograms: These provide a clear vertical representation of the current trend strength (Up, Down, or Neutral).
- Solid Lines: These represent the raw data of the Trend, Entry, and Turbo indicators, allowing you to see the actual values moving in real-time.
4. Intelligent Alert System For active traders, the script features a "Zero Cross Alert." Rather than alerting on every tiny wiggle in price, it monitors for a specific synchronization:
- It triggers an alert only when both the major Trend CCI and the medium-term Entry CCI cross the zero line in the same direction simultaneously.
- This helps filter out "noise" and focuses your attention on moments where both long-term and short-term momentum are aligning for a potential move.
//+------------------------------------------------------------------+
//| 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 8
#property indicator_color1 LimeGreen
#property indicator_color2 Crimson
#property indicator_color3 Orange
#property indicator_color4 Yellow
#property indicator_color5 White
#property indicator_color6 Aqua
#property indicator_color7 Magenta
#property indicator_color8 Yellow
#property indicator_level1 100
#property indicator_level2 200
#property indicator_level3 300
#property indicator_level4 -300
#property indicator_level5 -200
#property indicator_level6 -100
#property indicator_level7 50
#property indicator_level8 -50
//---- input parameters
extern int TrendCCI_Period = 50;
extern int EntryCCI_Period = 14;
extern int TurboCCI_Period = 6;
extern bool Zero_Cross_Alert;
extern bool Automatic_Timeframe_Setting;
extern int M1_TrendCCI_Period = 50;
extern int M1_EntryCCI_Period = 14;
extern int M1_TurboCCI_Period = 6;
extern int M5_TrendCCI_Period = 50;
extern int M5_EntryCCI_Period = 14;
extern int M5_TurboCCI_Period = 6;
extern int M15_TrendCCI_Period = 50;
extern int M15_EntryCCI_Period = 14;
extern int M15_TurboCCI_Period = 6;
extern int M30_TrendCCI_Period = 50;
extern int M30_EntryCCI_Period = 20;
extern int M30_TurboCCI_Period = 6;
extern int H1_TrendCCI_Period = 50;
extern int H1_EntryCCI_Period = 20;
extern int H1_TurboCCI_Period = 6;
extern int H4_TrendCCI_Period = 50;
extern int H4_EntryCCI_Period = 20;
extern int H4_TurboCCI_Period = 6;
extern int D1_TrendCCI_Period = 50;
extern int D1_EntryCCI_Period = 20;
extern int D1_TurboCCI_Period = 6;
extern int W1_TrendCCI_Period = 50;
extern int W1_EntryCCI_Period = 20;
extern int W1_TurboCCI_Period = 6;
extern int MN_TrendCCI_Period = 50;
extern int MN_EntryCCI_Period = 20;
extern int MN_TurboCCI_Period = 6;
double TrendCCI[];
double EntryCCI[];
double TurboCCI[];
double CCITrendUp[];
double CCITrendDown[];
double CCINoTrend[];
double CCITimeBar[];
double ZeroLine[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0, DRAW_HISTOGRAM, 0, 2);
SetIndexBuffer(0, CCITrendUp);
SetIndexStyle(1, DRAW_HISTOGRAM, 0, 2);
SetIndexBuffer(1, CCITrendDown);
SetIndexStyle(2, DRAW_HISTOGRAM, 0, 2);
SetIndexBuffer(2, CCINoTrend);
SetIndexStyle(3, DRAW_HISTOGRAM, 0, 2);
SetIndexBuffer(3, CCITimeBar);
SetIndexStyle(4, DRAW_LINE, STYLE_SOLID, 2);
SetIndexBuffer(4, TrendCCI);
SetIndexLabel(4, "TrendCCI");
SetIndexStyle(5, DRAW_LINE, STYLE_SOLID, 2);
SetIndexBuffer(5, EntryCCI);
SetIndexLabel(5, "EntryCCI");
SetIndexStyle(6, DRAW_LINE, STYLE_SOLID, 1);
SetIndexBuffer(6, TurboCCI);
SetIndexLabel(6, "TurboCCI");
SetIndexStyle(7, DRAW_LINE, STYLE_SOLID, 1);
SetIndexBuffer(7, ZeroLine);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start() {
int limit, i, trendCCI, entryCCI, turboCCI;
static datetime prevtime = 0;
static int trendUp = 0;
static int trendDown = 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; turboCCI = M1_TurboCCI_Period; break;
case 5: trendCCI = M5_TrendCCI_Period; entryCCI = M5_EntryCCI_Period; turboCCI = M5_TurboCCI_Period; break;
case 15: trendCCI = M15_TrendCCI_Period; entryCCI = M15_EntryCCI_Period; turboCCI = M15_TurboCCI_Period; break;
case 30: trendCCI = M30_TrendCCI_Period; entryCCI = M30_EntryCCI_Period; turboCCI = M30_TurboCCI_Period; break;
case 60: trendCCI = H1_TrendCCI_Period; entryCCI = H1_EntryCCI_Period; turboCCI = H1_TurboCCI_Period; break;
case 240: trendCCI = H4_TrendCCI_Period; entryCCI = H4_EntryCCI_Period; turboCCI = H4_TurboCCI_Period; break;
case 1440: trendCCI = D1_TrendCCI_Period; entryCCI = D1_EntryCCI_Period; turboCCI = D1_TurboCCI_Period; break;
case 10080: trendCCI = W1_TrendCCI_Period; entryCCI = W1_EntryCCI_Period; turboCCI = W1_TurboCCI_Period; break;
case 43200: trendCCI = MN_TrendCCI_Period; entryCCI = MN_EntryCCI_Period; turboCCI = MN_TurboCCI_Period; break;
}
}
else {
trendCCI = TrendCCI_Period;
entryCCI = EntryCCI_Period;
turboCCI = TurboCCI_Period;
}
IndicatorShortName("(TrendCCI: " + trendCCI + ", EntryCCI: " + entryCCI + ", TurboCCI: " + turboCCI + " ) ");
for(i = limit; i >= 0; i--) {
ZeroLine[i] = 0;
TrendCCI[i] = iCCI(NULL, 0, trendCCI, PRICE_TYPICAL, i);
EntryCCI[i] = iCCI(NULL, 0, entryCCI, PRICE_TYPICAL, i);
TurboCCI[i] = iCCI(NULL, 0, turboCCI, PRICE_TYPICAL, i);
if (TrendCCI[i+1] < 0 && TrendCCI[i] >= 0) {
if(trendDown < 4) {
CCINoTrend[i] = 0;
CCITrendUp[i] = TrendCCI[i];
CCITrendDown[i] = 0;
CCITimeBar[i] = 0;
}
else {
trendUp = 0;
}
}
if (TrendCCI[i] >= 0 ) {
trendUp++;
if(trendUp == 5) {
CCITimeBar[i] = TrendCCI[i];
CCINoTrend[i] = 0;
CCITrendUp[i] = 0;
CCITrendDown[i] = 0;
}
else if (trendUp > 5) {//(CCITimeBar[i+1] > 0 || CCITrendUp[i+1] > 0) {
CCINoTrend[i] = 0;
CCITrendUp[i] = TrendCCI[i];
CCITrendDown[i] = 0;
CCITimeBar[i] = 0;
}
else {
CCINoTrend[i] = TrendCCI[i];
CCITrendUp[i] = 0;
CCITrendDown[i] = 0;
CCITimeBar[i] = 0;
}
}
if (TrendCCI[i+1] >= 0 && TrendCCI[i] < 0) {
if(trendUp < 4) {
CCINoTrend[i] = 0;
CCITrendUp[i] = 0;
CCITrendDown[i] = TrendCCI[i];
CCITimeBar[i] = 0;
}
else {
trendDown = 0;
}
}
if (TrendCCI[i] <= 0 ) {
trendDown++;
if(trendDown == 5) {
CCITimeBar[i] = TrendCCI[i];
CCINoTrend[i] = 0;
CCITrendUp[i] = 0;
CCITrendDown[i] = 0;
}
else if (trendDown > 5) {//(CCITimeBar[i+1] < 0 || CCITrendDown[i+1] < 0) {
CCINoTrend[i] = 0;
CCITrendUp[i] = 0;
CCITrendDown[i] = TrendCCI[i];
CCITimeBar[i] = 0;
}
else {
CCINoTrend[i] = TrendCCI[i];
CCITrendUp[i] = 0;
CCITrendDown[i] = 0;
CCITimeBar[i] = 0;
}
}
if (TrendCCI[i+1] == 0 && TrendCCI[i] >= 0 && CCITrendUp[i+2] > 0) {
CCINoTrend[i] = 0;
CCITrendUp[i] = TrendCCI[i];
CCITrendDown[i] = 0;
CCITimeBar[i] = 0;
}
}
if (Zero_Cross_Alert == true) {
if (prevtime == Time[0]) {
return(0);
}
else {
if(EntryCCI[0] < 0) {
if((TrendCCI[0] < 0) && (TrendCCI[1] >= 0)) {
Alert(Symbol(), " M", Period(), " Trend & Entry CCI Have both crossed below zero");
}
}
else if(EntryCCI[0] > 0) {
if((TrendCCI[0] > 0) && (TrendCCI[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