forked from nique_372/MQLArticles
//+------------------------------------------------------------------+
| |
//| Prev.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_PREV_MQH
| |
#define MQLARTICLES_POSMGMT_TSL_INT_PREV_MQH
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
#include "Def.mqh"
| |
| |
//+------------------------------------------------------------------+
| |
//| Indices de MqlParam para CTrailingStopPrev::SetVariables |
| |
//+------------------------------------------------------------------+
| |
#define TSNMQLA_TSL_PREV_PARAM_TIMEFRAME 0 // ENUM_TIMEFRAMES
| |
#define TSNMQLA_TSL_PREV_PARAM_INDEX 1 // int: indice
| |
#define TSNMQLA_TSL_PREV_NPARAMS 2
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
namespace TSN
| |
{
| |
//+------------------------------------------------------------------+
| |
//| Trailing Stop by Prev High Low |
| |
//+------------------------------------------------------------------+
| |
class CTrailingStopPrev : public CTrailingStop
| |
{
| |
protected:
| |
//---
| |
double m_high;
| |
double m_low;
| |
int m_index;
| |
| |
//---
| |
inline double GetPricePositionSell(double curr_price) const override final { return m_high > curr_price ? m_high : 0.0; }
| |
inline double GetPricePositionBuy(double curr_price) const override final { return m_low < curr_price ? m_low : 0.0; }
| |
| |
public:
| |
CTrailingStopPrev()
| |
: CTrailingStop(TSNMQLA_TSL_PREV_NPARAMS, TSL_EXECUTION_ON_BAR, TRAILING_STOP_MODE_BASIC_PREV_LOHI) { }
| |
~CTrailingStopPrev() {}
| |
| |
//---
| |
bool SetVariables(const MqlParam ¶ms[]) override final;
| |
void OnNewBar() override;
| |
};
| |
| |
TSNMQLA_TRAILINGSTOP_REGISTER_CREATOR(CTrailingStopPrev, SimplePLohi, TRAILING_STOP_MODE_BASIC_PREV_LOHI)
| |
| |
//+------------------------------------------------------------------+
| |
bool CTrailingStopPrev::SetVariables(const MqlParam & params[])
| |
{
| |
m_timeframe = (ENUM_TIMEFRAMES)params[TSNMQLA_TSL_PREV_PARAM_TIMEFRAME].integer_value;
| |
m_index = (int)params[TSNMQLA_TSL_PREV_PARAM_INDEX].integer_value;
| |
return true;
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
void CTrailingStopPrev::OnNewBar(void)
| |
{
| |
m_high = iHigh(m_symbol, m_timeframe, m_index);
| |
m_low = iLow(m_symbol, m_timeframe, m_index);
| |
}
| |
| |
| |
//---
| |
}
| |
| |
| |
#endif // MQLARTICLES_POSMGMT_TSL_INT_PREV_MQH
|