137 lines
5.3 KiB
Plaintext
137 lines
5.3 KiB
Plaintext
//+------------------------------------------------------------------+
|
|
//| Trend.mqh |
|
|
//| Copyright 2000-2024, MetaQuotes Ltd. |
|
|
//| https://www.mql5.com |
|
|
//+------------------------------------------------------------------+
|
|
#include "Indicator.mqh"
|
|
//+------------------------------------------------------------------+
|
|
//| Class CiADX. |
|
|
//| Purpose: Class of the "Average Directional Index" indicator. |
|
|
//| Derives from class CIndicator. |
|
|
//+------------------------------------------------------------------+
|
|
class CiADX : public CIndicator
|
|
{
|
|
protected:
|
|
int m_ma_period;
|
|
|
|
public:
|
|
CiADX(void);
|
|
~CiADX(void);
|
|
//--- methods of access to protected data
|
|
int MaPeriod(void) const { return (m_ma_period); }
|
|
//--- method of creation
|
|
bool Create(const string symbol, const ENUM_TIMEFRAMES period, const int ma_period);
|
|
//--- methods of access to indicator data
|
|
double Main(const int index) const;
|
|
double Plus(const int index) const;
|
|
double Minus(const int index) const;
|
|
//--- method of identifying
|
|
virtual int Type(void) const { return (IND_ADX); }
|
|
|
|
protected:
|
|
//--- methods of tuning
|
|
virtual bool Initialize(const string symbol, const ENUM_TIMEFRAMES period, const int num_params, const MqlParam ¶ms[]);
|
|
bool Initialize(const string symbol, const ENUM_TIMEFRAMES period, const int ma_period);
|
|
};
|
|
//+------------------------------------------------------------------+
|
|
//| Constructor |
|
|
//+------------------------------------------------------------------+
|
|
CiADX::CiADX(void) : m_ma_period(-1)
|
|
{
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| Destructor |
|
|
//+------------------------------------------------------------------+
|
|
CiADX::~CiADX(void)
|
|
{
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| Create the "Average Directional Index" indicator |
|
|
//+------------------------------------------------------------------+
|
|
bool CiADX::Create(const string symbol, const ENUM_TIMEFRAMES period, const int ma_period)
|
|
{
|
|
//--- check history
|
|
if (!SetSymbolPeriod(symbol, period))
|
|
return (false);
|
|
//--- create
|
|
m_handle = iADX(symbol, period, ma_period);
|
|
//--- check result
|
|
if (m_handle == INVALID_HANDLE)
|
|
return (false);
|
|
//--- indicator successfully created
|
|
if (!Initialize(symbol, period, ma_period))
|
|
{
|
|
//--- initialization failed
|
|
IndicatorRelease(m_handle);
|
|
m_handle = INVALID_HANDLE;
|
|
return (false);
|
|
}
|
|
//--- ok
|
|
return (true);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| Initialize the indicator with universal parameters |
|
|
//+------------------------------------------------------------------+
|
|
bool CiADX::Initialize(const string symbol, const ENUM_TIMEFRAMES period, const int num_params, const MqlParam ¶ms[])
|
|
{
|
|
return (Initialize(symbol, period, (int)params[0].integer_value));
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| Initialize indicator with the special parameters |
|
|
//+------------------------------------------------------------------+
|
|
bool CiADX::Initialize(const string symbol, const ENUM_TIMEFRAMES period, const int ma_period)
|
|
{
|
|
if (CreateBuffers(symbol, period, 3))
|
|
{
|
|
//--- string of status of drawing
|
|
m_name = "ADX";
|
|
m_status = "(" + symbol + "," + PeriodDescription() + "," + IntegerToString(ma_period) + ") H=" + IntegerToString(m_handle);
|
|
//--- save settings
|
|
m_ma_period = ma_period;
|
|
//--- create buffers
|
|
((CIndicatorBuffer *)At(0)).Name("MAIN_LINE");
|
|
((CIndicatorBuffer *)At(1)).Name("PLUS_LINE");
|
|
((CIndicatorBuffer *)At(2)).Name("MINUS_LINE");
|
|
//--- ok
|
|
return (true);
|
|
}
|
|
//--- error
|
|
return (false);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| Access to Main buffer of "Average Directional Index" |
|
|
//+------------------------------------------------------------------+
|
|
double CiADX::Main(const int index) const
|
|
{
|
|
CIndicatorBuffer *buffer = At(0);
|
|
//--- check
|
|
if (buffer == NULL)
|
|
return (EMPTY_VALUE);
|
|
//---
|
|
return (buffer.At(index));
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| Access to Plus buffer of "Average Directional Index" |
|
|
//+------------------------------------------------------------------+
|
|
double CiADX::Plus(const int index) const
|
|
{
|
|
CIndicatorBuffer *buffer = At(1);
|
|
//--- check
|
|
if (buffer == NULL)
|
|
return (EMPTY_VALUE);
|
|
//---
|
|
return (buffer.At(index));
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| Access to Minus buffer of "Average Directional Index" |
|
|
//+------------------------------------------------------------------+
|
|
double CiADX::Minus(const int index) const
|
|
{
|
|
CIndicatorBuffer *buffer = At(2);
|
|
//--- check
|
|
if (buffer == NULL)
|
|
return (EMPTY_VALUE);
|
|
//---
|
|
return (buffer.At(index));
|
|
}
|