forked from nique_372/MQLArticles
//+------------------------------------------------------------------+
| |
//| 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_POSMGMT_TSL_INT_IND_BASE_MQH
| |
#define MQLARTICLES_POSMGMT_TSL_INT_IND_BASE_MQH
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
#include "..\\Def.mqh"
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
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:
| |
CTrailingStopIndicators(const int16_t nparams, const int type);
| |
~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;
| |
};
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
CTrailingStopIndicators::CTrailingStopIndicators(const int16_t nparams, const int type)
| |
: CTrailingStop(nparams, TSL_EXECUTION_ON_BAR, type),
| |
m_handle(INVALID_HANDLE),
| |
m_index(0)
| |
{
| |
//---
| |
ArrayResize(m_values, 1);
| |
ArraySetAsSeries(m_values, true);
| |
}
| |
//+------------------------------------------------------------------+
| |
CTrailingStopIndicators::~CTrailingStopIndicators()
| |
{
| |
if(m_handle != INVALID_HANDLE)
| |
IndicatorRelease(m_handle);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
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,
| |
StringFormat("No se pudieron copiar datos del indicador con tipo: %d, ultimo error = %d",
| |
m_type, ::GetLastError()));
| |
#endif
| |
}
| |
}
| |
| |
| |
//---
| |
}
| |
#endif // MQLARTICLES_POSMGMT_TSL_INT_IND_BASE_MQH
| |
//+------------------------------------------------------------------+
|