forked from nique_372/MQLArticles
//+------------------------------------------------------------------+
| |
//| 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 |
| |
//+------------------------------------------------------------------+
| |
class CLossProfitMaxDaily : public CLossProfitBaseProfit
| |
{
| |
public:
| |
CLossProfitMaxDaily(const ulong magic);
| |
~CLossProfitMaxDaily(void) { if(CBasicEvents::IsActive()) CBasicEvents::UnregisterEvent(&this, TSNQMALRT_BASIEVENT_TYPE_ON_NEW_DAY); }
| |
| |
//---
| |
void OnNewDay(const datetime curr_time) override final;
| |
};
| |
| |
//+------------------------------------------------------------------+
| |
CLossProfitMaxDaily::CLossProfitMaxDaily(const ulong magic)
| |
: CLossProfitBaseProfit(LOSSPROFIT_TYPE_MDP, false, magic)
| |
{
| |
CBasicEvents::RegisterEvent(&this, TSNQMALRT_BASIEVENT_TYPE_ON_NEW_DAY); // Registramos para recibir OnNewDay
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
void CLossProfitMaxDaily::OnNewDay(const datetime curr_time)
| |
{
| |
Set();
| |
m_saved_value = m_value;
| |
}
| |
//+------------------------------------------------------------------+
| |
| |
| |
//+------------------------------------------------------------------+
| |
//| MWP |
| |
//+------------------------------------------------------------------+
| |
class CLossProfitMaxWeekly : public CLossProfitBaseProfit
| |
{
| |
public:
| |
CLossProfitMaxWeekly(const ulong magic);
| |
~CLossProfitMaxWeekly(void) { if(CBasicEvents::IsActive()) CBasicEvents::UnregisterEvent(&this, TSNQMALRT_BASIEVENT_TYPE_ON_NEW_WEEK); }
| |
| |
//---
| |
void OnNewWeek(const datetime curr_time) override final;
| |
};
| |
| |
//+------------------------------------------------------------------+
| |
CLossProfitMaxWeekly::CLossProfitMaxWeekly(const ulong magic)
| |
: CLossProfitBaseProfit(LOSSPROFIT_TYPE_MWP, false, magic)
| |
{
| |
CBasicEvents::RegisterEvent(&this, TSNQMALRT_BASIEVENT_TYPE_ON_NEW_WEEK); // Registramos para recibir OnNewWeek
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
void CLossProfitMaxWeekly::OnNewWeek(const datetime curr_time)
| |
{
| |
Set();
| |
m_saved_value = m_value;
| |
}
| |
//+------------------------------------------------------------------+
| |
| |
| |
| |
//+------------------------------------------------------------------+
| |
//| MMP |
| |
//+------------------------------------------------------------------+
| |
class CLossProfitMaxMon : public CLossProfitBaseProfit
| |
{
| |
public:
| |
CLossProfitMaxMon(const ulong magic);
| |
~CLossProfitMaxMon(void) { if(CBasicEvents::IsActive()) CBasicEvents::UnregisterEvent(&this, TSNQMALRT_BASIEVENT_TYPE_ON_NEW_MONTH); }
| |
| |
//---
| |
void OnNewMonth(const datetime curr_time) override final;
| |
};
| |
| |
| |
//+------------------------------------------------------------------+
| |
CLossProfitMaxMon::CLossProfitMaxMon(const ulong magic)
| |
: CLossProfitBaseProfit(LOSSPROFIT_TYPE_MMP, false, magic)
| |
{
| |
CBasicEvents::RegisterEvent(&this, TSNQMALRT_BASIEVENT_TYPE_ON_NEW_MONTH); // Registramos para recibir OnNewMonth
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
void CLossProfitMaxMon::OnNewMonth(const datetime curr_time)
| |
{
| |
Set();
| |
m_saved_value = m_value;
| |
}
| |
| |
| |
//+------------------------------------------------------------------+
| |
//| MP - Maximum Profit (sin reseteo temporal) |
| |
//+------------------------------------------------------------------+
| |
class CLossProfitMax : public CLossProfitBaseProfit
| |
{
| |
public:
| |
CLossProfitMax(const ulong magic);
| |
~CLossProfitMax(void) {}
| |
};
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
CLossProfitMax::CLossProfitMax(const ulong magic)
| |
: CLossProfitBaseProfit(LOSSPROFIT_TYPE_MP, false, magic)
| |
{
| |
// No registra eventos temporales - tracking continuo sin reseteos
| |
}
| |
//+------------------------------------------------------------------+
| |
| |
| |
| |
| |
//+------------------------------------------------------------------+
| |
//| M desde el bajo |
| |
//+------------------------------------------------------------------+
| |
#define LOSSPROFIT_MAXMON_FLAG_BAJO_LISTO (1)
| |
| |
class CLossProfitMaxDesdeBaajo : public CLossProfitBaseProfit
| |
{
| |
private:
| |
bool m_pico_listo;
| |
double m_negative_profit;
| |
double m_min_negative_profit;
| |
FuncionLossProfitSuperate m_func_base;
| |
| |
//---
| |
void OnSuperated() override final;
| |
| |
public:
| |
CLossProfitMaxDesdeBaajo(const ulong magic);
| |
~CLossProfitMaxDesdeBaajo(void) {}
| |
| |
//---
| |
void OnLossProfit(const double p) override final;
| |
| |
//---
| |
void Init(double _calc_value, FuncionLossProfitSuperate fsup, FTSNMQLArtRmPctgVal fval);
| |
};
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
CLossProfitMaxDesdeBaajo::CLossProfitMaxDesdeBaajo(const ulong magic)
| |
: CLossProfitBaseProfit(LOSSPROFIT_TYPE_MDDBAJO, true, magic), m_func_base(NULL)
| |
, m_negative_profit(0.00), m_min_negative_profit(0.00),
| |
m_pico_listo(false)
| |
{
| |
}
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
void CLossProfitMaxDesdeBaajo::Init(double _calc_value, FuncionLossProfitSuperate fsup, FTSNMQLArtRmPctgVal fval)
| |
{
| |
m_func_base = fsup;
| |
CLossProfit::Init(_calc_value, LossProfitEmptyFuncionSup, fval); // Llamamos a la del padre
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
void CLossProfitMaxDesdeBaajo::OnSuperated()
| |
{
| |
m_pico_listo = false;
| |
m_negative_profit = 0.00;
| |
m_min_negative_profit = 0.00;
| |
m_f_check_sup = LossProfitEmptyFuncionSup;
| |
| |
#ifdef MORE_INFO_LOSS_PROFIT_DEFINE
| |
FastLog(FUNCION_ACTUAL, INFO_TEXT, "Run-up target reached, resetting to search new minimum");
| |
#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
| |
Set();
| |
m_saved_value = m_value;
| |
| |
m_pico_listo = false;
| |
m_min_negative_profit = m_negative_profit;
| |
m_f_check_sup = LossProfitEmptyFuncionSup;
| |
| |
#ifdef MORE_INFO_LOSS_PROFIT_DEFINE
| |
FastLog(FUNCION_ACTUAL, INFO_TEXT, StringFormat("New minimum detected: %.2f, target: %.2f", m_min_negative_profit, m_saved_value));
| |
#endif
| |
}
| |
| |
//---
| |
if(!m_pico_listo)
| |
{
| |
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;
| |
| |
#ifdef MORE_INFO_LOSS_PROFIT_DEFINE
| |
FastLog(FUNCION_ACTUAL, INFO_TEXT, "Recovery tracking activated");
| |
#endif
| |
}
| |
}
| |
//--- Perdida
| |
else
| |
{
| |
m_value -= p;
| |
if(!m_strict && p < 0.00 && m_value > m_saved_value)
| |
m_value = m_saved_value;
| |
}
| |
}
| |
}
| |
//+------------------------------------------------------------------+
| |
//+------------------------------------------------------------------+
| |
#endif // MQLARTICLES_ACCOUNT_RM_LOSSPROFIT_BASIC_MAXPROFITS_MQH
|