MQLArticles/Account/RM/LossProfit/Basic/Classes.mqh
153 行
6 KiB
MQL5
Nique_372
2026-10-27 18:07:28 -05:00
//+------------------------------------------------------------------+
//| Classes.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_CLASESS_MQH
#define MQLARTICLES_ACCOUNT_RM_LOSSPROFIT_BASIC_CLASESS_MQH
//+------------------------------------------------------------------+
//| Include |
//+------------------------------------------------------------------+
Nique_372
2026-10-28 10:48:27 -05:00
#include "..\\Bases\\Base.mqh"
Nique_372
2026-10-27 18:07:28 -05:00
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
namespace TSN
{
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
/*
## Notas:
Stricto:
-True: "Se tiene que recuperar todo, incluso lo perdido"
*/
//+------------------------------------------------------------------+
Nique_372
2026-10-28 10:48:27 -05:00
//| |
Nique_372
2026-10-27 18:07:28 -05:00
//+------------------------------------------------------------------+
Nique_372
2026-10-28 10:48:27 -05:00
class CLossProfitBaseLP : public CLossProfit
Nique_372
2026-10-27 18:07:28 -05:00
{
protected:
Nique_372
2026-10-28 10:48:27 -05:00
bool m_strict; // Strict en calculacion
Nique_372
2026-10-27 18:07:28 -05:00
//---
Nique_372
2026-10-28 10:48:27 -05:00
CLossProfitBaseLP(const int type, const bool act_hook, const ulong magic, const ENUM_LOSS_PROFIT tt);
public:
~CLossProfitBaseLP(void);
Nique_372
2026-10-27 18:07:28 -05:00
//---
Nique_372
2026-10-28 10:48:27 -05:00
__forceinline bool Strict() const { return m_strict; }
void Strict(bool strict) { m_strict = strict; }
Nique_372
2026-10-27 18:07:28 -05:00
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
Nique_372
2026-10-28 10:48:27 -05:00
CLossProfitBaseLP::CLossProfitBaseLP(const int type, const bool act_hook, const ulong magic, const ENUM_LOSS_PROFIT tt)
: CLossProfit(type, act_hook, magic, tt), m_strict(true)
Nique_372
2026-10-27 18:07:28 -05:00
{
//--- Requerimos el denevto OnLossPrfoit para capturar el profit
Nique_372
2026-10-28 10:48:27 -05:00
if(tt != T_GMLPO)
Nique_372
2026-10-28 22:50:57 -05:00
account_status.RegisterEvent(&this, TSNMQLART_ACCST_ETYPE_ON_LOSS_PROFIT);
Nique_372
2026-10-28 10:48:27 -05:00
}
Nique_372
2026-10-27 18:07:28 -05:00
Nique_372
2026-10-28 10:48:27 -05:00
//+------------------------------------------------------------------+
CLossProfitBaseLP::~CLossProfitBaseLP(void)
{
if(m_type_loss_or_profit != T_GMLPO && account_status.IsActive())
Nique_372
2026-10-28 22:50:57 -05:00
account_status.UnregisterEvent(&this, TSNMQLART_ACCST_ETYPE_ON_LOSS_PROFIT);
Nique_372
2026-10-27 18:07:28 -05:00
}
Nique_372
2026-10-28 10:48:27 -05:00
//+------------------------------------------------------------------+
//| Clase base para los profits |
//+------------------------------------------------------------------+
class CLossProfitBaseProfit : public CLossProfitBaseLP
{
protected:
CLossProfitBaseProfit(const int type, const bool act_hook, const ulong magic)
: CLossProfitBaseLP(type, act_hook, magic, T_PROFIT) { }
public:
// Solo eliminamos si no es global..
~CLossProfitBaseProfit(void) {}
//---
void OnLossProfit(const double p) override;
};
Nique_372
2026-10-27 18:07:28 -05:00
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
Nique_372
2026-11-01 16:43:47 -05:00
// caso: limite de gnaica 100
// pero peirdes 200 enonces m_value=300 con strict=recuperamos todo sin strict simpelte le ponemos tope
// osea solo queremos ganar los 100 y no me improta si ese dia perdi 200
Nique_372
2026-10-27 18:07:28 -05:00
void CLossProfitBaseProfit::OnLossProfit(const double p)
{
//---
if(m_magic_number != NOT_MAGIC_NUMBER && m_magic_number != account_status.last_deal_magic)
return;
Nique_372
2026-11-01 16:43:47 -05:00
//--- Reducie siempre
m_value -= p;
Nique_372
2026-10-27 18:07:28 -05:00
//--- Perdida
Nique_372
2026-11-01 16:43:47 -05:00
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
//---
#ifdef MORE_INFO_LOSS_PROFIT_DEFINE
Nique_372
2026-11-02 22:03:44 -05:00
FastLog(FUNCION_ACTUAL, INFO_TEXT, StringFormat("Risk value '%s' updated: %.2f", Name(), m_value));
Nique_372
2026-10-27 18:07:28 -05:00
#endif
}
//+------------------------------------------------------------------+
//| Clase base para los profits |
//+------------------------------------------------------------------+
Nique_372
2026-10-28 10:48:27 -05:00
class CLossProfitBaseLoss : public CLossProfitBaseLP
Nique_372
2026-10-27 18:07:28 -05:00
{
protected:
//--- Aqui para impedir instanciacion
Nique_372
2026-10-28 10:48:27 -05:00
CLossProfitBaseLoss(const int type, const bool act_hook, const ulong magic)
: CLossProfitBaseLP(type, act_hook, magic, ((type == LOSSPROFIT_TYPE_GMLPO) ? T_GMLPO : T_LOSS)) {}
Nique_372
2026-10-27 18:07:28 -05:00
public:
Nique_372
2026-10-28 10:48:27 -05:00
~CLossProfitBaseLoss(void) {}
Nique_372
2026-10-27 18:07:28 -05:00
//---
void OnLossProfit(const double p) override;
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CLossProfitBaseLoss::OnLossProfit(const double p)
{
//---
if(m_magic_number != NOT_MAGIC_NUMBER && m_magic_number != account_status.last_deal_magic)
return;
Nique_372
2026-11-01 16:43:47 -05:00
//--- Aumenta siempre
m_value += p;
//--- condiciones:
// 1. Modo estricto.. en el modo no estricto "se le deja fluir"
// 2. Tiene que haber profit (ahi es donde cuidadimos para fijar un tope de lo maximo qeu peude perder o si acomula las ganacias)
// 3. en caso supere saved value... entonces lo truncamos.
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
//---
#ifdef MORE_INFO_LOSS_PROFIT_DEFINE
Nique_372
2026-11-02 22:03:44 -05:00
FastLog(FUNCION_ACTUAL, INFO_TEXT, StringFormat("Risk value '%s' updated: %.2f", Name(), m_value));
Nique_372
2026-10-27 18:07:28 -05:00
#endif
}
}
//+------------------------------------------------------------------+
#endif // MQLARTICLES_ACCOUNT_RM_LOSSPROFIT_BASIC_CLASESS_MQH