Download MetaTrader 5

Script to get value of indicator ATR

To add comments, please log in or register
They are making profit already using Freelance service. You can join them!
zubr
172
zubr 2013.06.21 21:56 

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
17998
Simon Gniadkowski 2013.06.21 23:18  
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 2013.06.21 23:40  
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
14805
Biantoro Kunarto 2013.06.22 02:52  

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
17998
Simon Gniadkowski 2013.06.22 09:53  
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 2013.06.23 15:05  
biantoro:

This is the simple code to get ATR Value :

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