//+------------------------------------------------------------------+ //| Class CiIchimoku. | //| Purpose: Class of the "Ichimoku Kinko Hyo" indicator. | //| Derives from class CIndicator. | //+------------------------------------------------------------------+ class CiIchimoku : public CIndicator { protected: int m_tenkan_sen; int m_kijun_sen; int m_senkou_span_b; public: CiIchimoku(void); ~CiIchimoku(void); //--- methods of access to protected data int TenkanSenPeriod(void) const { return (m_tenkan_sen); } int KijunSenPeriod(void) const { return (m_kijun_sen); } int SenkouSpanBPeriod(void) const { return (m_senkou_span_b); } //--- method of creation bool Create(const string symbol, const ENUM_TIMEFRAMES period, const int tenkan_sen, const int kijun_sen, const int senkou_span_b); //--- methods of access to indicator data double TenkanSen(const int index) const; double KijunSen(const int index) const; double SenkouSpanA(const int index) const; double SenkouSpanB(const int index) const; double ChinkouSpan(const int index) const; //--- method of identifying virtual int Type(void) const { return (IND_ICHIMOKU); } 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 tenkan_sen, const int kijun_sen, const int senkou_span_b); }; //+------------------------------------------------------------------+ //| Constructor | //+------------------------------------------------------------------+ CiIchimoku::CiIchimoku(void) : m_tenkan_sen(-1), m_kijun_sen(-1), m_senkou_span_b(-1) { } //+------------------------------------------------------------------+ //| Destructor | //+------------------------------------------------------------------+ CiIchimoku::~CiIchimoku(void) { } //+------------------------------------------------------------------+ //| Create indicator "Ichimoku Kinko Hyo" | //+------------------------------------------------------------------+ bool CiIchimoku::Create(const string symbol, const ENUM_TIMEFRAMES period, const int tenkan_sen, const int kijun_sen, const int senkou_span_b) { //--- check history if (!SetSymbolPeriod(symbol, period)) return (false); //--- create m_handle = iIchimoku(symbol, period, tenkan_sen, kijun_sen, senkou_span_b); //--- check result if (m_handle == INVALID_HANDLE) return (false); //--- indicator successfully created if (!Initialize(symbol, period, tenkan_sen, kijun_sen, senkou_span_b)) { //--- initialization failed IndicatorRelease(m_handle); m_handle = INVALID_HANDLE; return (false); } //--- ok return (true); } //+------------------------------------------------------------------+ //| Initialize the indicator with universal parameters | //+------------------------------------------------------------------+ bool CiIchimoku::Initialize(const string symbol, const ENUM_TIMEFRAMES period, const int num_params, const MqlParam ¶ms[]) { return (Initialize(symbol, period, (int)params[0].integer_value, (int)params[1].integer_value, (int)params[2].integer_value)); } //+------------------------------------------------------------------+ //| Initialize indicator with the special parameters | //+------------------------------------------------------------------+ bool CiIchimoku::Initialize(const string symbol, const ENUM_TIMEFRAMES period, const int tenkan_sen, const int kijun_sen, const int senkou_span_b) { if (CreateBuffers(symbol, period, 5)) { //--- string of status of drawing m_name = "Ichimoku"; m_status = "(" + symbol + "," + PeriodDescription() + "," + IntegerToString(tenkan_sen) + "," + IntegerToString(kijun_sen) + "," + IntegerToString(senkou_span_b) + ") H=" + IntegerToString(m_handle); //--- save settings m_tenkan_sen = tenkan_sen; m_kijun_sen = kijun_sen; m_senkou_span_b = senkou_span_b; //--- create buffers ((CIndicatorBuffer *)At(0)).Name("TENKANSEN_LINE"); ((CIndicatorBuffer *)At(1)).Name("KIJUNSEN_LINE"); ((CIndicatorBuffer *)At(2)).Name("SENKOUSPANA_LINE"); ((CIndicatorBuffer *)At(2)).Offset(kijun_sen); ((CIndicatorBuffer *)At(3)).Name("SENKOUSPANB_LINE"); ((CIndicatorBuffer *)At(3)).Offset(kijun_sen); ((CIndicatorBuffer *)At(4)).Name("CHIKOUSPAN_LINE"); ((CIndicatorBuffer *)At(4)).Offset(-kijun_sen); //--- ok return (true); } //--- error return (false); } //+------------------------------------------------------------------+ //| Access to TenkanSen buffer of "Ichimoku Kinko Hyo" | //+------------------------------------------------------------------+ double CiIchimoku::TenkanSen(const int index) const { CIndicatorBuffer *buffer = At(0); //--- check if (buffer == NULL) return (EMPTY_VALUE); //--- return (buffer.At(index)); } //+------------------------------------------------------------------+ //| Access to KijunSen buffer of "Ichimoku Kinko Hyo" | //+------------------------------------------------------------------+ double CiIchimoku::KijunSen(const int index) const { CIndicatorBuffer *buffer = At(1); //--- check if (buffer == NULL) return (EMPTY_VALUE); //--- return (buffer.At(index)); } //+------------------------------------------------------------------+ //| Access to SenkouSpanA buffer of "Ichimoku Kinko Hyo" | //+------------------------------------------------------------------+ double CiIchimoku::SenkouSpanA(const int index) const { CIndicatorBuffer *buffer = At(2); //--- check if (buffer == NULL) return (EMPTY_VALUE); //--- return (buffer.At(index)); } //+------------------------------------------------------------------+ //| Access to SenkouSpanB buffer of "Ichimoku Kinko Hyo" | //+------------------------------------------------------------------+ double CiIchimoku::SenkouSpanB(const int index) const { CIndicatorBuffer *buffer = At(3); //--- check if (buffer == NULL) return (EMPTY_VALUE); //--- return (buffer.At(index)); } //+------------------------------------------------------------------+ //| Access to ChikouSpan buffer of "Ichimoku Kinko Hyo" | //+------------------------------------------------------------------+ double CiIchimoku::ChinkouSpan(const int index) const { CIndicatorBuffer *buffer = At(4); //--- check if (buffer == NULL) return (EMPTY_VALUE); //--- return (buffer.At(index)); }