Author: mladen
All_CCI

This script is a specialized multi-timeframe analysis tool designed to help traders visualize the Commodity Channel Index (CCI) across several different time horizons simultaneously. Instead of looking at just one timeframe at a time, it provides a comprehensive "bird's-eye view" of market momentum.

Core Functionality

The primary purpose of this tool is to overlay the CCI data from multiple timeframes—ranging from short-term (like 1-minute or 5-minute charts) to long-term (like Daily or Weekly charts)—onto a single visual window. This allows a trader to see how current price action aligns with broader market trends at a glance.

Key Features and Logic

  • Multi-Timeframe Synchronization: The tool automatically selects a set of relevant timeframes based on your preferences. It can dynamically adjust these to show either "short" intervals (useful for scalping) or "long" intervals (better for swing trading), ensuring the data is always relevant to your specific trading style.
  • Dynamic Scaling and Boundaries: To ensure that all the different timeframes can be viewed clearly in one window without overlapping messily, the script calculates the highest and lowest values reached by the CCI across all displayed periods. It then creates visual boundaries (min/max lines) so you can see the relative position of every timeframe against the same scale.
  • Visual Separation: The script distinguishes between different timeframes using a series of horizontal separators and clear text labels. This makes it easy to identify which line belongs to which timeframe, preventing confusion when looking at multiple overlapping data sets.
  • Customizable Layout: Users have the flexibility to adjust how many past bars are displayed for each timeframe and whether the data should be slightly offset (shifted) to the right to improve readability on the chart.

How it Benefits the Trader

By using this tool, a trader can quickly identify confluence. For example, you might see that while a short-term timeframe shows a bullish move, the longer-term timeframes are still trending downward. By visualizing all of these factors in one place, the script helps traders make more informed decisions by ensuring they aren't trading against the "bigger picture" of the market.

Indicators Used
Commodity channel index
Miscellaneous
Implements a curve of type %1
14 Views
0 Downloads
0 Favorites
All_CCI
//+------------------------------------------------------------------+
//|                                                      All CCI.mq4 |
//|                                                           mladen |
//+------------------------------------------------------------------+
#property copyright   "mladen"
#property link        ""
#define indicatorName "All CCI"
//----
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1  Gold
#property indicator_level1  -100
#property indicator_level2     0
#property indicator_level3   100
#property indicator_levelcolor DimGray
//---- input parameters
extern int    CCIperiod           =14;
extern int    AppliedPrice        =5;
extern bool   showHigherTimeframes=true;
extern int    barsPerTimeFrame    =35;
extern bool   shiftRight          =False;
extern color  txtColor            =Silver;
extern color  separatorColor      =DimGray;
//---- buffers
double ExtMapBuffer1[];
//----
string shortName;
string labelsShort[] ={"M1","M5","M15","M30","H1","H4","D1"};
string labelsLong[]  ={"M15","M30","H1","H4","D1","W1","MN1"};
string labels[];
int    periodsShort[]={PERIOD_M1,PERIOD_M5,PERIOD_M15,PERIOD_M30,PERIOD_H1,PERIOD_H4,PERIOD_D1};
int    periodsLong[] ={PERIOD_M15,PERIOD_M30,PERIOD_H1,PERIOD_H4,PERIOD_D1,PERIOD_W1,PERIOD_MN1};
int    periods[];
int    Shift;
double minValue;
double maxValue;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   if (shiftRight) Shift=1;
   else            Shift=0;
   //----
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexShift(0,Shift*(barsPerTimeFrame+1));
   SetIndexLabel(0,"CCI");
   //----
   barsPerTimeFrame   =MathMax(barsPerTimeFrame,30);
   shortName=indicatorName+" ("+CCIperiod+")";
   IndicatorShortName(shortName);
     if (showHigherTimeframes) 
     {
      ArrayCopy(labels,labelsLong);
      ArrayCopy(periods,periodsLong);
     }
     else  
     {
      ArrayCopy(labels,labelsShort);
      ArrayCopy(periods,periodsShort);
     }
   //----
   for(int i=1;i<7;i++)
      if (Period()==periods[i])
        {
         string tmpLbl=labels[i];
         int    tmpPer=periods[i];
         //----
         for(int k=i ;k>0; k--)
           {
            labels[k] =labels[k-1];
            periods[k]=periods[k-1];
           }
         labels[0] =tmpLbl;
         periods[0]=tmpPer;
        }
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   for(int l=0;l<7;l++)
     {
      ObjectDelete(indicatorName+l);
      ObjectDelete(indicatorName+l+1);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   string on;
   int    wn=WindowFind(shortName);
   int    k=0;
   //----
   minValue= 999999;
   maxValue=-999999;
   for(int p=0; p<7;p++)
     {
      for(int i=0; i<barsPerTimeFrame;i++,k++)
        {
         ExtMapBuffer1[k]=iCCI(NULL,periods[p],CCIperiod,AppliedPrice,i);
         checkMinMax(k);
        }
      ExtMapBuffer1[k]=EMPTY_VALUE; k+=1;
      //----
      on=indicatorName+p;
      if(ObjectFind(on)==-1)
         ObjectCreate(on,OBJ_TREND,wn,0,0);
      ObjectSet(on,OBJPROP_TIME1,myTime(k-Shift*(barsPerTimeFrame+1)-1));
      ObjectSet(on,OBJPROP_TIME2,myTime(k-Shift*(barsPerTimeFrame+1)-1));
      ObjectSet(on,OBJPROP_PRICE1,  0);
      ObjectSet(on,OBJPROP_PRICE2,100);
      ObjectSet(on,OBJPROP_COLOR ,separatorColor);
      ObjectSet(on,OBJPROP_WIDTH ,2);
      on=indicatorName+p+1;
      if(ObjectFind(on)==-1)
         ObjectCreate(on,OBJ_TEXT,wn,0,0);
      ObjectSet(on,OBJPROP_TIME1,myTime(k-(Shift*barsPerTimeFrame)-6));
      ObjectSetText(on,labels[p],9,"Arial",txtColor);
     }
   //----
   for(p=0; p<7;p++)
     {
      on=indicatorName+p;
      ObjectSet(on,OBJPROP_PRICE1,minValue*1.05);
      ObjectSet(on,OBJPROP_PRICE2,maxValue);
      on=indicatorName+p+1;
      ObjectSet(on,OBJPROP_PRICE1,maxValue);
     }
   //----
   SetIndexDrawBegin(0,Bars-k);
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom functions and procedures                                  |
//+------------------------------------------------------------------+
void checkMinMax(int shift)
  {
   minValue=MathMin(ExtMapBuffer1[shift],minValue);
   maxValue=MathMax(ExtMapBuffer1[shift],maxValue);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int myTime(int a)
  {
   if(a<0)
      return(Time[0]+Period()*60*MathAbs(a));
   else  return(Time[a]);
  }
//+------------------------------------------------------------------+

Comments