MQLArticles/PosMgmt/TSL/Int/Prev.mqh
77 行
3 KiB
MQL5
Nique_372
2026-10-24 11:58:18 -05:00
//+------------------------------------------------------------------+
//| Prev.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_PREV_MQH
#define MQLARTICLES_POSMGMT_TSL_INT_PREV_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
Nique_372
2026-10-24 12:47:47 -05:00
//+------------------------------------------------------------------+
//| Indices de MqlParam para CTrailingStopPrev::SetVariables |
//+------------------------------------------------------------------+
#define TSNMQLA_TSL_PREV_PARAM_TIMEFRAME 0 // ENUM_TIMEFRAMES
#define TSNMQLA_TSL_PREV_PARAM_INDEX 1 // int: indice
Nique_372
2026-11-05 17:09:00 -05:00
#define TSNMQLA_TSL_PREV_NPARAMS 2
Nique_372
2026-10-24 12:47:47 -05:00
Nique_372
2026-10-24 11:58:18 -05:00
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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:
Nique_372
2026-10-24 17:50:41 -05:00
CTrailingStopPrev()
Nique_372
2026-11-05 17:09:00 -05:00
: CTrailingStop(TSNMQLA_TSL_PREV_NPARAMS, TSL_EXECUTION_ON_BAR, TRAILING_STOP_MODE_BASIC_PREV_LOHI) { }
Nique_372
2026-10-24 11:58:18 -05:00
~CTrailingStopPrev() {}
//---
bool SetVariables(const MqlParam &params[]) override final;
void OnNewBar() override;
};
Nique_372
2026-10-24 17:50:41 -05:00
TSNMQLA_TRAILINGSTOP_REGISTER_CREATOR(CTrailingStopPrev, SimplePLohi, TRAILING_STOP_MODE_BASIC_PREV_LOHI)
Nique_372
2026-10-24 11:58:18 -05:00
//+------------------------------------------------------------------+
bool CTrailingStopPrev::SetVariables(const MqlParam & params[])
{
Nique_372
2026-10-24 12:47:47 -05:00
m_timeframe = (ENUM_TIMEFRAMES)params[TSNMQLA_TSL_PREV_PARAM_TIMEFRAME].integer_value;
m_index = (int)params[TSNMQLA_TSL_PREV_PARAM_INDEX].integer_value;
Nique_372
2026-10-24 11:58:18 -05:00
return true;
}
//+------------------------------------------------------------------+
void CTrailingStopPrev::OnNewBar(void)
{
m_high = iHigh(m_symbol, m_timeframe, m_index);
m_low = iLow(m_symbol, m_timeframe, m_index);
}
//---
}
Nique_372
2026-10-24 12:47:47 -05:00
#endif // MQLARTICLES_POSMGMT_TSL_INT_PREV_MQH