Files
MT5-EA-Sniper-Strategy/Include/Nkanven/Frameworks/Extensions/Indicators/IndicatorATR.mqh
T
2021-11-14 05:36:01 +01:00

78 lines
1.4 KiB
Plaintext

/*
IndicatorATR.mqh
Copyright 2013-2020, Orchard Forex
https://www.orchardforex.com
*/
#include "../../Framework.mqh"
class CIndicatorATR : public CIndicatorBase {
private:
protected: // member variables
int mPeriods;
public: // constructors
CIndicatorATR(int periods)
: CIndicatorBase()
{ Init(periods); }
CIndicatorATR(string symbol, ENUM_TIMEFRAMES timeframe,
int periods)
: CIndicatorBase(symbol, timeframe)
{ Init(periods); }
~CIndicatorATR();
virtual int Init(int periods);
public:
virtual double GetData(const int buffer_num,const int index);
};
CIndicatorATR::~CIndicatorATR() {
}
int CIndicatorATR::Init(int periods) {
if (InitResult()!=INIT_SUCCEEDED) return(InitResult());
mPeriods = periods;
#ifdef __MQL5__
mIndicatorHandle = iATR(mSymbol, mTimeframe, mPeriods);
if (mIndicatorHandle==INVALID_HANDLE) return(InitError("Failed to create indicator handle", INIT_FAILED));
#endif
return(INIT_SUCCEEDED);
}
double CIndicatorATR::GetData(const int buffer_num,const int index) {
double value = 0;
#ifdef __MQL4__
value = iATR(mSymbol, mTimeframe, mPeriods, index);
#endif
#ifdef __MQL5__
double bufferData[];
ArraySetAsSeries(bufferData, true);
int cnt = CopyBuffer(mIndicatorHandle, buffer_num, index, 1, bufferData);
if (cnt>0) value = bufferData[0];
#endif
return(value);
}