forked from nique_372/MQLArticles
//+------------------------------------------------------------------+
| |
//| 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 |
| |
//+------------------------------------------------------------------+
| |
#include "..\\Bases\\Base.mqh"
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
namespace TSN
| |
{
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
/*
| |
## Notas:
| |
| |
Stricto:
| |
-True: "Se tiene que recuperar todo, incluso lo perdido"
| |
*/
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
class CLossProfitBaseLP : public CLossProfit
| |
{
| |
protected:
| |
bool m_strict; // Strict en calculacion
| |
| |
//---
| |
CLossProfitBaseLP(const int type, const bool act_hook, const ulong magic, const ENUM_LOSS_PROFIT tt);
| |
public:
| |
~CLossProfitBaseLP(void);
| |
| |
//---
| |
__forceinline bool Strict() const { return m_strict; }
| |
void Strict(bool strict) { m_strict = strict; }
| |
};
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
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)
| |
{
| |
//--- Requerimos el denevto OnLossPrfoit para capturar el profit
| |
if(tt != T_GMLPO)
| |
account_status.RegisterEvent(&this, TSNMQLART_ACCST_ETYPE_ON_LOSS_PROFIT);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
CLossProfitBaseLP::~CLossProfitBaseLP(void)
| |
{
| |
if(m_type_loss_or_profit != T_GMLPO && account_status.IsActive())
| |
account_status.UnregisterEvent(&this, TSNMQLART_ACCST_ETYPE_ON_LOSS_PROFIT);
| |
}
| |
| |
| |
//+------------------------------------------------------------------+
| |
//| 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;
| |
};
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
// 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
| |
void CLossProfitBaseProfit::OnLossProfit(const double p)
| |
{
| |
//---
| |
if(m_magic_number != NOT_MAGIC_NUMBER && m_magic_number != account_status.last_deal_magic)
| |
return;
| |
| |
//--- Reducie siempre
| |
m_value -= p;
| |
| |
//--- Perdida
| |
if(!m_strict && p < 0.00 && m_value > m_saved_value)
| |
m_value = m_saved_value;
| |
| |
//---
| |
#ifdef MORE_INFO_LOSS_PROFIT_DEFINE
| |
FastLog(FUNCION_ACTUAL, INFO_TEXT, StringFormat("Risk value '%s' updated: %.2f", Name(), m_value));
| |
#endif
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| Clase base para los profits |
| |
//+------------------------------------------------------------------+
| |
class CLossProfitBaseLoss : public CLossProfitBaseLP
| |
{
| |
protected:
| |
//--- Aqui para impedir instanciacion
| |
CLossProfitBaseLoss(const int type, const bool act_hook, const ulong magic)
| |
: CLossProfitBaseLP(type, act_hook, magic, ((type == LOSSPROFIT_TYPE_GMLPO) ? T_GMLPO : T_LOSS)) {}
| |
public:
| |
~CLossProfitBaseLoss(void) {}
| |
| |
//---
| |
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;
| |
| |
//--- 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;
| |
| |
//---
| |
#ifdef MORE_INFO_LOSS_PROFIT_DEFINE
| |
FastLog(FUNCION_ACTUAL, INFO_TEXT, StringFormat("Risk value '%s' updated: %.2f", Name(), m_value));
| |
#endif
| |
}
| |
}
| |
//+------------------------------------------------------------------+
| |
#endif // MQLARTICLES_ACCOUNT_RM_LOSSPROFIT_BASIC_CLASESS_MQH
|