CCI_onMA_sigMA
Download scriptThis script is a custom technical analysis tool designed for the MetaTrader platform to help traders visualize market trends by combining three distinct types of moving averages into a single cohesive display. Instead of looking at these indicators in isolation, the script blends them to provide a smoother, more filtered perspective on price action.
Core Logic Overview
The tool operates through a three-layer calculation process:
1. The Base Components The script starts by pulling two primary pieces of market data:
- Commodity Channel Index (CCI): A momentum indicator that measures how far the current price is deviating from its statistical average.
- Simple Moving Average (MA): A standard tool used to smooth out price fluctuations to identify the general direction of the trend.
2. The Hybrid Calculation (CCI on MA) Unlike standard indicators that simply plot these values side-by-side, this script performs a mathematical fusion. It takes the CCI value, scales it down using a specific multiplier, and then adds it directly to the Moving Average.
- The Result: This creates a "modified" moving average. By adding the momentum (CCI) to the trend line (MA), the indicator reacts more intelligently to price shifts while maintaining the stability of a moving average.
3. The Signal Smoothing (SigMA) To further refine the data, the script applies a third layer of analysis. It takes the "Hybrid" result from the previous step and runs it through yet another moving average calculation.
- The Result: This acts as a secondary filter (often used as a "signal" line). It smooths out the noise from the hybrid line, making it easier for traders to spot significant trend reversals or sustained momentum shifts without being distracted by minor price "jitters."
Visual Behavior and Customization
The script is designed to be highly flexible, allowing users to toggle different components on or off:
- Trend Visibility: You can choose to display the primary hybrid line, the base Moving Average, and/or the smoothed Signal line independently.
- Sensitivity Adjustments: Users can modify the periods (the amount of historical data looked at) and the "Method" (how the averages are calculated, such as Simple vs. Exponential) to suit different trading styles, from fast-paced scalping to long-term trend following.
In summary, this tool transforms raw price data into a multi-layered trend system that balances momentum (speed) with smoothing (stability), providing a clearer picture of where the market is heading.
//+------------------------------------------------------------------+
//| 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 3
#property indicator_color1 Red
#property indicator_color2 RoyalBlue
#property indicator_color3 Orange
#property indicator_width1 2
#property indicator_width2 1
#property indicator_width3 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 bool Show_MA = true;
extern int SigMaPeriod = 9;
extern int SigMaMetod = 0;
extern bool Show_SigMA = false;
//SigMaPrice close only (onArray);
extern string note_Price = "0C,1O 2H3L,4Md 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[];
double SigMA_Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//|------------------------------------------------------------------|
int init()
{
//----
IndicatorBuffers(3);
SetIndexBuffer(0, CCIonMABuffer);
SetIndexBuffer(1, MA_Buffer);
SetIndexBuffer(2, SigMA_Buffer);
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_NONE); if (Show_MA) SetIndexStyle(1,DRAW_LINE);
SetIndexStyle(2,DRAW_NONE); if (Show_SigMA) SetIndexStyle(2,DRAW_LINE);
//----
SetIndexLabel(0,"CCIonMA CCI:("+CCI_Period+"|"+CCI_Price+")");
SetIndexLabel(1,"MA ("+MaPeriod+")"+MaMetod+","+MaPrice+"");
SetIndexLabel(2,"SigMA ("+SigMaPeriod+")"+SigMaMetod+"");
IndicatorShortName("CCIonMA ("+CCI_Period+") "+MaPeriod+"|"+SigMaPeriod+"|");
int max= MathMax (MaPeriod,CCI_Period);
max= MathMax (max,SigMaPeriod);
for (int i=0;i<indicator_buffers;i++)
SetIndexDrawBegin (i,max);
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);
limit= MathMax(limit,SigMaPeriod);
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];
}
for(i=0; i<limit; i++)
{
SigMA_Buffer[i]=iMAOnArray(CCIonMABuffer,0,SigMaPeriod,0,SigMaMetod,i);
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments