Calling two function using Icustom from one ex5 file

 
Hi 

I would like to ask some help with the iCustom function

I have file A so to speak and file A has these 2 indicators

     EMA13_initial = iMA(_Symbol, TimeFrame, EMAPERIOD, 0, EMAMODELT, PriceType);
     MACD_initial = iMACD(_Symbol, TimeFrame, FASTEMA, SLOWEMA, MACDESMA, PriceType1);  


In File 2 I want to call both of these using


      EMA13A_initial = iCustom(_Symbol,TimeFrame,"Elder Impulse system", TimeFrame, EMAPERIOD, 0, EMAMODELT, PriceType);

      //Print("MA_handle = ",EMA13A_initial,"  error = ",GetLastError());

      MACDA_initial = iCustom(_Symbol, TimeFrame,"Elder Impulse system", TimeFrame, FASTEMA, SLOWEMA, MACDESMA, PriceType1);


if I comment out the MACDA line all is fine 
As soon as I uncomment the MACDA line I get error "cannot load indicator 'Moving Average' [4002]"

I double check the parameters and all seems to be fine.

Anyone know if its possible to use two iCustom function to call two function in the same file (A)?


Kind regards





 
Of course it's possible, but you need to take care of several things.

First of all remember to assign indicator handles in OnInit and retreive their buffers in OnTick/OnCalculate using copy buffer. (MT5)

Then, a look on documentation will surely help you with your error code https://www.mql5.com/en/docs/constants/errorswarnings/errorcodes

You are basically passing wrong parameters type, you maybe used wrong variable types, or wrong order. Check it.
 
DGRL: Anyone know if its possible to use two iCustom function to call two function in the same file (A)?
  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. iCustom/CopyBuffer, only reads buffers. It can not call functions. If those two indicator values are not put in buffers, you can't read them from the File A.

  3. Read the indicators directly.

 
Fabio Cavalloni #:
You are basically passing wrong parameters type, you maybe used wrong variable types, or wrong order. Check it.

@Fabio Cavalloni

Thank you for the answer..

I was able to fix the issue now all is working as expected

Documentation on MQL5: Technical Indicators / iMACD
Documentation on MQL5: Technical Indicators / iMACD
  • www.mql5.com
iMACD - Technical Indicators - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
William Roeder #:
  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. iCustom/CopyBuffer, only reads buffers. It can not call functions. If those two indicator values are not put in buffers, you can't read them from the File A.

  3. Read the indicators directly.

@William Roeder


Thank you for the answer.
Ill try to remember for the next post since I cant edit it now anymore.
There is only a few min. timespan to edit post.

 
DGRL:
Hi 

I would like to ask some help with the iCustom function

I have file A so to speak and file A has these 2 indicators

     EMA13_initial = iMA(_Symbol, TimeFrame, EMAPERIOD, 0, EMAMODELT, PriceType);
     MACD_initial = iMACD(_Symbol, TimeFrame, FASTEMA, SLOWEMA, MACDESMA, PriceType1);  


In File 2 I want to call both of these using


      EMA13A_initial = iCustom(_Symbol,TimeFrame,"Elder Impulse system", TimeFrame, EMAPERIOD, 0, EMAMODELT, PriceType);

      //Print("MA_handle = ",EMA13A_initial,"  error = ",GetLastError());

      MACDA_initial = iCustom(_Symbol, TimeFrame,"Elder Impulse system", TimeFrame, FASTEMA, SLOWEMA, MACDESMA, PriceType1);


if I comment out the MACDA line all is fine 
As soon as I uncomment the MACDA line I get error "cannot load indicator 'Moving Average' [4002]"

I double check the parameters and all seems to be fine.

Anyone know if its possible to use two iCustom function to call two function in the same file (A)?


Kind regards





You can also try to use it like this, if you need to use multiple custom indicators in a file, you'll need to ensure that each iCustom call corresponds to a separate custom indicator. From your code, it looks like you're trying to call two different custom indicators ( Elder Impulse system and Moving Average Convergence Divergence (MACD) ).

EMA13A_initial = iCustom(_Symbol, TimeFrame, "Elder Impulse system", EMAPERIOD, 0, EMAMODELT, PriceType);


MACDA_initial = iCustom(_Symbol, TimeFrame, "MACD", FASTEMA, SLOWEMA, MACDESMA, PriceType1);


 
Nardus Van Staden #:
"Elder Impulse system"

@Nardus Van Staden


Thanks for the answer


Elder Impulse system is the file name and short name of the indicator I want to call the functions from.

This file contains both iMA and iMACD

Nevertheless I fixed the code 


Thanks everyone for reaching out!

Reason: