Download MetaTrader 5

Script to get value of indicator ATR

To add comments, please log in or register
zubr
172
zubr  

Hi,

 I try to program  a simple script.

 My question: How do I get the value of the ATR (average true range) indicator in a script? I've found the function "iATR" (https://www.mql5.com/en/docs/indicators/iatr) but it does not return the current ATR value. Any ideas?

 

Thank you.

Best,

Chris 

Documentation on MQL5: Technical Indicators / iATR
Documentation on MQL5: Technical Indicators / iATR
  • www.mql5.com
Technical Indicators / iATR - Documentation on MQL5
Simon Gniadkowski
Moderator
18035
Simon Gniadkowski  
zubr:

Hi,

 I try to program  a simple script.

 My question: How do I get the value of the ATR (average true range) indicator in a script? I've found the function "iATR" (https://www.mql5.com/en/docs/indicators/iatr) but it does not return the current ATR value. Any ideas?

It doesn't return the ATR value,  it returns a handle . . .  read the documentation and sample code.
zubr
172
zubr  
RaptorUK:
It doesn't return the ATR value,  it returns a handle . . .  read the documentation and sample code.
Do you know how to get the ATR value? I haven't found the function yet.
Biantoro Kunarto
17672
Biantoro Kunarto  

This is the simple code to get ATR Value :

int      MA_Period = 15;               // The value of the averaging period for the indicator calculation
int      Count = 5;                    // Amount to copy
int      ATRHandle;                    // Variable to store the handle of ATR
double   ATRValue[];                   // Variable to store the value of ATR    
ATRHandle = iATR(_Symbol,0,MA_Period); // returns a handle for ATR
ArraySetAsSeries( ATRValue,true );     // Set the ATRValue to timeseries, 0 is the oldest. 
if( CopyBuffer( ATRHandle,0,0,Count,ATRValue ) > 0 ) // Copy value of ATR to ATRValue
   {
      for( int i=0;i<Count;i++ )
         {
            Print(ATRValue[i]); // Print the value of the ATR
         } 
   }
Simon Gniadkowski
Moderator
18035
Simon Gniadkowski  
zubr:
Do you know how to get the ATR value? I haven't found the function yet.

Yes,  I already told you what to do . . .

RaptorUK:
   read the documentation and sample code.
zubr
172
zubr  
biantoro:

This is the simple code to get ATR Value :

Thank you!
To add comments, please log in or register