Overview
This tool is a custom technical analysis indicator designed to provide traders with a visual representation of market momentum combined with long-term price trends. By merging two distinct types of market data—momentum and moving averages—it helps identify where current price velocity sits in relation to the prevailing trend.
How the Logic Works
The indicator operates by calculating and blending two primary components:
1. The Momentum Component (CCI) The script utilizes the Commodity Channel Index (CCI), which measures how far the current price is deviating from its statistical average. In simple terms, it tells you if an asset is overbought, oversold, or moving with significant strength.
2. The Trend Component (Moving Average) Simultaneously, the script calculates a Moving Average (MA). This represents the "smoothed" history of the price. Depending on your settings, this can be a simple average, an exponential average, or other variations that highlight whether the overall market direction is bullish or bearish.
3. The Fusion Process The core logic lies in how these two pieces of information are combined:
- The script takes the Moving Average as a baseline value.
- It then calculates the CCI value, scales it down (using a customizable multiplier), and adds it directly to the Moving Average.
- This result is plotted as a single line on your chart.
What This Means for Trading
Instead of looking at two separate lines that might cross each other and cause confusion, this script provides a unified "trend-momentum" line:
- Trend Context: Because the Moving Average is the foundation of the calculation, the primary direction of the line reflects the general trend of the market.
- Momentum Overlay: The "wiggles" or fluctuations in the line are influenced by the CCI. When momentum is high in the direction of the trend, the line reacts accordingly; when momentum slows down or reverses, the line adjusts to show that shift.
- Visual Clarity: This allows a trader to see at a glance whether the current price movement has enough "fuel" (momentum) to continue the established trend or if the move is losing steam.
Customization Options
The script provides several flexible settings to tailor the logic to different trading styles:
- Period Settings: You can adjust how far back the tool looks for both momentum and trend data (e.g., looking at the last 14 candles vs. 50).
- Price Source: You can choose which price data the tool calculates from (such as the High, Low, or Closing price).
- Sensitivity Multiplier: This allows you to control how much influence the momentum component has on the final line. A higher multiplier makes the line more sensitive to quick price swings, while a lower multiplier keeps the line smoother and more focused on the long-term trend.
//+------------------------------------------------------------------+
//| 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