MQLArticles/RM/RM_Defines.mqh

265 lines
8.7 KiB
MQL5
Raw Permalink Normal View History

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
//+------------------------------------------------------------------+
//| 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
#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
//---
#define RISK_MANGEMENT_LOSS_PROFIT_MIN_VALUE 1e-4
//--- Losses Profits
#define LOSS_PROFIT_COUNT 8
//--- 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
{
risk_mode_propfirm_dynamic_daiy_loss, //Prop Firm (FTMO-FundendNext)
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
};
enum ENUM_LOSS_PROFIT
{
T_LOSS,
T_PROFIT,
T_GMLPO
};
enum ENUM_TYPE_LOSS_PROFIT
{
LP_MDP = 0, //Maxima ganancias diaria
LP_MWP = 1,//Maxima ganancia semanal
LP_MMP = 2,//Maxima ganancia mensual
LP_MDL = 3, //Maxima perdida diaria
LP_MWL = 4, //Maxima perdida semanal
LP_MML = 5, //Maxima perdida mensual
LP_ML = 6, //Maxima perdida total
LP_GMLPO = 7 //Maxima perdida por operacion
};
//+------------------------------------------------------------------+
//| Structures |
//+------------------------------------------------------------------+
//--- Positions
struct pack(sizeof(double)) Position //remove pack if it increases to +4bytes
2025-09-22 09:09:20 -05:00
{
ulong ticket; //position ticket
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
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)
struct 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
//---
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
2025-11-23 08:04:16 -05:00
//--- 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)
2025-11-23 08:04:16 -05:00
//--- Open position info or closed position info
2025-09-22 09:09:20 -05:00
Position position;
};
2025-11-23 08:04:16 -05:00
2025-09-22 09:09:20 -05:00
//---
struct ROnOpenClosePosition
{
//--- Position
2025-09-22 09:09:20 -05:00
Position position;
2025-11-23 08:04:16 -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
2025-11-23 08:04:16 -05:00
//--- Account
double account_balance; // Account balance
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
2025-11-23 08:04:16 -05:00
2025-09-22 09:09:20 -05:00
//--- Extra
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
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
//--- 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;
};
//+------------------------------------------------------------------+
//| Arrays para las ordenes |
//+------------------------------------------------------------------+
const bool EsUnaOrderPendiente[9]
{
false, // 0
false, // 1
true, // 2
true, // 3
true, // 4
true, // 4
true, // 5
true, // 7
false // 8
};
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
};
/*
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
*/
//+------------------------------------------------------------------+
2025-11-10 09:33:30 -05:00
#endif // MQLARTICLES_RM_RDEFINES_MQH
//+------------------------------------------------------------------+