How to correct use of inbuild CIndicator class for example CiDEMA

 

Hello, I would like to find out how to use correctly the inbuild CIndicator class for example the CiDEMA included in MQL5.

I have some example code but the CiDEMA doesn't seem to give back the right value. Can someone please check the code?

/*
   CiDEMA versus CiDEMA.mq5
*/
#include <Indicators\Indicators.mqh>
CiDEMA *DEMA;

// Input variables for indicator
string                    inp_symbol         = NULL;           // symbol name 
input ENUM_TIMEFRAMES     inp_period         = PERIOD_CURRENT; // period 
input int                 inp_ma_period      = 14;             // averaging period 
input int                 inp_ma_shift       = 0;              // horizontal shift 
input ENUM_APPLIED_PRICE  inp_applied_price  = PRICE_CLOSE;    // type of price or handle 

// Variables for indicator handle
int                       indicator_handle;                    // indicator handle 
int                       inp_buffer_num     = 0;              // indicator buffer number 
int                       inp_start_pos      = 0;              // start position 
int                       inp_count          = 3;              // data count to copy 
double                    inp_buffer[];                            // target array to copy 

// Expert initialization function
int OnInit() {

   DEMA = new CiDEMA();
   DEMA.Create(inp_symbol, inp_period, inp_ma_period, inp_ma_shift, inp_applied_price);

   indicator_handle = iDEMA(inp_symbol, inp_period, inp_ma_period, inp_ma_shift, inp_applied_price);
   
   ArraySetAsSeries(inp_buffer, true);
   
   return(INIT_SUCCEEDED);

}

// Expert deinitialization function
void OnDeinit(const int reason) {
   
   IndicatorRelease(indicator_handle);
   
}

// Expert tick function
void OnTick() {

   CopyBuffer(indicator_handle, inp_buffer_num, inp_start_pos, inp_count, inp_buffer);
   
   double value_idema = NormalizeDouble(inp_buffer[1], _Digits);
   double value_cidema = NormalizeDouble(DEMA.Main(1), _Digits);
   
   Comment("Value of iDEMA: ", value_idema, "\n",
           "Value of CiDEMA: ", value_cidema);
            
}
 
How to start with MQL5
How to start with MQL5
  • 2021.12.30
  • www.mql5.com
This thread discusses MQL5 code examples. There will be examples of how to get data from indicators, how to program advisors...
 
Vladimir Karputov #:

Working with the CiDEMA class

Thank you so much :) I added the Refresh() function and it works perfect.