Calling iMA() in a custom indicator

 

Hi!

I'm trying to call iMA in OnCalculate of a custom indicator:

for (int i = start; i < rates_total; i++)

{

double fast_MA_prev = iMA(_Symbol, _Period, prm_MA_fast_period, 0, prm_MA_calculation_mode, i-1); // where  prm_MA_fast_period=10, prm_MA_calculation_mode (ENUM_MA_METHOD) is MODE_EMA.

// calculations

//...

}

Doing so I can compile the indicator, meaning the syntax is indeed correct (it is also aligned on the web description of iMA() )

Though, when attaching the indicator to a chart, I'm receiving the (I guess classic) message: cannot load indicator "Moving Average" [4803]

Any idea?

 
  1. Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
          General rules and best pratices of the Forum. - General - MQL5 programming forum #25 (2019)
              Messages Editor
          Forum rules and recommendations - General - MQL5 programming forum (2023)

  2. double fast_MA_prev = iMA(_Symbol, _Period, prm_MA_fast_period, 0, prm_MA_calculation_mode, i-1)

    Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
    Next time, post in the correct place. The moderators will likely move this thread there soon.

  3. Thomas110: cannot load indicator “Moving Average” [4803] Any idea?

    Your posted code is without context. Are those lines together, in OnCalculate? Always post all relevant code (using Code button) or attach the source file. If your file actually called “Moving Average.mq4” with the space?File (Alt+F) → Open Data Folder (D) and verify you put it in the correct location (“MQL4\Experts” folder)? Did you compile it?

  4. There is no error 4803 in MT4. Which terminal are you using?
 
William Roeder #:


Hi William,

(1) thanks for the feedback, will do it next time.

(2) it was actually supposed to be a MT5 code: but your question made me realize the issue. Apparently the indicator returns values directly in MT4, whereas it returns the handle in MT5 (handle to declare in start of program, to initialize in OnInit) and CopyBuffer is required in OnCalculate().

(3) adjusting (2) could fix the error I had; now MT can find the iMA indicator as it is properly used/its parameters are well defined.

Thanks for the help!