2026-10-24 11:58:18 -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
|
| | |
|
2026-10-24 12:47:47 -05:00 | | | #ifndef MQLARTICLES_POSMGMT_TSL_INT_IND_BASE_MQH
|
| | | #define MQLARTICLES_POSMGMT_TSL_INT_IND_BASE_MQH
|
2026-10-24 11:58:18 -05:00 | | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-10-24 17:50:41 -05:00 | | | #include "..\\Def.mqh"
|
2026-10-24 11:58:18 -05:00 | | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | namespace TSN
|
| | | {
|
| | | //+------------------------------------------------------------------+
|
| | | //| Trailing Stop by Indicator Simple |
|
| | | //+------------------------------------------------------------------+
|
| | | class CTrailingStopIndicators : public CTrailingStop
|
| | | {
|
| | | protected:
|
| | | //---
|
| | | double m_values[];
|
| | | int m_handle;
|
| | | int m_index;
|
| | |
|
| | | //---
|
| | | inline double GetPricePositionSell(double curr_price) const override final { return m_values[0] > curr_price ? m_values[0] : 0.0; }
|
| | | inline double GetPricePositionBuy(double curr_price) const override final { return m_values[0] < curr_price ? m_values[0] : 0.0; }
|
| | |
|
| | |
|
| | | public:
|
2026-11-05 17:09:00 -05:00 | | | CTrailingStopIndicators(const int16_t nparams, const int type);
|
2026-10-24 11:58:18 -05:00 | | | ~CTrailingStopIndicators();
|
| | |
|
| | | //---
|
| | | inline void Index(int new_value) { m_index = new_value; }
|
| | | inline int Index(int new_value) const { return m_index; }
|
| | | inline int Handle() const { return m_handle; }
|
| | |
|
| | | //---
|
| | | void OnNewBar() override final;
|
| | | };
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-11-05 17:09:00 -05:00 | | | CTrailingStopIndicators::CTrailingStopIndicators(const int16_t nparams, const int type)
|
| | | : CTrailingStop(nparams, TSL_EXECUTION_ON_BAR, type),
|
2026-10-24 11:58:18 -05:00 | | | m_handle(INVALID_HANDLE),
|
2026-11-05 17:09:00 -05:00 | | | m_index(0)
|
2026-10-24 11:58:18 -05:00 | | | {
|
| | | //---
|
| | | ArrayResize(m_values, 1);
|
| | | ArraySetAsSeries(m_values, true);
|
| | | }
|
| | | //+------------------------------------------------------------------+
|
| | | CTrailingStopIndicators::~CTrailingStopIndicators()
|
| | | {
|
| | | if(m_handle != INVALID_HANDLE)
|
| | | IndicatorRelease(m_handle);
|
| | | }
|
2026-11-05 17:09:00 -05:00 | | |
|
2026-10-24 11:58:18 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | void CTrailingStopIndicators::OnNewBar(void)
|
| | | {
|
| | | //---
|
| | | #ifndef GENBYLEO_TRAILINGSTOP_DESACTIVE_ERR_LOGS
|
| | | ResetLastError();
|
| | | #endif
|
| | |
|
| | | //---
|
| | | if(CopyBuffer(m_handle, 0, m_index, 1, m_values) < 1)
|
| | | {
|
| | | #ifndef GENBYLEO_TRAILINGSTOP_DESACTIVE_ERR_LOGS
|
| | | FastLog(FUNCION_ACTUAL, FATAL_ERROR_TEXT,
|
2026-11-05 17:09:00 -05:00 | | | StringFormat("No se pudieron copiar datos del indicador con tipo: %d, ultimo error = %d",
|
| | | m_type, ::GetLastError()));
|
2026-10-24 11:58:18 -05:00 | | | #endif
|
| | | }
|
| | | }
|
| | |
|
| | |
|
| | | //---
|
| | | }
|
2026-10-24 12:47:47 -05:00 | | | #endif // MQLARTICLES_POSMGMT_TSL_INT_IND_BASE_MQH
|
2026-10-24 11:58:18 -05:00 | | | //+------------------------------------------------------------------+
|