IMA indicator value of 10

 

Hi everyone, 

I'm new in mql5, 

I'm trying to run a script that get the value of the moving average IMA. but the problem that it always return me the value of 10 

i know that mql5 is different than mql4, and i have to use the function Copybuffer. i tried but no result 

if anyone can help me please !! that's my code :

void OnStart()
{
//---
   int EMA  = iMA(Symbol(),PERIOD_M5,3,1,MODE_SMA,PRICE_CLOSE);
   Print(EMA);
} 


   

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
 

1. Please insert the code correctly: when editing a message, press the button       Codeand paste your code into the pop-up window (for the first time I corrected your message and pasted the code correctly)

2. An example of how to get the indicator value from an Expert Advisor: Creating an iMA indicator handle, getting indicator values

How to start with MQL5
How to start with MQL5
  • 2020.03.05
  • www.mql5.com
This thread discusses MQL5 code examples. There will be examples of how to get data from indicators, how to program advisors...
 
elyatim:

Hi everyone, 

I'm new in mql5, 

I'm trying to run a script that get the value of the moving average IMA. but the problem that it always return me the value of 10 

i know that mql5 is different than mql4, and i have to use the function Copybuffer. i tried but no result 

if anyone can help me please !! that's my code :


   

int EMA_HANDLE = iMA(Symbol(),PERIOD_M5,3,1,MODE_EMA,PRICE_CLOSE);
double data[];
ArraySetAsSeries(data, true);
CopyBuffer(EMA_HANDLE , 0, 0, 1, data);
double ema_value=data[0];
 
Yashar Seyyedin #:

Perhaps you should read the manual, especially the examples.
   How To Ask Questions The Smart Way. (2004)
      How To Interpret Answers.
         RTFM and STFW: How To Tell You've Seriously Screwed Up.

They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate (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)
          How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 (2020)
          MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors - MQL5 Articles (2010)
          How to call indicators in MQL5 - MQL5 Articles (2010)

Reason: