Author: Copyright © 2007, MetaQuotes Software Corp.

The provided script is a custom technical analysis indicator designed for the MetaTrader 5 platform. Its primary purpose is to calculate and visualize a specific type of "smoothed" price movement by comparing two different moving averages derived from market volume.

Core Logic Overview

The indicator functions by processing Accumulated Delta (AD)—a data point that typically represents the difference between buying and selling pressure based on volume. Rather than looking at raw price alone, it uses this volume-based data as the foundation for its calculations.

The script operates through three main logic stages:

1. Data Input and Configuration

  • Smoothing Methods: The user can choose from various mathematical models to smooth the data (such as SMA, EMA, LWMA, JJMA, etc.).
  • Dual Period Analysis: It establishes two distinct timeframes: a Fast Period (short-term movement) and a Slow Period (long-term trend).
  • Phase Parameter: A smoothing coefficient is applied to adjust the sensitivity of the curves.

2. Calculation Process The script performs a continuous "dual-engine" calculation on every price tick:

  • Fast Curve: It calculates a moving average based on the Fast Period. This represents the immediate, rapid fluctuations in volume momentum.
  • Slow Curve: Simultaneously, it calculates a moving average based on the Slow Period. This represents the broader, underlying trend of the volume momentum.
  • The Difference (CHO): The final value displayed on the chart is the mathematical difference between these two curves (Fast - Slow).

3. Visual Representation

  • Separate Window: Instead of drawing directly on the price candles, the indicator creates its own sub-window at the bottom of the chart.
  • The Line: The result is plotted as a continuous solid line (colored Dark Turquoise). This line helps traders identify where momentum is shifting; for example, when the fast movement significantly deviates from the slow trend, it indicates a potential surge or exhaustion in market activity.

Summary for the User

In simple terms, this tool ignores "noise" by smoothing out raw volume data into two different speeds. By subtracting the slow speed from the fast speed, it creates a unique momentum oscillator (labeled "CHO"). When the line moves up, it suggests that short-term buying/selling pressure is accelerating faster than the long-term average; when it moves down, it suggests a relative deceleration or shift in pressure.

Indicators Used
Accumulation/Distribution indicator
11 Views
0 Downloads
0 Favorites
cho_v3
ÿþ//+---------------------------------------------------------------------+

//|                                                             CHO.mq5 |

//|                         Copyright © 2007, MetaQuotes Software Corp. |

//|                                           http://www.metaquotes.net |

//+---------------------------------------------------------------------+ 

//| Place the SmoothAlgorithms.mqh file                                 |

//| in the directory: terminal_data_folder\MQL5\Include                 |

//+---------------------------------------------------------------------+

#property copyright "Copyright © 2007, MetaQuotes Software Corp."

#property link      "http://www.metaquotes.net"

//--- indicator version

#property version   "1.00"

//--- drawing the indicator in a separate window

#property indicator_separate_window 

//--- number of indicator buffers is 1

#property indicator_buffers 1 

//--- one plot is used

#property indicator_plots   1

//+-----------------------------------+

//|  Indicator drawing parameters     |

//+-----------------------------------+

//--- drawing the indicator as a line

#property indicator_type1   DRAW_LINE

//--- DarkTurquoise is used as the color of the indicator line

#property indicator_color1 clrDarkTurquoise

//--- the indicator line is a continuous curve

#property indicator_style1  STYLE_SOLID

//--- indicator line width is 1

#property indicator_width1  1

//--- displaying the indicator label

#property indicator_label1  "CHO"

//+-----------------------------------+

//| ?8A0=85 :;0AA0 CXMA              |

//+-----------------------------------+

#include <SmoothAlgorithms.mqh> 

//+-----------------------------------+

//--- declaration of the CXMA class variables from the SmoothAlgorithms.mqh file

CXMA XMA1,XMA2;

//+-----------------------------------+

//| declaration of enumerations       |

//+-----------------------------------+

/*enum Smooth_Method - enumeration is declared in SmoothAlgorithms.mqh

  {

   MODE_SMA_,  // SMA

   MODE_EMA_,  // EMA

   MODE_SMMA_, // SMMA

   MODE_LWMA_, // LWMA

   MODE_JJMA,  // JJMA

   MODE_JurX,  // JurX

   MODE_ParMA, // ParMA

   MODE_T3,    // T3

   MODE_VIDYA, // VIDYA

   MODE_AMA,   // AMA

  }; */

//+-----------------------------------+

//| declaration of constants          |

//+-----------------------------------+

#define RESET 0 // The constant for returning the indicator recalculation command to the terminal

//+-----------------------------------+

//| Indicator input parameters        |

//+-----------------------------------+

input Smooth_Method XMA_Method=MODE_SMA;          // Method of averaging

input uint FastPeriod=3;                          // Period of fast averaging

input uint SlowPeriod=10;                         // Period of slow averaging

input int XPhase=15;                              // Smoothing parameter

//--- for JJMA it varies within the range -100 ... +100 and influences the quality of the transient period;

input ENUM_APPLIED_VOLUME VolumeType=VOLUME_TICK; // Volume 

//+-----------------------------------+

//--- declaration of dynamic arrays that

//--- will be used as indicator buffers

double ExtBuffer[];

//--- declaration of integer variables for storing indicator handles

int Ind_Handle;

//--- declaration of integer variables of data starting point

int  min_rates_,min_rates_total;

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit()

  {

//--- initialization of variables of the start of data calculation

   min_rates_=2;

   int min_rates_1=XMA1.GetStartBars(XMA_Method,FastPeriod,XPhase);

   int min_rates_2=XMA1.GetStartBars(XMA_Method,SlowPeriod,XPhase);

   min_rates_total=min_rates_+int(MathMax(min_rates_1,min_rates_2));

//--- ?>;CG5=85 E5=4;0 8=48:0B>@0 iAD

   Ind_Handle=iAD(Symbol(),PERIOD_CURRENT,VolumeType);

   if(Ind_Handle==INVALID_HANDLE)

     {

      Print(" Failed to get the handle of the iAD indicator");

      return(INIT_FAILED);

     }

//--- set dynamic array as an indicator buffer

   SetIndexBuffer(0,ExtBuffer,INDICATOR_DATA);

//--- indexing elements in the buffer as in timeseries

   ArraySetAsSeries(ExtBuffer,true);

//--- shift the beginning of indicator drawing

   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);

//--- setting the indicator values that won't be visible on a chart

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);

//--- creation of the name to be displayed in a separate sub-window and in a pop up help

   IndicatorSetString(INDICATOR_SHORTNAME,"CHO");

//--- determining the accuracy of the indicator values

   IndicatorSetInteger(INDICATOR_DIGITS,0);

//--- initialization end

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+  

//| Custom indicator iteration function                              | 

//+------------------------------------------------------------------+  

int OnCalculate(const int rates_total,    // number of bars in history at the current tick

                const int prev_calculated,// amount of history in bars at the previous tick

                const datetime &time[],

                const double &open[],

                const double &high[],

                const double &low[],

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[])

  {

//--- checking if the number of bars is enough for the calculation

   if(rates_total<min_rates_total || BarsCalculated(Ind_Handle)<rates_total) return(RESET);

//--- declarations of local variables 

   int to_copy,limit,bar,maxbar;

//--- declaration of variables with a floating point  

   double AD[],Fast,Slow;

//--- apply timeseries indexing to array elements  

   ArraySetAsSeries(AD,true);

//---   

   maxbar=rates_total-min_rates_-1;

//--- Calculating the required amount of data to copy

//--- the starting number limit for the bar recalculation loop

   if(prev_calculated>rates_total || prev_calculated<=0)// checking for the first start of calculation of an indicator

     {

      limit=maxbar;  // starting index for the calculation of all bars

     }

   else limit=rates_total-prev_calculated; // starting index for the calculation of new bars

//---   

   to_copy=limit+1;

//--- copy newly appeared data in the arrays

   if(CopyBuffer(Ind_Handle,0,0,to_copy,AD)<=0) return(RESET);

//--- the first indicator calculation loop

   for(bar=limit; bar>=0 && !IsStopped(); bar--)

     {     

      Fast=XMA1.XMASeries(maxbar,prev_calculated,rates_total,XMA_Method,XPhase,FastPeriod,AD[bar],bar,true);

      Slow=XMA2.XMASeries(maxbar,prev_calculated,rates_total,XMA_Method,XPhase,SlowPeriod,AD[bar],bar,true);

      ExtBuffer[bar]=Fast-Slow;

     }

//---    

   return(rates_total);

  }

//+------------------------------------------------------------------+

Comments