//+------------------------------------------------------------------+ //| CHV.mq5 | //| Copyright 2000-2025, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2000-2025, MetaQuotes Ltd." #property link "https://www.mql5.com" #property description "Chaikin Volatility" #include //--- indicator settings #property indicator_separate_window #property indicator_buffers 3 #property indicator_plots 1 #property indicator_type1 DRAW_LINE #property indicator_color1 clrDodgerBlue //--- enum enum SmoothMethod { SMA=0,// Simple MA EMA=1 // Exponential MA }; //--- input parameters input int InpSmoothPeriod=10; // Smoothing period input int InpCHVPeriod=10; // CHV period input SmoothMethod InpSmoothType=EMA; // Smoothing method //--- indicator buffers double ExtCHVBuffer[]; double ExtHLBuffer[]; double ExtSHLBuffer[]; int ExtSmoothPeriod,ExtCHVPeriod; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { string ma_name=EnumToString(InpSmoothType); //--- check inputs if(InpSmoothPeriod<=0) { ExtSmoothPeriod=10; PrintFormat("Incorrect value for input variable InpSmoothPeriod=%d. Indicator will use value=%d for calculations.",InpSmoothPeriod,ExtSmoothPeriod); } else ExtSmoothPeriod=InpSmoothPeriod; if(InpCHVPeriod<=0) { ExtCHVPeriod=10; PrintFormat("Incorrect value for input variable InpCHVPeriod=%d. Indicator will use value=%d for calculations.",InpCHVPeriod,ExtCHVPeriod); } else ExtCHVPeriod=InpCHVPeriod; //--- define buffers SetIndexBuffer(0,ExtCHVBuffer); SetIndexBuffer(1,ExtHLBuffer,INDICATOR_CALCULATIONS); SetIndexBuffer(2,ExtSHLBuffer,INDICATOR_CALCULATIONS); //--- set draw begin PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtSmoothPeriod+ExtCHVPeriod-1); //--- set name and index label string params=StringFormat("(%d,%s)",ExtSmoothPeriod,ma_name); IndicatorSetString(INDICATOR_SHORTNAME,"Chaikin Volatility"+params); PlotIndexSetString(0,PLOT_LABEL,"CHV"+params); //--- round settings IndicatorSetInteger(INDICATOR_DIGITS,1); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, 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[]) { int i,pos,pos_chv; //--- check for rates total pos_chv=ExtCHVPeriod+ExtSmoothPeriod-2; if(rates_total