Need Help with iCustom Function - Returns integers instead of buffer value

To add comments, please log in or register
RedTruth
28
RedTruth  

Hey MQL Experts!

I'm attempting to use iCustom to return the current values of the indicators for my EA.

I've been hunting around MQL5 forums and Stack Overflow and attempted to follow the responses exactly however still not getting much luck. I'm clearly missing something and I bet it's super obvious so a virtual shout to whoever can nail it first! :) 

Trying to return two values from the Adaptive Moving Average indicator 'AMA'. 

According to what I've read, in terms of the params you use:

1. Symbol

2. Period

3. <Indicator Name>

4. Inputs

5. Buffer Index

6. Value offset

I've tried all different sorts of combos in the parameters but I still continuously receive integers counting up instead of the actual value of the adaptive moving average which is what I'm after.


I've also attached both the EA and Indi file for your reference.


iCustom returns Int

Any other references than?

https://www.mql5.com/en/docs/indicators/icustom


   static double currentAma;
   currentAma = iCustom(_Symbol,_Period,"AMA",10,2,30,0,0,0);
   
   Print("currentAma = ", DoubleToString(currentAma,6));
   
   static double previousAma;
   previousAma = iCustom(_Symbol,_Period,"AMA",10,2,30,0,0,1);
   
   Print("previousAma = ", DoubleToString(previousAma,6));
Documentation on MQL5: Technical Indicators / iCustom
Documentation on MQL5: Technical Indicators / iCustom
  • www.mql5.com
[in]  The name of the custom indicator, with path relative to the root directory of indicators (MQL5/Indicators/). If an indicator is located in a subdirectory, for example, in MQL5/Indicators/ [in] input-parameters of a custom indicator, separated by commas. Type and order of parameters must match. If there is no parameters specified, then...
Files:
RedTruth
28
RedTruth  

Ok, so after more playing around I've figured out that it's only the 'handle' that's being returned as an integer, not the actual buffer values.


Is the correct practice to declare a buffer inside the EA and then use those values, or is there still another way to retrieve the values in the buffer with one command?

Alain Verleyen
40433
Alain Verleyen  
RedTruth:

Ok, so after more playing around I've figured out that it's only the 'handle' that's being returned as an integer, not the actual buffer values.


Is the correct practice to declare a buffer inside the EA and then use those values, or is there still another way to retrieve the values in the buffer with one command?

It would help you to read the documentation.
Xiaowei Yan
944
Xiaowei Yan  
Alain Verleyen:
It would help you to read the documentation.

I have another question. In MT5, the indicator called by iCustom is calculated asynchronously, so when I want to get the value of indicator in my EA's OnTick function, how do I know the indicator value is already up to date.

When an old bar is closed and a new bar just open, then mt5 will do the calculation of indicator's OnCalculate function and my ea's OnTick function asynchronously, it is possible that OnTick is finished earlier than OnCalculate if the indicator is very complex. I don't find a way to check if the calculation of OnCalculate has aready finished.

RedTruth
28
RedTruth  

Alain Verleyen:
It would help you to read the documentation.


Not helpful.

Read the documentation and doesn't mention anything about EA to Indicator best practice.

Alain Verleyen
40433
Alain Verleyen  
Xiaowei Yan:

I have another question. In MT5, the indicator called by iCustom is calculated asynchronously, so when I want to get the value of indicator in my EA's OnTick function, how do I know the indicator value is already up to date.

When an old bar is closed and a new bar just open, then mt5 will do the calculation of indicator's OnCalculate function and my ea's OnTick function asynchronously, it is possible that OnTick is finished earlier than OnCalculate if the indicator is very complex. I don't find a way to check if the calculation of OnCalculate has aready finished.

iCustom() is asynchronous, but CopyBuffer() is not. On each new tick OnCalculate() is called AND returned, before OnTick() is executed.
William Roeder
21941
William Roeder  
Perhaps you should read the manual, especially the examples. They all (including iCustom) return a handle (an int.) You get that in OnInit. In OnTick (after the indicator has updated its buffers,) you use the handle, shift and count to get the data.
          Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
          Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
          How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 2020.03.08
          How to call indicators in MQL5 - MQL5 Articles 12 March 2010
To add comments, please log in or register