CCI_onMA_v1

Download script
CCI_onMA_v1

This technical indicator is designed to provide traders with a unique visual representation of market momentum by merging two distinct types of financial analysis: the Commodity Channel Index (CCI) and a Moving Average (MA).

Instead of viewing these two tools separately on your chart, this script combines them into a single, unified line. This allows you to observe how momentum is interacting with the overall price trend in real-time, helping to identify potential price movements more clearly.

How the Logic Works

The indicator functions by calculating three primary components simultaneously:

1. The Moving Average (Baseline) First, the script calculates a standard Moving Average based on your chosen settings (such as the period length and the specific smoothing method). This serves as the "foundation" of the indicator, representing the smooth path of the asset's price over time.

2. The Commodity Channel Index (Momentum) Next, the script measures the CCI. This is a momentum oscillator that identifies whether an asset is overbought, oversold, or in a period of high volatility relative to its average price.

3. The Combined Calculation The core logic of this tool lies in how it joins these two pieces of information. Rather than simply overlaying one line on top of the other, the script takes the CCI value and multiplies it by a specific factor (a multiplier). It then adds this modified momentum value to the Moving Average.

What This Means for the User

Because the CCI is "attached" to the Moving Average, the resulting line moves with the general trend of the market but reacts dynamically to price momentum:

  • Trend Following: The line will generally follow the direction of the Moving Average, showing you the primary market direction.
  • Momentum Sensitivity: Because the CCI is included in the calculation, the line will "swing" or deviate based on current momentum. If the momentum is strong, the line will pull further away from the average; if momentum weakens, the line will flatten toward the average.
  • Visual Clarity: By merging these two metrics into one line, it eliminates visual clutter, allowing you to see both the "big picture" trend and the "short-term" momentum in a single, cohesive motion.
Indicators Used
Commodity channel indexMoving average indicator
Miscellaneous
Implements a curve of type %1
10 Views
0 Downloads
0 Favorites
CCI_onMA_v1
//+------------------------------------------------------------------+
//|                                                     CCI_onMA.mq4 |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
//2008forextsd   ki
#property copyright "http://www.forex-tsd.com/"
#property link    ""
#property indicator_chart_window
//----
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 DodgerBlue
#property indicator_width1 2
#property indicator_width2 1
//---- 
extern int CCI_Period  =14;
extern int CCI_Price   =5;
extern double CCI_multiplier=0.3;
//----
extern int MaPeriod    =14;
extern int MaMetod     =0;
extern int MaPrice     =5;
//----
extern string   note_Price="0C 1O 2H 3L4Md 5Tp 6WghC: Md(HL/2)4,Tp(HLC/3)5,Wgh(HLCC/4)6";
extern string   MA_Method_="SMA0 EMA1 SMMA2 LWMA3";
//---- 
double CCIonMABuffer[];
double MA_Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//|------------------------------------------------------------------|
int init()
  {
//---- 
   IndicatorBuffers(2);
   SetIndexBuffer(0, CCIonMABuffer);
   SetIndexBuffer(1, MA_Buffer);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
//----    
   SetIndexLabel(0,"CCIonMA CCI:("+CCI_Period+"|"+CCI_Price+")("+MaPeriod+")");
   SetIndexLabel(1,"MA ("+MaPeriod+")"+MaMetod+","+MaPrice+"");
   IndicatorShortName("CCIonMA "+CCI_Period+";"+MaPeriod+"");
//----
   for(int i=0;i<indicator_buffers;i++)
      SetIndexDrawBegin(i,MathMax (MaPeriod,CCI_Period));
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    i,limit,    CountedBars=IndicatorCounted();
   if (CountedBars<0) return(-1);
   if (CountedBars>0) CountedBars--;
//----
   limit= Bars-CountedBars;
   limit= MathMax(limit,CCI_Period);
   limit= MathMax(limit,MaPeriod);
//----
   for(i=limit;i>=0;i--)
     {
      double     CCI_val =iCCI(NULL,0,CCI_Period,CCI_Price,i);
      MA_Buffer      [i] =iMA(NULL,0,MaPeriod,0,MaMetod,MaPrice,i);
      CCIonMABuffer  [i] =CCI_val*CCI_multiplier*Point+ MA_Buffer[i];
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments