Issues with indicator Buffers - Help Needed!

 

The mt5 indicator below (MA_Of_CCI) appears to have two buffers but when used for an EA code, these buffers do not return any values. They are empty almost all time during test and this is the problem.

Please take a look at the Code below and assist; thanks!

//+------------------------------------------------------------------+
//|                                                    MA_Of_CCI.mq5 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                                 https://mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://mql5.com"
#property version   "1.00"
#property description "MA of CCI oscillator"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots   2
//--- plot CCI
#property indicator_label1  "CCI"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrBlue
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot MA
#property indicator_label2  "MA"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrFireBrick
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//--- input parameters
input uint                 InpPeriodCCI      =  14;            // CCI period
input ENUM_APPLIED_PRICE   InpAppliedPrice   =  PRICE_CLOSE;   // CCI applied price
input uint                 InpPeriodMA       =  20;            // MA period
input ENUM_MA_METHOD       InpMethod         =  MODE_SMA;      // MA method
//--- indicator buffers
double         BufferCCI[];
double         BufferMA[];
//--- global variables
int            period_cci;
int            period_ma;
int            period_max;
int            handle_cci;
int            weight_sum;
//--- includes
#include <MovingAverages.mqh>
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- set global variables
   period_cci=int(InpPeriodCCI<1 ? 1 : InpPeriodCCI);
   period_ma=int(InpPeriodMA<2 ? 2 : InpPeriodMA);
   period_max=fmax(period_cci,period_ma);
//--- indicator buffers mapping
   SetIndexBuffer(0,BufferCCI,INDICATOR_DATA);
   SetIndexBuffer(1,BufferMA,INDICATOR_DATA);
//--- setting indicator parameters
   IndicatorSetString(INDICATOR_SHORTNAME,"MA of CCI ("+(string)period_cci+","+(string)period_ma+")");
   IndicatorSetInteger(INDICATOR_DIGITS,Digits());
//--- setting buffer arrays as timeseries
   ArraySetAsSeries(BufferCCI,true);
   ArraySetAsSeries(BufferMA,true);
//--- create cci handle
   ResetLastError();
   handle_cci=iCCI(NULL,PERIOD_CURRENT,period_cci,InpAppliedPrice);
   if(handle_cci==INVALID_HANDLE)
     {
      Print("The iCCI(",(string)period_cci,") object was not created: Error ",GetLastError());
      return INIT_FAILED;
     }
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| 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[])
  {
//--- Проверка и расчёт количества просчитываемых баров
   if(rates_total<fmax(period_max,4)) return 0;
//--- Проверка и расчёт количества просчитываемых баров
   int limit=rates_total-prev_calculated;
   if(limit>1)
     {
      limit=rates_total-1;
      ArrayInitialize(BufferCCI,EMPTY_VALUE);
      ArrayInitialize(BufferMA,EMPTY_VALUE);
     }

//--- Подготовка данных
   int count=(limit>1 ? rates_total : 1);
   ResetLastError();
   int copied=CopyBuffer(handle_cci,0,0,count,BufferCCI);
    //
   if(copied!=count) return 0;
   
//--- Расчёт индикатора
   switch(InpMethod)
     {
      case MODE_EMA  :  return ExponentialMAOnBuffer(rates_total,prev_calculated,period_cci,period_ma,BufferCCI,BufferMA);
      case MODE_SMMA :  return SmoothedMAOnBuffer(rates_total,prev_calculated,period_cci,period_ma,BufferCCI,BufferMA);
      case MODE_LWMA :  return LinearWeightedMAOnBuffer(rates_total,prev_calculated,period_cci,period_ma,BufferCCI,BufferMA,weight_sum);
      //---MODE_SMA
      default        :  return SimpleMAOnBuffer(rates_total,prev_calculated,period_cci,period_ma,BufferCCI,BufferMA);
     }
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • 2023.06.16
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
 
Your topic has been moved to the section: Technical Indicators — In the future, please consider which section is most appropriate for your query.
 
Please clarify how you code to access buffer values.
 
Yashar Seyyedin #: Please clarify how you code to access buffer values.

Hello Yashar, thanks for your reply. Below is the code I used to call the "MA_Of_CCI" indicator. Kindly verify to see if am doing something wrong ...

//+------------------------------------------------------------------+
//|                                                CC_Call.mq5       |
//|                                                Fxheadmaster      |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Fxheadmaster"
#property link         "Tsoene"
#property version    "1.00"
//
input int                CCI_period               = 21;
input ENUM_APPLIED_PRICE Applied_Price            = PRICE_CLOSE;
input int                CCI_MA_period            = 21;
input ENUM_MA_METHOD     MA_type                  = MODE_SMA;

//
int CC_Handle;
double CCI_Val,MA_Val;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
     CC_Handle=iCustom(Symbol(),PERIOD_CURRENT,"Examples\\MA_OF_CCI",CCI_period,CCI_MA_period,MA_type,Applied_Price);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   Comment("");
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
    if(IsNewCandle())
    {
    
      CCI_Val=CC1(0,1);     //buffer 0
      MA_Val =CC1(1,1);     //buffer 1
      //---------
      
      Comment(
              "CCCI Val            ",DoubleToString(CCI_Val,Digits())
              +"\nMA Val               ",DoubleToString(MA_Val,Digits())
             );
             
    } //cand funct end
  
  }
//+-----------------------------end----------------------------------+

bool IsNewCandle()
{
 static int ChartBars=0;
 int BarsOnChart = iBars(_Symbol,PERIOD_CURRENT); 
 //
 if(ChartBars==BarsOnChart)
  {
   return(false);
  }
  //
  ChartBars=BarsOnChart;
  return(true);
}
//-----------------------------------------------------------------/
double CC1(int buff,int shift)
 {
   double arr[];
   ArraySetAsSeries(arr,true);
   CopyBuffer(CC_Handle,buff,0,Bars(_Symbol,0),arr);
  //
   return(arr[shift]);
 }
//-----------------------------------------------------------------/

 
Hello community, can someone please look at my issue and assist me?