VininI_CMA

The CMA indicator is a specialized technical analysis tool designed to help traders visualize price momentum and trend direction by smoothing out market noise. It operates by calculating a moving average and comparing it against the standard volatility of the market to determine whether the current price movement is significant enough to be considered a trend.

Core Logic and Methodology

The tool functions through three primary stages:

1. Moving Average and Volatility Analysis The script begins by evaluating a standard Moving Average (MA) over a user-defined period. Simultaneously, it calculates the market's volatility using Standard Deviation. This provides a baseline for "normal" price behavior, allowing the tool to distinguish between minor price fluctuations and actual market shifts.

2. The Dynamic Smoothing Mechanism Unlike a standard moving average that follows the price exactly, this script uses a unique mathematical formula to determine how much of the moving average's direction should be applied to the current line.

  • It calculates the distance between the previous value and the moving average.
  • It then compares this distance against the market volatility (the Standard Deviation).
  • If the price movement is small compared to the typical volatility, the smoothing effect is minimized. If the movement is substantial, the script adjusts the line more aggressively to follow the trend.

3. Trend Directional Signals The indicator produces a continuous line that reacts dynamically to these calculations. To make it easier for traders to read the "flow" of the market, the script identifies two specific movements:

  • Upward Momentum: When the current value of the calculated line is higher than the previous value, it signals an upward trend.
  • Downward Momentum: When the current value of the calculated line is lower than the previous value, it signals a downward trend.

Summary for Traders

By combining standard moving averages with volatility filters, this tool aims to provide a smoother, more responsive view of market trends. It helps filter out "market noise," allowing users to see whether the price is truly gaining momentum or simply oscillating within a normal range. The resulting visual output clearly highlights shifts in direction, making it easier to identify potential entry and exit points based on the smoothed trend path.

Indicators Used
Moving average indicatorStandard Deviation indicator
Miscellaneous
Implements a curve of type %1
14 Views
0 Downloads
0 Favorites
VininI_CMA
//+------------------------------------------------------------------+
//|                                                          CMA.mq4 |
//|                                                             Raff |
//|                                          just_raff1410@yahoo.com |
//+------------------------------------------------------------------+

// "Modify 2008, Victor Nicolev"
// link "vinin.ucoz.ru"
// Óáðàë âñå ÿâíûå îøèáêè, òåïåðü èíäèêòîð ìîæíî èñïîëüçîâàòü â ñîâåòíèêå
// Ïðè èñïîëüçîâàíèè â îñâåòíèêå îáðàùàòüñÿ ê íóëåâîìó áóôôåðó



#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Yellow
#property indicator_color2 Green
#property indicator_color3 Red
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2

extern int     Ma_Period = 5;
extern int     Ma_Method = 0;
extern int     Ma_Price = 0;
extern double  Koef=1.0;
//---- buffers
double CA[];
double DIR[];
double UpBuffer[];
double DnBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(0,CA);
   SetIndexBuffer(1,UpBuffer);
   SetIndexBuffer(2,DnBuffer);
   SetIndexDrawBegin(0,Ma_Period);
   SetIndexDrawBegin(1,Ma_Period);
   SetIndexDrawBegin(2,Ma_Period);
   
   IndicatorShortName("CMA("+Ma_Period+")");
   SetIndexLabel(1,"UP");
   SetIndexLabel(2,"DN");



//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {
   double K, v1, v2, MA;

   int counted_bars = IndicatorCounted(); 

   if(counted_bars < 0) return(-1); 
   if (counted_bars > 0) counted_bars--;   
   
   int i, limit;
   
   limit=Bars - counted_bars-1;
   
   for(i=limit;i>=0;i--) {
      if (CA[i+1]==0) CA[i+1]=Price(Ma_Price,i+1);
      MA=iMA(NULL,0,Ma_Period,0,Ma_Method,Ma_Price,i);
      v1=Koef*MathSqrt(iStdDev(NULL,0,Ma_Period,0,Ma_Method,Ma_Price,i));
      v2=MathSqrt(MathAbs(CA[i+1]-MA));
      if (v2<v1 || v2==0) {K=0;} else {K=1-(v1/v2);}

      CA[i]=CA[i+1]+K*(MA-CA[i+1]);
      
      DnBuffer[i] = EMPTY_VALUE;
      UpBuffer[i] = EMPTY_VALUE;
      
      if (CA[i]-CA[i+1] > 0) UpBuffer[i] = CA[i];
      if (CA[i+1]-CA[i] > 0) DnBuffer[i] = CA[i];
   }
   return(0);
}
//+------------------------------------------------------------------+

double Price(int mode, int pos){
   switch (mode) {
      case PRICE_CLOSE     : return(Close[pos]);
      case PRICE_OPEN      : return(Open[pos]);
      case PRICE_HIGH      : return(High[pos]);
      case PRICE_LOW       : return(Low[pos]);
      case PRICE_MEDIAN    : return((High[pos]+Low[pos])/2.0); 
      case PRICE_TYPICAL   : return((High[pos]+Low[pos]+Close[pos])/3.0);
      case PRICE_WEIGHTED  : return((High[pos]+Low[pos]+2.0*Close[pos])/4.0);
   }
   return(-1);
}

Comments