MQLArticles/Account/RM/LossProfit/Basic/MaxProfits.mqh
244 行
8.9 KiB
MQL5
Nique_372
2026-10-27 18:07:28 -05:00
//+------------------------------------------------------------------+
//| MaxProfits.mqh |
//| Copyright 2025, Niquel Mendoza. |
//| https://www.mql5.com/es/users/nique_372 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, Niquel Mendoza."
#property link "https://www.mql5.com/es/users/nique_372"
#property strict
#ifndef MQLARTICLES_ACCOUNT_RM_LOSSPROFIT_BASIC_MAXPROFITS_MQH
#define MQLARTICLES_ACCOUNT_RM_LOSSPROFIT_BASIC_MAXPROFITS_MQH
//+------------------------------------------------------------------+
//| Include |
//+------------------------------------------------------------------+
#include "Classes.mqh"
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
namespace TSN
{
//+------------------------------------------------------------------+
//| MDP |
//+------------------------------------------------------------------+
Nique_372
2026-10-28 10:48:27 -05:00
class CLossProfitMaxDaily : public CLossProfitBaseProfit
Nique_372
2026-10-27 18:07:28 -05:00
{
public:
Nique_372
2026-10-27 22:04:41 -05:00
CLossProfitMaxDaily(const ulong magic);
Nique_372
2026-11-02 06:40:25 -05:00
~CLossProfitMaxDaily(void) { if(CBasicEvents::IsActive()) CBasicEvents::UnregisterEvent(&this, TSNQMALRT_BASIEVENT_TYPE_ON_NEW_DAY); }
Nique_372
2026-10-27 18:07:28 -05:00
//---
void OnNewDay(const datetime curr_time) override final;
};
//+------------------------------------------------------------------+
Nique_372
2026-10-28 10:48:27 -05:00
CLossProfitMaxDaily::CLossProfitMaxDaily(const ulong magic)
: CLossProfitBaseProfit(LOSSPROFIT_TYPE_MDP, false, magic)
Nique_372
2026-10-27 18:07:28 -05:00
{
Nique_372
2026-11-02 06:40:25 -05:00
CBasicEvents::RegisterEvent(&this, TSNQMALRT_BASIEVENT_TYPE_ON_NEW_DAY); // Registramos para recibir OnNewDay
Nique_372
2026-10-27 18:07:28 -05:00
}
//+------------------------------------------------------------------+
void CLossProfitMaxDaily::OnNewDay(const datetime curr_time)
{
Nique_372
2026-10-28 10:48:27 -05:00
Set();
m_saved_value = m_value;
Nique_372
2026-10-27 18:07:28 -05:00
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| MWP |
//+------------------------------------------------------------------+
Nique_372
2026-10-28 10:48:27 -05:00
class CLossProfitMaxWeekly : public CLossProfitBaseProfit
Nique_372
2026-10-27 18:07:28 -05:00
{
public:
Nique_372
2026-10-27 22:04:41 -05:00
CLossProfitMaxWeekly(const ulong magic);
Nique_372
2026-11-02 06:40:25 -05:00
~CLossProfitMaxWeekly(void) { if(CBasicEvents::IsActive()) CBasicEvents::UnregisterEvent(&this, TSNQMALRT_BASIEVENT_TYPE_ON_NEW_WEEK); }
Nique_372
2026-10-27 18:07:28 -05:00
//---
void OnNewWeek(const datetime curr_time) override final;
};
//+------------------------------------------------------------------+
Nique_372
2026-10-28 10:48:27 -05:00
CLossProfitMaxWeekly::CLossProfitMaxWeekly(const ulong magic)
Nique_372
2026-11-01 16:18:50 -05:00
: CLossProfitBaseProfit(LOSSPROFIT_TYPE_MWP, false, magic)
Nique_372
2026-10-27 18:07:28 -05:00
{
Nique_372
2026-11-02 06:40:25 -05:00
CBasicEvents::RegisterEvent(&this, TSNQMALRT_BASIEVENT_TYPE_ON_NEW_WEEK); // Registramos para recibir OnNewWeek
Nique_372
2026-10-27 18:07:28 -05:00
}
//+------------------------------------------------------------------+
void CLossProfitMaxWeekly::OnNewWeek(const datetime curr_time)
{
Nique_372
2026-10-28 10:48:27 -05:00
Set();
m_saved_value = m_value;
Nique_372
2026-10-27 18:07:28 -05:00
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| MMP |
//+------------------------------------------------------------------+
Nique_372
2026-10-28 10:48:27 -05:00
class CLossProfitMaxMon : public CLossProfitBaseProfit
Nique_372
2026-10-27 18:07:28 -05:00
{
public:
Nique_372
2026-10-27 22:04:41 -05:00
CLossProfitMaxMon(const ulong magic);
Nique_372
2026-11-02 06:40:25 -05:00
~CLossProfitMaxMon(void) { if(CBasicEvents::IsActive()) CBasicEvents::UnregisterEvent(&this, TSNQMALRT_BASIEVENT_TYPE_ON_NEW_MONTH); }
Nique_372
2026-10-27 18:07:28 -05:00
//---
void OnNewMonth(const datetime curr_time) override final;
};
//+------------------------------------------------------------------+
Nique_372
2026-10-28 10:48:27 -05:00
CLossProfitMaxMon::CLossProfitMaxMon(const ulong magic)
: CLossProfitBaseProfit(LOSSPROFIT_TYPE_MMP, false, magic)
Nique_372
2026-10-27 18:07:28 -05:00
{
Nique_372
2026-11-02 06:40:25 -05:00
CBasicEvents::RegisterEvent(&this, TSNQMALRT_BASIEVENT_TYPE_ON_NEW_MONTH); // Registramos para recibir OnNewMonth
Nique_372
2026-10-27 18:07:28 -05:00
}
//+------------------------------------------------------------------+
void CLossProfitMaxMon::OnNewMonth(const datetime curr_time)
{
Nique_372
2026-10-28 10:48:27 -05:00
Set();
m_saved_value = m_value;
Nique_372
2026-10-27 18:07:28 -05:00
}
//+------------------------------------------------------------------+
//| MP - Maximum Profit (sin reseteo temporal) |
//+------------------------------------------------------------------+
Nique_372
2026-10-28 10:48:27 -05:00
class CLossProfitMax : public CLossProfitBaseProfit
Nique_372
2026-10-27 18:07:28 -05:00
{
public:
Nique_372
2026-10-27 22:04:41 -05:00
CLossProfitMax(const ulong magic);
Nique_372
2026-10-27 18:07:28 -05:00
~CLossProfitMax(void) {}
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
Nique_372
2026-10-28 10:48:27 -05:00
CLossProfitMax::CLossProfitMax(const ulong magic)
: CLossProfitBaseProfit(LOSSPROFIT_TYPE_MP, false, magic)
Nique_372
2026-10-27 18:07:28 -05:00
{
// No registra eventos temporales - tracking continuo sin reseteos
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| M desde el bajo |
//+------------------------------------------------------------------+
#define LOSSPROFIT_MAXMON_FLAG_BAJO_LISTO (1)
Nique_372
2026-10-28 10:48:27 -05:00
class CLossProfitMaxDesdeBaajo : public CLossProfitBaseProfit
Nique_372
2026-10-27 18:07:28 -05:00
{
private:
Nique_372
2026-11-02 10:55:13 -05:00
bool m_pico_listo;
Nique_372
2026-10-27 18:07:28 -05:00
double m_negative_profit;
double m_min_negative_profit;
FuncionLossProfitSuperate m_func_base;
//---
void OnSuperated() override final;
public:
Nique_372
2026-10-27 22:04:41 -05:00
CLossProfitMaxDesdeBaajo(const ulong magic);
Nique_372
2026-10-27 18:07:28 -05:00
~CLossProfitMaxDesdeBaajo(void) {}
//---
void OnLossProfit(const double p) override final;
//---
Nique_372
2026-10-28 10:48:27 -05:00
void Init(double _calc_value, FuncionLossProfitSuperate fsup, FTSNMQLArtRmPctgVal fval);
Nique_372
2026-10-27 18:07:28 -05:00
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
Nique_372
2026-10-28 10:48:27 -05:00
CLossProfitMaxDesdeBaajo::CLossProfitMaxDesdeBaajo(const ulong magic)
: CLossProfitBaseProfit(LOSSPROFIT_TYPE_MDDBAJO, true, magic), m_func_base(NULL)
Nique_372
2026-10-27 18:07:28 -05:00
, m_negative_profit(0.00), m_min_negative_profit(0.00),
Nique_372
2026-11-02 07:16:20 -05:00
m_pico_listo(false)
Nique_372
2026-10-27 18:07:28 -05:00
{
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
Nique_372
2026-10-28 10:48:27 -05:00
void CLossProfitMaxDesdeBaajo::Init(double _calc_value, FuncionLossProfitSuperate fsup, FTSNMQLArtRmPctgVal fval)
Nique_372
2026-10-27 18:07:28 -05:00
{
m_func_base = fsup;
Nique_372
2026-10-28 10:48:27 -05:00
CLossProfit::Init(_calc_value, LossProfitEmptyFuncionSup, fval); // Llamamos a la del padre
Nique_372
2026-10-27 18:07:28 -05:00
}
Nique_372
2026-10-28 10:48:27 -05:00
Nique_372
2026-10-27 18:07:28 -05:00
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CLossProfitMaxDesdeBaajo::OnSuperated()
{
Nique_372
2026-11-02 07:16:20 -05:00
m_pico_listo = false;
Nique_372
2026-10-27 18:07:28 -05:00
m_negative_profit = 0.00;
m_min_negative_profit = 0.00;
Nique_372
2026-10-28 10:48:27 -05:00
m_f_check_sup = LossProfitEmptyFuncionSup;
Nique_372
2026-10-27 18:07:28 -05:00
#ifdef MORE_INFO_LOSS_PROFIT_DEFINE
Nique_372
2026-10-27 19:06:42 -05:00
FastLog(FUNCION_ACTUAL, INFO_TEXT, "Run-up target reached, resetting to search new minimum");
Nique_372
2026-10-27 18:07:28 -05:00
#endif
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CLossProfitMaxDesdeBaajo::OnLossProfit(const double p)
{
//---
if(m_magic_number != NOT_MAGIC_NUMBER && m_magic_number != account_status.last_deal_magic)
return;
//---
m_negative_profit += p;
//---
if(m_negative_profit < m_min_negative_profit)
{
//--- Calculamos el nuevo valor
Nique_372
2026-10-28 10:48:27 -05:00
Set();
m_saved_value = m_value;
Nique_372
2026-10-27 18:07:28 -05:00
Nique_372
2026-11-02 07:16:20 -05:00
m_pico_listo = false;
Nique_372
2026-10-27 18:07:28 -05:00
m_min_negative_profit = m_negative_profit;
Nique_372
2026-10-28 10:48:27 -05:00
m_f_check_sup = LossProfitEmptyFuncionSup;
Nique_372
2026-10-27 18:07:28 -05:00
#ifdef MORE_INFO_LOSS_PROFIT_DEFINE
Nique_372
2026-11-02 07:16:20 -05:00
FastLog(FUNCION_ACTUAL, INFO_TEXT, StringFormat("New minimum detected: %.2f, target: %.2f", m_min_negative_profit, m_saved_value));
Nique_372
2026-10-27 18:07:28 -05:00
#endif
}
//---
Nique_372
2026-11-02 07:16:20 -05:00
if(!m_pico_listo)
Nique_372
2026-10-27 18:07:28 -05:00
{
Nique_372
2026-11-02 07:16:20 -05:00
if(p > 0.00 && m_min_negative_profit != 0.00) // Caimos y se recupero
{
m_pico_listo = true;
m_f_check_sup = m_func_base;
Nique_372
2026-10-27 18:07:28 -05:00
#ifdef MORE_INFO_LOSS_PROFIT_DEFINE
Nique_372
2026-11-02 07:16:20 -05:00
FastLog(FUNCION_ACTUAL, INFO_TEXT, "Recovery tracking activated");
Nique_372
2026-10-27 18:07:28 -05:00
#endif
Nique_372
2026-11-02 07:16:20 -05:00
}
Nique_372
2026-10-27 18:07:28 -05:00
}
//--- Perdida
Nique_372
2026-11-02 07:16:20 -05:00
else
Nique_372
2026-10-27 18:07:28 -05:00
{
Nique_372
2026-11-02 07:16:20 -05:00
m_value -= p;
if(!m_strict && p < 0.00 && m_value > m_saved_value)
m_value = m_saved_value;
Nique_372
2026-10-27 18:07:28 -05:00
}
}
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
#endif // MQLARTICLES_ACCOUNT_RM_LOSSPROFIT_BASIC_MAXPROFITS_MQH