Value of Moving Average

 
What is the code to get the Moving Average indicator value?
 
Farhad1:
What is the code to get the Moving Average indicator value?

Look up iMA in the documentation.

 
Keith Watford:

Look up iMA in the documentation.

But that code only returns the number 10
 
Farhad1: But that code only returns the number 10

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 (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 start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 2020.07.05
          How to call indicators in MQL5 - MQL5 Articles 12 March 2010

 
Farhad1:
But that code only returns the number 10

Show your code that only returns the number 10.

 
Keith Watford:

Show your code that only returns the number 10.

Comment(iMA(_Symbol,_Period,20,0,MODE_EMA,PRICE_CLOSE));

this code show me number 10.

 
Farhad1:

this code show me number 10.

That is the code to get the handle.

Show the code where you use CopyBuffer.

 

I got the same... 

Do i have to use the CopyBuffer?

I am using it directly:


   for (i = 0; i < 2 + 1; i++)

    { 

        ma[i]=0;

        ma_off[i]=0;

        ma[i] = iMA(_Symbol, timeframe_ma, period, i, MODE_SMA, PRICE_CLOSE);

        ma_off[i] = iMA(_Symbol, timeframe_ma, period, i+offset, MODE_SMA, PRICE_CLOSE

     }
 
@RundesZweieck #: I got the same... Do i have to use the CopyBuffer? I am using it directly:

Yes, you have to use CopyBuffer in MQL5. Please read the documentation ...

iMA

Moving Average

CopyBuffer

Gets data of a specified buffer from a specified indicator into an array

 
uff one thing what changed from MQL4 .. i thought the basics would be the same.

So the solution in this thread is something like this. 

    double ama[];
    ResizeArray(ama,3);
    int ma = iMA(_Symbol, timeframe_ma, period, 0, MODE_SMA, PRICE_CLOSE);
    //ma_off = iMA(_Symbol, timeframe_ma, period, offset, MODE_SMA, PRICE_CLOSE);
    CopyBuffer(ma,0,0,2,ama);
    //CopyBuffer(ma_off,0,0,2,ama_off);
EDIT:

Why do i cant get a proper value from an IMA like this? With a offset of -6 ?
    double ama[];
    ResizeArray(ama,3);
    ma_off = iMA(_Symbol, timeframe_ma, period, -6, MODE_SMA, PRICE_CLOSE);
    CopyBuffer(ma_off,0,0,2,ama_off);

    Comment( "SMA OFF -6  ", ama_off[0];
 
Hello. 

Here, look at this code. 
It is functional and very simple. 
You should find the answers to your questions.

Reason: