MQLArticles/PosMgmt/TSL/Int/Ind/Base.mqh
96 行
3.6 KiB
MQL5
Nique_372
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
Nique_372
2026-10-24 12:47:47 -05:00
#ifndef MQLARTICLES_POSMGMT_TSL_INT_IND_BASE_MQH
#define MQLARTICLES_POSMGMT_TSL_INT_IND_BASE_MQH
Nique_372
2026-10-24 11:58:18 -05:00
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
Nique_372
2026-10-24 17:50:41 -05:00
#include "..\\Def.mqh"
Nique_372
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:
Nique_372
2026-11-05 17:09:00 -05:00
CTrailingStopIndicators(const int16_t nparams, const int type);
Nique_372
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;
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
Nique_372
2026-11-05 17:09:00 -05:00
CTrailingStopIndicators::CTrailingStopIndicators(const int16_t nparams, const int type)
: CTrailingStop(nparams, TSL_EXECUTION_ON_BAR, type),
Nique_372
2026-10-24 11:58:18 -05:00
m_handle(INVALID_HANDLE),
Nique_372
2026-11-05 17:09:00 -05:00
m_index(0)
Nique_372
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);
}
Nique_372
2026-11-05 17:09:00 -05:00
Nique_372
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,
Nique_372
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()));
Nique_372
2026-10-24 11:58:18 -05:00
#endif
}
}
//---
}
Nique_372
2026-10-24 12:47:47 -05:00
#endif // MQLARTICLES_POSMGMT_TSL_INT_IND_BASE_MQH
Nique_372
2026-10-24 11:58:18 -05:00
//+------------------------------------------------------------------+