2026-10-30 19:22:39 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| Base.mqh |
|
| | | //| Copyright 2026, Niquel Mendoza. |
|
| | | //| https://www.mql5.com |
|
| | | //+------------------------------------------------------------------+
|
| | | #property copyright "Copyright 2026, Niquel Mendoza."
|
| | | #property link "https://www.mql5.com"
|
| | | #property strict
|
| | |
|
| | | #ifndef MQLARTICLES_INDICATORSCTS_BASE_BASE_MQH
|
| | | #define MQLARTICLES_INDICATORSCTS_BASE_BASE_MQH
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| Include |
|
| | | //+------------------------------------------------------------------+
|
| | | #include "Def.mqh"
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | namespace TSN
|
| | | {
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | class CiIndicatorBase
|
| | | {
|
| | | protected:
|
| | | ENUM_TIMEFRAMES m_timeframe;
|
| | | int m_handle;
|
| | | string m_symbol;
|
| | | bool m_realese;
|
| | | int m_chart_idx;
|
| | |
|
| | | public:
|
| | | const int m_type;
|
| | |
|
| | | public:
|
| | | CiIndicatorBase(const int type);
|
| | | ~CiIndicatorBase();
|
| | |
|
| | | //--- Destruccion
|
| | | void Destroy();
|
| | |
|
| | | //--- Getters
|
| | | inline int Handle() const { return m_handle; }
|
| | | inline ENUM_TIMEFRAMES Timeframe() const { return m_timeframe; }
|
| | | inline string Symbol() const { return m_symbol; }
|
| | | inline bool Realese() const { return m_realese; }
|
| | | inline bool HandleIsValid() const {return m_handle != INVALID_HANDLE; }
|
| | |
|
| | | //--- Utils
|
| | | inline void Realese(bool realese) { m_realese = realese; }
|
| | | bool CheckData(const int min_bars_calc, const int ms_sleep, int attemps = 100);
|
| | |
|
| | | //--- Grafico
|
| | | bool AddToChart(const long chart, const int subwin);
|
| | | bool DeleteFromChart(const long chart, const int subwin) const;
|
| | |
|
| | | //--- Calculated bars
|
| | | __forceinline int BarsCalculated() const { return ::BarsCalculated(m_handle); }
|
2026-11-06 10:40:44 -05:00 | | |
|
| | | //---
|
| | | static void FormatTrace(const TSNErrorFrame &trace[], int &trace_idx, string &out);
|
2026-10-30 19:22:39 -05:00 | | | };
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | CiIndicatorBase::CiIndicatorBase(const int type)
|
| | | : m_timeframe(WRONG_VALUE), m_symbol(NULL), m_handle(INVALID_HANDLE),
|
| | | m_realese(true), m_type(type), m_chart_idx(-1)
|
| | | {
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | CiIndicatorBase::~CiIndicatorBase()
|
| | | {
|
| | | Destroy();
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | void CiIndicatorBase::Destroy()
|
| | | {
|
| | | if(m_realese && m_handle != INVALID_HANDLE)
|
| | | {
|
| | | ::ResetLastError();
|
| | | if(!::IndicatorRelease(m_handle))
|
| | | FastLog(FUNCION_ACTUAL, ERROR_TEXT, ::StringFormat("Failed to clean indicador %d, last error = %d", m_type, ::GetLastError()));
|
| | |
|
| | | //---
|
| | | #ifdef MQLARTICLEs_INDSIMPLE_MAIN_LOG_DESC
|
| | | FastLog(FUNCION_ACTUAL, INFO_TEXT, ::StringFormat("Indicator [handle=%d] %d clenaed succefilled", m_handle, m_type));
|
| | | #endif // MQLARTICLEs_INDSIMPLE_MAIN_LOG_DESC
|
| | |
|
| | | //---
|
| | | m_handle = INVALID_HANDLE;
|
| | | }
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | bool CiIndicatorBase::CheckData(const int min_bars_calc, const int ms_sleep, int attemps = 100)
|
| | | {
|
| | | //---
|
| | | while(attemps-- > 0)
|
| | | {
|
| | | if(::BarsCalculated(m_handle) >= min_bars_calc)
|
| | | return true;
|
| | |
|
| | | //---
|
| | | ::Sleep(ms_sleep);
|
| | | }
|
| | |
|
| | | //---
|
| | | FastLog(FUNCION_ACTUAL, ERROR_TEXT, ::StringFormat("Fallo al obtener data del indicador %d | # Intenos = %d | Min Bars = %d | SleepMs = %d",
|
| | | m_type, attemps, min_bars_calc, ms_sleep));
|
| | |
|
| | | //---
|
| | | return false;
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | bool CiIndicatorBase::AddToChart(const long chart, const int subwin)
|
| | | {
|
| | | ::ResetLastError();
|
| | | if(!::ChartIndicatorAdd(chart, subwin, m_handle))
|
2026-11-02 16:24:01 -05:00 | | | return false;
|
2026-10-30 19:22:39 -05:00 | | | m_chart_idx = ::ChartIndicatorsTotal(chart, subwin) - 1;
|
2026-11-02 16:24:01 -05:00 | | | return true;
|
2026-10-30 19:22:39 -05:00 | | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | bool CiIndicatorBase::DeleteFromChart(const long chart, const int subwin) const
|
| | | {
|
| | | ::ResetLastError();
|
| | | return(::ChartIndicatorDelete(chart, subwin, ::ChartIndicatorName(chart, subwin, m_chart_idx)));
|
| | | }
|
2026-11-06 10:40:44 -05:00 | | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | static void CiIndicatorBase::FormatTrace(const TSNErrorFrame &trace[], int &trace_idx, string &out)
|
| | | {
|
| | | TSNSTD_ERRMAN_PUSHINI(out, trace_idx)
|
| | | switch(trace[trace_idx].code)
|
| | | {
|
| | | case TSNMQLART_INDICATOR_ERR_NOT:
|
| | | TSNSTD_ERRMAN_PUSHOUT(out, "Not errors", trace_idx)
|
| | | break;
|
| | | case TSNMQLART_INDICATOR_ERR_INVALID_HANDLE:
|
| | | TSNSTD_ERRMAN_PUSHOUT(out, StringFormat("Failed create indicador [type=%d], last mql5 err = %d", (int)trace[trace_idx].info,
|
| | | trace[trace_idx].mql_err), trace_idx)
|
| | | break;
|
| | | default:
|
| | | TSNSTD_ERRMAN_PUSHOUT(out, "Unknow error", trace_idx)
|
| | | break;
|
| | | }
|
| | | }
|
| | |
|
| | | //---
|
2026-10-30 19:22:39 -05:00 | | | }
|
| | |
|
| | | #endif // MQLARTICLES_INDICATORSCTS_BASE_BASE_MQH
|
| | | //+------------------------------------------------------------------+
|