CCI_onMA_MAs_v1
Download scriptThis specialized trading tool is designed to provide visual clarity by combining two popular market analysis metrics: the Commodity Channel Index (CCI) and the Moving Average (MA). Instead of looking at these indicators in isolation, the script merges their data points to help traders identify price trends and momentum shifts more intuitively on a single chart.
How the Logic Works
The core functionality of this tool relies on a mathematical "overlay" approach. Here is a breakdown of the logic used to generate the visual data:
1. Trend Foundation (Moving Average) The script first calculates a standard Moving Average based on your preferred timeframe and price type (such as Close, High, Low, or Median prices). This acts as the "baseline" for the indicator, representing the general direction of the market over a specific period.
2. Momentum Adjustment (CCI Integration) The tool then pulls data from the Commodity Channel Index, which is typically used to measure the deviation of price from its average. Rather than just showing this as a separate line at the bottom of your screen, the script scales this momentum value down using a multiplier and adds it directly onto the Moving Average.
3. Dynamic Visual Outputs By combining these two values, the script produces several unique visual layers:
- Combined CCI on MA: A primary line that shows the Moving Average "shifted" by the current momentum. This allows you to see if the price is pushing harder than the average trend would normally suggest.
- Price-Specific Variations: The logic also calculates specific versions of Moving Averages based on "Typical" prices (a mix of High, Low, and Close) and standard "Close" prices.
- CCI on Close: An additional calculation that adds the momentum data directly to the current closing price, providing a secondary way to view how much the market is over-extending at any given moment.
Key Benefits for the User
- Reduced Clutter: By merging two indicators into one visual line, it clears up screen space while still providing all the necessary information from both tools.
- Early Warning Signals: Because the CCI momentum is added to the Moving Average, the line may "curve" or "stretch" ahead of the actual price action, potentially signaling a shift in strength before it becomes obvious on a standard chart.
- Customizable Sensitivity: Users can adjust the multiplier and periods to make the indicator more sensitive to small price fluctuations or smoother for long-term trend analysis.
//+------------------------------------------------------------------+
//| CCI_onMA.mq4 |
//| CCI on MA +MAs http://www.metaquotes.net |
//+------------------------------------------------------------------+
//2008forextsd ki
#property copyright "http://www.forex-tsd.com/"
#property link ""
//----
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_color1 Red
#property indicator_color2 Purple
#property indicator_color3 DodgerBlue
#property indicator_color4 Yellow
#property indicator_color5 Green
//----
#property indicator_width1 2
#property indicator_width2 1
#property indicator_width3 1
#property indicator_width4 1
#property indicator_style4 2
//----
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 ShowMa1Typical =true;
extern bool ShowMa1Close =true;
extern bool ShowCCIonClose =true;
//----
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[];
double MA1typBuffer[];
double MA1closeBuffer[];
double CCIonCloseBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//|------------------------------------------------------------------|
int init()
{
//----
IndicatorBuffers(5);
{
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);
SetIndexStyle(2,DRAW_NONE); if (ShowMa1Typical) SetIndexStyle(2,DRAW_LINE);
SetIndexStyle(3,DRAW_NONE); if (ShowMa1Close) SetIndexStyle(3,DRAW_LINE);
SetIndexStyle(4,DRAW_NONE); if (ShowCCIonClose) SetIndexStyle(4,DRAW_LINE);
}
//----
SetIndexBuffer(0, CCIonMABuffer);
SetIndexBuffer(1, MA_Buffer);
SetIndexBuffer(2, MA1typBuffer);
SetIndexBuffer(3, MA1closeBuffer);
SetIndexBuffer(4, CCIonCloseBuffer);
//----
SetIndexLabel(0,"CCIonMA CCI:per("+CCI_Period+")price "+CCI_Price+" MA per("+MaPeriod+")");
SetIndexLabel(1,"MA per("+MaPeriod+") method "+MaMetod+"; price "+MaPrice+"");
SetIndexLabel(2,"MA Per1 priceTypical");
SetIndexLabel(3,"MA Per1 priceClose");
SetIndexLabel(4,"CCIon iclose");
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];
//----
MA1typBuffer [i]=iMA(NULL,0,1,0,0,5,i);
MA1closeBuffer [i]=iMA(NULL,0,1,0,0,0,i);
CCIonCloseBuffer [i]=Close[i]+ CCI_val*CCI_multiplier*Point;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments