do i need to code/include MA indicator?

 

i'm using this iMA docs and this smoothing  on MT5 code as reference to add a simple MA 5:

double MA_5simple = iMA(Symbol(),PERIOD_H4,5,0,MODE_SMA,PRICE_CLOSE);

but turns out the output is 10.0 and somehow this iMA is using int instead of double. i look for how to add MA, according this codebase and forum, i need to create/include MA code. 

so my question is, how to add MA into my code? do i really need to do extra step instead of that simple code above (like mql4 do)? thanks

Documentation on MQL5: Technical Indicators / iMA
Documentation on MQL5: Technical Indicators / iMA
  • www.mql5.com
iMA - Technical Indicators - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

This is how you access value of specific index of indicator in MQL5:

double MA(int index)
{
   int MA_handle = iMA(Symbol(),PERIOD_H4,5,0,MODE_SMA,PRICE_CLOSE);
   double value[];
   ArraySetAsSeries(value, true);
   if(CopyBuffer(MA_handle, 0, index, 1, value)<=0)
   {  
      Print("Problem reading indicator value!", GetLastError());
      return 0;
   }
   return value[0];
}

note: It is best to initiate indicator handle once in OnInit.

 
Yashar Seyyedin #:

This is how you access value of specific index of indicator in MQL5:

note: It is best to initiate indicator handle once in OnInit.

thank you so much. i also found the docs about it. i'll learn more later

Documentation on MQL5: Timeseries and Indicators Access / CopyBuffer
Documentation on MQL5: Timeseries and Indicators Access / CopyBuffer
  • www.mql5.com
CopyBuffer - Timeseries and Indicators Access - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Reason: