2025-09-22 09:09:20 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| RM_Defines.mqh |
|
| | | //| Niquel y Leo, Copyright 2025 |
|
| | | //| https://www.mql5.com |
|
| | | //+------------------------------------------------------------------+
|
| | | #property copyright "Niquel y Leo, Copyright 2025"
|
| | | #property link "https://www.mql5.com"
|
| | | #property strict
|
| | |
|
2025-11-10 09:33:30 -05:00 | | | #ifndef MQLARTICLES_RM_RDEFINES_MQH
|
| | | #define MQLARTICLES_RM_RDEFINES_MQH
|
2025-09-22 09:09:20 -05:00 | | |
|
2026-09-12 19:41:52 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | namespace TSN
|
| | | {
|
2025-09-22 09:09:20 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| Defines |
|
| | | //+------------------------------------------------------------------+
|
| | | #define NOT_MAGIC_NUMBER 2//Not Magic Number
|
| | | #define FLAG_CLOSE_ALL_PROFIT 2 //Flag indicating to close only operations with profit
|
| | | #define FLAG_CLOSE_ALL_LOSS 4 //Flag indicating to close only operations without profit
|
| | |
|
| | | //--- positions
|
| | | #define FLAG_POSITION_TYPE_BUY 8
|
| | | #define FLAG_POSITION_TYPE_SELL 16
|
| | |
|
| | | //--- orders
|
2026-09-12 19:41:52 -05:00 | | | /*
|
| | | 2025.08.06 16:50:41.989 GetID (XAUUSD,M1) ORDER_TYPE_BUY = 0
|
| | | 2025.08.06 16:50:41.989 GetID (XAUUSD,M1) ORDER_TYPE_SELL = 1
|
| | | 2025.08.06 16:50:41.989 GetID (XAUUSD,M1) ORDER_TYPE_BUY_LIMIT = 2
|
| | | 2025.08.06 16:50:41.989 GetID (XAUUSD,M1) ORDER_TYPE_SELL_LIMIT = 3
|
| | | 2025.08.06 16:50:41.989 GetID (XAUUSD,M1) ORDER_TYPE_BUY_STOP = 4
|
| | | 2025.08.06 16:50:41.989 GetID (XAUUSD,M1) ORDER_TYPE_SELL_STOP = 5
|
| | | 2025.08.06 16:50:41.989 GetID (XAUUSD,M1) ORDER_TYPE_BUY_STOP_LIMIT = 6
|
| | | 2025.08.06 16:50:41.989 GetID (XAUUSD,M1) ORDER_TYPE_SELL_STOP_LIMIT = 7
|
| | | 2025.08.06 16:50:41.989 GetID (XAUUSD,M1) ORDER_TYPE_CLOSE_BY = 8
|
| | | */
|
| | |
|
| | | //- to
|
| | | #define MQLArticles_OrderToFlag(v) (1<<v)
|
| | |
|
| | | //- is
|
| | | #define MQLArticles_IsPendingOrder(v) (v>1&&v<8)
|
| | |
|
| | | //- f
|
2025-09-22 09:09:20 -05:00 | | | #define FLAG_ORDER_TYPE_BUY 1
|
| | | #define FLAG_ORDER_TYPE_SELL 2
|
| | | #define FLAG_ORDER_TYPE_BUY_LIMIT 4
|
| | | #define FLAG_ORDER_TYPE_SELL_LIMIT 8
|
| | | #define FLAG_ORDER_TYPE_BUY_STOP 16
|
| | | #define FLAG_ORDER_TYPE_SELL_STOP 32
|
| | | #define FLAG_ORDER_TYPE_BUY_STOP_LIMIT 64
|
| | | #define FLAG_ORDER_TYPE_SELL_STOP_LIMIT 128
|
| | | #define FLAG_ORDER_TYPE_CLOSE_BY 256
|
| | |
|
2026-09-12 19:41:52 -05:00 | | |
|
| | |
|
2025-09-22 09:09:20 -05:00 | | | //---
|
| | | #define RISK_MANGEMENT_LOSS_PROFIT_MIN_VALUE 1e-4
|
| | |
|
| | |
|
| | | //--- Tickets
|
| | | #define INVALID_TICKET 0
|
| | | //+------------------------------------------------------------------+
|
| | | //| Enumerations |
|
| | | //+------------------------------------------------------------------+
|
| | | enum ENUM_LOTE_TYPE //lot type
|
| | | {
|
| | | Dinamico,//Dynamic
|
| | | Fijo//Fixed
|
| | | };
|
| | |
|
| | | //--- Enumeration to define the types of calculation of the value of maximum profits and losses
|
| | | enum ENUM_RISK_CALCULATION_MODE
|
| | | {
|
2025-09-24 14:00:58 -05:00 | | | money = 0, //Money
|
2025-09-22 09:09:20 -05:00 | | | percentage //Percentage %
|
| | | };
|
| | |
|
2025-09-24 14:00:58 -05:00 | | | const string RiskCalcModeToString[2]
|
| | | {
|
| | | "Money",
|
| | | "Percentage"
|
| | | };
|
| | |
|
2025-09-22 09:09:20 -05:00 | | | //--- Enumeration to define the type of risk management
|
| | | enum ENUM_MODE_RISK_MANAGEMENT
|
| | | {
|
2026-01-28 12:07:20 -05:00 | | | risk_mode_propfirm_dynamic_daiy_loss = 0, //Prop Firm (FTMO-FundendNext)
|
2025-09-22 09:09:20 -05:00 | | | risk_mode_personal_account // Personal Account
|
| | | };
|
| | |
|
| | | //--- Enumeration to define the value to which the percentages will be applied
|
| | | enum ENUM_APPLIED_PERCENTAGES
|
| | | {
|
| | | Balance = 0, //Balance
|
| | | ganancianeta = 1,//Net profit
|
| | | free_margin = 2, //Free margin
|
| | | equity = 3 //Equity
|
| | | };
|
| | |
|
| | | //--- Enumeration for ways to obtain the lot
|
| | | enum ENUM_GET_LOT
|
| | | {
|
| | | GET_LOT_BY_ONLY_RISK_PER_OPERATION, //Obtain the lot for the risk per operation
|
| | | GET_LOT_BY_STOPLOSS_AND_RISK_PER_OPERATION //Obtain and adjust the lot through the risk per operation and stop loss respectively.
|
| | | };
|
| | |
|
| | | //--- Enumeration of the types of dynamic operational risk
|
| | | enum ENUM_OF_DYNAMIC_MODES_OF_GMLPO
|
| | | {
|
| | | DYNAMIC_GMLPO_FULL_CUSTOM, //Customisable dynamic risk per operation
|
| | | DYNAMIC_GMLPO_FIXED_PARAMETERS,//Risk per operation with fixed parameters
|
| | | NO_DYNAMIC_GMLPO //No dynamic risk for risk per operation
|
| | | };
|
| | |
|
2026-01-28 12:07:20 -05:00 | | | //---
|
2025-09-22 09:09:20 -05:00 | | | enum ENUM_LOSS_PROFIT
|
| | | {
|
| | | T_LOSS,
|
| | | T_PROFIT,
|
| | | T_GMLPO
|
| | | };
|
| | |
|
2026-01-28 12:07:20 -05:00 | | | //---
|
| | | // Esto es solo para RiskManagement ojito
|
2025-09-22 09:09:20 -05:00 | | | enum ENUM_TYPE_LOSS_PROFIT
|
2026-05-28 12:01:58 -05:00 | | | {
|
2026-01-28 12:07:20 -05:00 | | | LP_GMLPO = 0, // Maxima perdida por operacion (base % a arriesgar)
|
| | | LP_MDL = 1, // Maxima perdida diaria
|
| | | LP_MWL = 2, // Maxima perdida semanal
|
| | | LP_MML = 3, // Maxima perdida mensual
|
| | | LP_ML = 4, // Maxima perdida total
|
| | | LP_ML_PICO = 5, // Maxima perdida desde el pico
|
| | | LP_MDP = 6, // Maxima ganancia diaria
|
| | | LP_MWP = 7, // Maxima ganancia semanal
|
| | | LP_MMP = 8, // Maxima ganancia mensual
|
| | | LP_MP = 9, // Maxima ganancia total
|
| | | LP_MP_BAJO = 10 // Maxima ganancia desde el bajo
|
2026-05-28 12:01:58 -05:00 | | | };
|
2025-09-22 09:09:20 -05:00 | | |
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| Structures |
|
| | | //+------------------------------------------------------------------+
|
| | | //--- Positions
|
2025-10-26 20:52:13 -05:00 | | | struct pack(sizeof(double)) Position //remove pack if it increases to +4bytes
|
2025-09-22 09:09:20 -05:00 | | | {
|
| | | ulong ticket; //position ticket
|
2025-10-26 20:52:13 -05:00 | | | ulong magic; //magic number with which it was opened
|
| | | double profit; //last recorded profit
|
| | | double open_price; //opening price
|
2025-11-23 08:04:16 -05:00 | | | double sl; //stop loss
|
| | | double tp; //take profit
|
2025-10-26 20:52:13 -05:00 | | | datetime open_time; //opening time
|
2025-11-26 07:03:20 -05:00 | | | double volume;
|
2025-09-22 09:09:20 -05:00 | | | ENUM_POSITION_TYPE type; //position type
|
| | | };
|
2025-11-23 08:04:16 -05:00 | | |
|
| | | // Notes: The tp/sl of the position is only modified if the CACCOUNT_STATUS_ACTIVE_ON_POSITION_MODIFIED statement is defined.
|
| | | // Otherwise, only the tp/sl stores the first registered tp and sl.
|
| | |
|
| | | //--- Order (OnOrderAdd | OnOrderUpdate | OnOrderDelete)
|
2026-05-28 12:01:58 -05:00 | | | struct pack(sizeof(double)) ROrder
|
2025-09-22 09:09:20 -05:00 | | | {
|
2025-11-23 08:04:16 -05:00 | | | double order_open_price; // order open price
|
| | | double order_stop_loss; // order stop loss
|
| | | double order_take_profit; // order take profit
|
| | | ulong order_magic; //magic number of the order
|
| | | ulong order_ticket; //order ticket
|
| | | datetime order_time_expiration; // order expiration time
|
| | | ENUM_ORDER_REASON order_reason; // order reason
|
| | | ENUM_ORDER_TYPE order_type; //order type
|
| | | ENUM_ORDER_STATE order_state; //order state
|
| | | ENUM_ORDER_TYPE_TIME order_type_time; // order type time
|
2025-09-22 09:09:20 -05:00 | | | };
|
2025-11-23 08:04:16 -05:00 | | |
|
2025-09-22 09:09:20 -05:00 | | | //---
|
2026-05-28 12:01:58 -05:00 | | | struct pack(8) RAccountProfit
|
2025-09-22 09:09:20 -05:00 | | | {
|
2026-09-12 19:41:52 -05:00 | | | //--- Account
|
2026-05-28 12:01:58 -05:00 | | | double account_profit_diario; // Account daily profit
|
| | | double account_profit_semanal; // Account weekly profit
|
| | | double account_profit_total; // Account total profit
|
| | | double account_profit_mensual; // Account monthly profit
|
| | | double account_balance; // Account balance
|
2025-09-22 09:09:20 -05:00 | | | };
|
2025-11-23 08:04:16 -05:00 | | |
|
2026-05-28 12:01:58 -05:00 | | |
|
2025-09-22 09:09:20 -05:00 | | | //---
|
2026-05-28 12:01:58 -05:00 | | | struct ROnOpenPosition : RAccountProfit
|
2025-09-22 09:09:20 -05:00 | | | {
|
2025-10-26 20:52:13 -05:00 | | | //--- Position
|
2025-09-22 09:09:20 -05:00 | | | Position position;
|
2025-11-23 08:04:16 -05:00 | | |
|
2025-10-26 20:52:13 -05:00 | | | //--- Deal
|
| | | ulong deal_ticket; // Ticket
|
| | | double deal_profit; // Profit
|
| | | ENUM_DEAL_REASON deal_reason; // Reason
|
| | | ENUM_DEAL_ENTRY deal_entry_type; // Entry type
|
2026-05-28 12:01:58 -05:00 | | | };
|
2025-11-23 08:04:16 -05:00 | | |
|
2026-05-28 12:01:58 -05:00 | | | //---
|
| | | struct ROnClosePosition : ROnOpenPosition
|
| | | {
|
2025-10-26 20:52:13 -05:00 | | | ulong magic_number_closed; // Magic number at position close
|
2025-09-22 09:09:20 -05:00 | | | };
|
2025-11-23 08:04:16 -05:00 | | |
|
2026-05-28 12:01:58 -05:00 | | |
|
| | |
|
2025-09-22 09:09:20 -05:00 | | | //--- Loss/Profit
|
| | | struct Loss_Profit
|
| | | {
|
| | | double value; //value
|
2025-11-26 07:03:20 -05:00 | | | double calculation_value; //calculation value (percentage or money)
|
2025-09-22 09:09:20 -05:00 | | | ENUM_APPLIED_PERCENTAGES percentage_applied_to; //percentage applied to
|
| | | };
|
2025-11-23 08:04:16 -05:00 | | |
|
2025-10-26 20:52:13 -05:00 | | | //--- Dynamic gmlpo/ Dynamic risk per operation
|
2025-09-22 09:09:20 -05:00 | | | struct Dynamic_LossProfit
|
| | | {
|
| | | double balance_to_activate_the_risk[];
|
| | | double risk_to_be_adjusted[];
|
| | | };
|
2025-11-23 08:04:16 -05:00 | | |
|
2025-09-22 09:09:20 -05:00 | | | //---
|
| | | struct RiskParams
|
| | | {
|
| | | ENUM_MODE_RISK_MANAGEMENT mode;
|
| | | MqlParam params[];
|
| | | };
|
2025-11-23 08:04:16 -05:00 | | |
|
2025-09-22 09:09:20 -05:00 | | | //---
|
| | | struct ModfierInitInfo
|
| | | {
|
| | | double balance;
|
| | | ulong magic;
|
| | | };
|
| | |
|
2026-05-28 12:01:58 -05:00 | | | //---
|
| | | struct ModifierOnOpenCloseStruct
|
| | | {
|
| | | //--- Last deal info
|
| | | ulong deal_ticket; // Deal ticket
|
| | | double deal_profit; // Deal profit
|
| | | ENUM_DEAL_REASON deal_reason; // Deal reason
|
| | | ENUM_DEAL_ENTRY deal_entry_type; // Deal entry type
|
| | |
|
| | | //--- Magic number profit
|
| | | double profit_diario; // Daily profit regarding the magic number of (RiskManagement)
|
| | | double profit_semanal; // Weekly profit regarding the magic number of (RiskManagement)
|
| | | double profit_total; // Total profit regarding the magic number of (RiskManagement)
|
| | | double profit_mensual; // Monthly profit regarding the magic number of (RiskManagement)
|
| | |
|
| | | //--- Open position info or closed position info
|
| | | Position position;
|
2026-09-12 19:41:52 -05:00 | | | };
|
2025-09-22 09:09:20 -05:00 | | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| Arrays para las ordenes |
|
| | | //+------------------------------------------------------------------+
|
2026-09-12 19:41:52 -05:00 | | | /*
|
2025-09-22 09:09:20 -05:00 | | | const bool EsUnaOrderPendiente[9]
|
| | | {
|
| | | false, // 0
|
| | | false, // 1
|
| | | true, // 2
|
| | | true, // 3
|
| | | true, // 4
|
| | | true, // 4
|
| | | true, // 5
|
| | | true, // 7
|
| | | false // 8
|
2026-09-12 19:41:52 -05:00 | | | };*/
|
| | | /*
|
2025-09-22 09:09:20 -05:00 | | | const int OrdensToFlagArray[9] =
|
| | | {
|
| | | FLAG_ORDER_TYPE_BUY, // 0
|
| | | FLAG_ORDER_TYPE_SELL, // 1
|
| | | FLAG_ORDER_TYPE_BUY_LIMIT, // 2
|
| | | FLAG_ORDER_TYPE_SELL_LIMIT, // 3
|
| | | FLAG_ORDER_TYPE_BUY_STOP, // 4
|
| | | FLAG_ORDER_TYPE_SELL_STOP, // 5
|
| | | FLAG_ORDER_TYPE_BUY_STOP_LIMIT, // 6
|
| | | FLAG_ORDER_TYPE_SELL_STOP_LIMIT, // 7
|
| | | FLAG_ORDER_TYPE_CLOSE_BY // 8
|
| | | };
|
| | | */
|
2026-09-12 19:41:52 -05:00 | | | }
|
2025-09-22 09:09:20 -05:00 | | | //+------------------------------------------------------------------+
|
2025-11-10 09:33:30 -05:00 | | | #endif // MQLARTICLES_RM_RDEFINES_MQH
|
2025-10-26 20:52:13 -05:00 | | | //+------------------------------------------------------------------+
|