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 |
|
| | | //+------------------------------------------------------------------+
|
2026-10-28 10:48:27 -05:00 | | | #include "..\\Bases\\Base.mqh"
|
2026-10-27 18:07:28 -05:00 | | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | namespace TSN
|
| | | {
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | /*
|
| | | ## Notas:
|
| | |
|
| | | Stricto:
|
| | | -True: "Se tiene que recuperar todo, incluso lo perdido"
|
| | | */
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-10-28 10:48:27 -05:00 | | | //| |
|
2026-10-27 18:07:28 -05:00 | | | //+------------------------------------------------------------------+
|
2026-10-28 10:48:27 -05:00 | | | class CLossProfitBaseLP : public CLossProfit
|
2026-10-27 18:07:28 -05:00 | | | {
|
| | | protected:
|
2026-10-28 10:48:27 -05:00 | | | bool m_strict; // Strict en calculacion
|
2026-10-27 18:07:28 -05:00 | | |
|
| | | //---
|
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);
|
2026-10-27 18:07:28 -05:00 | | |
|
| | | //---
|
2026-10-28 10:48:27 -05:00 | | | __forceinline bool Strict() const { return m_strict; }
|
| | | void Strict(bool strict) { m_strict = strict; }
|
2026-10-27 18:07:28 -05:00 | | | };
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
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)
|
2026-10-27 18:07:28 -05:00 | | | {
|
| | | //--- Requerimos el denevto OnLossPrfoit para capturar el profit
|
2026-10-28 10:48:27 -05:00 | | | if(tt != T_GMLPO)
|
2026-10-28 22:50:57 -05:00 | | | account_status.RegisterEvent(&this, TSNMQLART_ACCST_ETYPE_ON_LOSS_PROFIT);
|
2026-10-28 10:48:27 -05:00 | | | }
|
2026-10-27 18:07:28 -05:00 | | |
|
2026-10-28 10:48:27 -05:00 | | | //+------------------------------------------------------------------+
|
| | | CLossProfitBaseLP::~CLossProfitBaseLP(void)
|
| | | {
|
| | | if(m_type_loss_or_profit != T_GMLPO && account_status.IsActive())
|
2026-10-28 22:50:57 -05:00 | | | account_status.UnregisterEvent(&this, TSNMQLART_ACCST_ETYPE_ON_LOSS_PROFIT);
|
2026-10-27 18:07:28 -05:00 | | | }
|
| | |
|
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;
|
| | | };
|
| | |
|
2026-10-27 18:07:28 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
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
|
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;
|
| | |
|
2026-11-01 16:43:47 -05:00 | | | //--- Reducie siempre
|
| | | m_value -= p;
|
| | |
|
2026-10-27 18:07:28 -05:00 | | | //--- Perdida
|
2026-11-01 16:43:47 -05:00 | | | if(!m_strict && p < 0.00 && m_value > m_saved_value)
|
| | | m_value = m_saved_value;
|
2026-10-27 18:07:28 -05:00 | | |
|
| | | //---
|
| | | #ifdef MORE_INFO_LOSS_PROFIT_DEFINE
|
2026-11-02 22:03:44 -05:00 | | | FastLog(FUNCION_ACTUAL, INFO_TEXT, StringFormat("Risk value '%s' updated: %.2f", Name(), m_value));
|
2026-10-27 18:07:28 -05:00 | | | #endif
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| Clase base para los profits |
|
| | | //+------------------------------------------------------------------+
|
2026-10-28 10:48:27 -05:00 | | | class CLossProfitBaseLoss : public CLossProfitBaseLP
|
2026-10-27 18:07:28 -05:00 | | | {
|
| | | protected:
|
| | | //--- Aqui para impedir instanciacion
|
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)) {}
|
2026-10-27 18:07:28 -05:00 | | | public:
|
2026-10-28 10:48:27 -05:00 | | | ~CLossProfitBaseLoss(void) {}
|
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;
|
| | |
|
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;
|
2026-10-27 18:07:28 -05:00 | | |
|
| | | //---
|
| | | #ifdef MORE_INFO_LOSS_PROFIT_DEFINE
|
2026-11-02 22:03:44 -05:00 | | | FastLog(FUNCION_ACTUAL, INFO_TEXT, StringFormat("Risk value '%s' updated: %.2f", Name(), m_value));
|
2026-10-27 18:07:28 -05:00 | | | #endif
|
| | | }
|
| | | }
|
| | | //+------------------------------------------------------------------+
|
| | | #endif // MQLARTICLES_ACCOUNT_RM_LOSSPROFIT_BASIC_CLASESS_MQH
|