2026-10-27 18:07:28 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| Def.mqh |
|
| | | //| Copyright 2026, Niquel Mendoza. |
|
| | | //| https://www.mql5.com |
|
| | | //+------------------------------------------------------------------+
|
| | | #property copyright "Copyright 2026, Niquel Mendoza."
|
| | | #property link "https://www.mql5.com"
|
| | | #property strict
|
| | |
|
| | | #ifndef MQLARTICLES_ACCOUNT_RM_LOSSPROFIT_BASES_DEF_MQH
|
| | | #define MQLARTICLES_ACCOUNT_RM_LOSSPROFIT_BASES_DEF_MQH
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| Include |
|
| | | //+------------------------------------------------------------------+
|
2026-10-27 22:04:41 -05:00 | | | #include "..\\..\\\..\\MoneyStatus\\Manager.mqh"
|
| | | #include "..\\\..\\Bases\\Functions.mqh"
|
2026-10-27 18:07:28 -05:00 | | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | namespace TSN
|
| | | {
|
| | | //+------------------------------------------------------------------+
|
| | | //| Defines |
|
| | | //+------------------------------------------------------------------+
|
2026-10-27 22:04:41 -05:00 | | | //---
|
| | | class CLossProfit; // Class to handle maximum losses or gains
|
| | | class CLossProfitManager; // Container class to manage CLossProfit objects
|
| | |
|
| | |
|
| | | //---
|
2026-10-27 18:07:28 -05:00 | | | #define MAX_VAL_DEFINES_CLOSS_PROFIT (DBL_MAX)
|
2026-11-07 21:17:58 -05:00 | | | #define MIN_VAL_DEFINES_CLOSE_PROFIT (0.0)
|
| | |
|
| | | //---
|
| | | #define TSNMQLART_ACCST_RMLP_DYNCTYPE_NEG (0)
|
| | | #define TSNMQLART_ACCST_RMLP_DYNCTYPE_POS (1)
|
| | | #define TSNMQLART_ACCST_RMLP_DYNCTYPE_NEG_POS (2)
|
| | | #define TSNMQLART_ACCST_RMLP_DYNCTYPE_INV (3)
|
2026-10-27 18:07:28 -05:00 | | |
|
| | | //---
|
| | | __forceinline bool LossProfitEmptyFuncionSup(const double value, const double saved_value, void* ptr) { return false; }
|
| | |
|
| | | //---
|
| | | enum ENUM_TYPE_LOSS_PROFIT
|
| | | {
|
| | | LP_GMLPO = 0, // Maxima perdida por operacion (base % a arriesgar)
|
2026-10-28 13:32:56 -05:00 | | |
|
| | | //---
|
2026-10-27 18:07:28 -05:00 | | | LP_MDL, // Maxima perdida diaria
|
| | | LP_MWL, // Maxima perdida semanal
|
| | | LP_MML, // Maxima perdida mensual
|
| | | LP_ML, // Maxima perdida total
|
| | | LP_ML_PICO, // Maxima perdida desde el pico
|
2026-10-28 13:32:56 -05:00 | | |
|
| | | //---
|
2026-10-27 18:07:28 -05:00 | | | LP_MDP, // Maxima ganancia diaria
|
| | | LP_MWP, // Maxima ganancia semanal
|
| | | LP_MMP, // Maxima ganancia mensual
|
| | | LP_MP, // Maxima ganancia total
|
| | | LP_MP_BAJO, // Maxima ganancia desde el bajo
|
2026-10-28 13:32:56 -05:00 | | |
|
| | | //---
|
2026-10-27 19:06:42 -05:00 | | | LP_TOTAL, // Total
|
2026-10-27 18:07:28 -05:00 | | | };
|
| | |
|
2026-11-02 06:40:25 -05:00 | | | //---
|
2026-11-02 07:16:20 -05:00 | | | TSNSTD_STATIC_ASSERT(LP_GMLPO == 0
|
| | | && LP_MDL == 1 && LP_MWL == 2 && LP_MML == 3 && LP_ML == 4 && LP_ML_PICO == 5
|
2026-11-02 06:40:25 -05:00 | | | && LP_MDP == 6 && LP_MWP == 7 && LP_MMP == 8 && LP_MP == 9 && LP_MP_BAJO == 10 && LP_TOTAL == 11,
|
| | | tsnqmalrt_rm_lp_check_values)
|
| | |
|
2026-11-02 21:51:46 -05:00 | | | //--- NOTA: solo funciona para las perdidas\ganancias en base a preiodos (Diario,Semanal,Mensual)
|
2026-11-02 07:16:20 -05:00 | | | // los demas pico y total cada uno decidie como lo maneja
|
| | | // dado que depende de como lo tomes peudes hacer varias cosas.
|
2026-11-02 06:40:25 -05:00 | | | #define TSNMQLART_RM_LP_M_BEVENTS_F_LOSS(LP_TYPE) BASICEVENT_REF_FLAG_MAKE((LP_TYPE)-TSN::LP_MDL)
|
| | | #define TSNMQLART_RM_LP_M_BEVENTS_F_PROFIT(LP_TYPE) BASICEVENT_REF_FLAG_MAKE((LP_TYPE)-TSN::LP_MDP)
|
| | |
|
2026-10-28 13:32:56 -05:00 | | | //---
|
| | | enum ENUM_LOSS_PROFIT
|
| | | {
|
| | | T_LOSS,
|
| | | T_PROFIT,
|
| | | T_GMLPO
|
| | | };
|
2026-10-27 18:07:28 -05:00 | | |
|
| | | //--- Tipos basicos
|
2026-10-27 19:06:42 -05:00 | | | #define LOSSPROFIT_TYPE_GMLPO (LP_GMLPO) // Tipo base % a arriesgar
|
2026-10-27 18:07:28 -05:00 | | |
|
| | | //---
|
2026-10-27 19:06:42 -05:00 | | | #define LOSSPROFIT_TYPE_MDL (LP_MDL) // Maxima perdida diaria
|
| | | #define LOSSPROFIT_TYPE_MWL (LP_MWL) // Maxima perdida semanal
|
| | | #define LOSSPROFIT_TYPE_MML (LP_MML) // Maxima perdida mensual
|
| | | #define LOSSPROFIT_TYPE_ML (LP_ML) // Maxima perdida
|
2026-10-27 18:07:28 -05:00 | | | #define LOSSPROFIT_TYPE_MDDPICO (LP_ML_PICO) // Maxima perdida desde nuevo pico de la cuenta
|
| | |
|
| | | //---
|
2026-10-27 19:06:42 -05:00 | | | #define LOSSPROFIT_TYPE_MDP (LP_MDP) // Maxima ganancia diaria
|
| | | #define LOSSPROFIT_TYPE_MWP (LP_MWP) // Maxima ganancia semanal
|
| | | #define LOSSPROFIT_TYPE_MMP (LP_MMP) // Maxima ganancia mensual
|
| | | #define LOSSPROFIT_TYPE_MP (LP_MP) // Maxima ganancia
|
2026-10-27 18:07:28 -05:00 | | | #define LOSSPROFIT_TYPE_MDDBAJO (LP_MP_BAJO) // Maxima ganancia desde el bajo de la cuenta
|
| | |
|
| | | //--- Losses Profits
|
2026-10-27 19:06:42 -05:00 | | | #define LOSS_PROFIT_COUNT (LP_TOTAL)
|
2026-10-27 18:07:28 -05:00 | | | #define LOSS_PROFIT_COUNT_MAXTYPE (6)
|
| | |
|
| | | //---
|
| | | const string g_mqarticles_lp_str_names[LOSS_PROFIT_COUNT]
|
| | | {
|
| | | "GMLPO",
|
| | | "Maxium daily loss",
|
| | | "Maxium weekly loss",
|
| | | "Maxium monthly loss",
|
| | | "Maxium loss",
|
| | | "Maxium loss PICO",
|
| | | "Maxium daily profit",
|
| | | "Maxium weekly profit",
|
| | | "Maxium monthly profit",
|
| | | "Maxium profit",
|
| | | "Maxium profit BAJO",
|
| | | };
|
| | |
|
| | | //---
|
| | | #ifndef TSN_MQLART_RM_LP_NAME
|
| | | #define TSN_MQLART_RM_LP_NAME(TYPE) g_mqarticles_lp_str_names[TYPE]
|
| | | #endif // TSN_MQLART_RM_LP_NAME
|
| | |
|
| | |
|
| | | //---
|
| | | enum ENUM_TSNMQLART_RM_LP_RES
|
| | | {
|
| | | TSNMQLART_RM_LP_RES_OK,
|
| | |
|
| | | //---
|
| | | TSNMQLART_RM_LP_RES_LPDYNC_ERR_INVALID_SIZE,
|
2026-11-07 09:32:25 -05:00 | | | TSNMQLART_RM_LP_RES_LPDYNC_ERR_MALFORMED_VALUES,
|
2026-10-27 18:07:28 -05:00 | | | TSNMQLART_RM_LP_RES_LPDYNC_ERR_SIZE_NOT_EQ_ARRS,
|
| | |
|
2026-10-27 19:06:42 -05:00 | | | TSNMQLART_RM_LP_RES_LPDYNC_ERR_INVALID_CACHE,
|
2026-11-02 21:51:46 -05:00 | | | TSNMQLART_RM_LP_RES_LPDYNC_ERR_INVALID_VALUE_DYNC_PCTG,
|
| | | TSNMQLART_RM_LP_RES_LPDYNC_ERR_DYN_PCTG_ADD_HASHMAP
|
2026-10-28 16:35:48 -05:00 | | | };
|
2026-10-27 19:06:42 -05:00 | | |
|
2026-10-28 16:35:48 -05:00 | | | //--- Dynamic gmlpo/ Dynamic risk per operation
|
| | | struct Dynamic_LossProfit
|
| | | {
|
| | | double balance_to_activate_the_risk[];
|
| | | double risk_to_be_adjusted[];
|
| | | };
|
| | |
|
| | |
|
| | | //--- Enumeration to define the types of calculation of the value of maximum profits and losses
|
| | | enum ENUM_RISK_CALCULATION_MODE
|
| | | {
|
| | | money = 0, //Money
|
| | | percentage //Percentage %
|
2026-10-27 18:07:28 -05:00 | | | };
|
| | |
|
2026-10-28 16:35:48 -05:00 | | | //---
|
| | | const string RiskCalcModeToString[2]
|
| | | {
|
| | | "Money",
|
| | | "Percentage"
|
| | | };
|
| | |
|
| | | //--- Enumeration to define the value to which the percentages will be applied
|
| | | enum ENUM_APPLIED_PERCENTAGES
|
| | | {
|
| | | Balance = 0, // Balance
|
| | | ganancianeta, // Net profit
|
| | | free_margin, // Free margin
|
| | | equity // Equity
|
| | | };
|
| | |
|
| | |
|
2026-10-27 18:07:28 -05:00 | | | //---
|
| | | // #define MQLARTICLES_RM_LOSSPROFIT_ACTIVEGUARDS
|
2026-10-28 16:35:48 -05:00 | | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | //--- typedef
|
| | | // Superate
|
| | | typedef bool (*FuncionLossProfitSuperate)(const double, const double, void*);
|
| | | // Calculate percentage value (recibe el porcentage)
|
| | | // [calc value], [ptr]
|
| | | typedef double (*FTSNMQLArtRmPctgVal)(double, void*);
|
| | |
|
2026-11-02 06:40:25 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-11-05 12:56:42 -05:00 | | | #define TSNMQLART_RISKM_NORM_PERCERNTAGE(P) (P/100.0)
|
| | | #define TSNMQLART_RISKM_NORM_PERCERNTAGE_A(P) P/=100.0
|
| | | #define TSNMQLART_RISKM_NORM_TO_PERCENTAGE(P) (P*100.0)
|
2026-11-02 06:40:25 -05:00 | | |
|
2026-10-28 16:35:48 -05:00 | | | //---
|
2026-10-27 18:07:28 -05:00 | | | }
|
| | |
|
| | |
|
| | | #endif // MQLARTICLES_ACCOUNT_RM_LOSSPROFIT_BASES_DEF_MQH
|
| | | //+------------------------------------------------------------------+
|