forked from nique_372/MQLArticles
//+------------------------------------------------------------------+
| |
//| 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
| |
| |
#ifndef MQLARTICLES_ACCOUNT_RM_BASES_DEF_MQH
| |
#define MQLARTICLES_ACCOUNT_RM_BASES_DEF_MQH
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
#include <Trade/Trade.mqh>
| |
#include <TSN\\Std\\Basics\\CompTime.mqh>
| |
#include <TSN\\Std\\Basics\\ErrManager.mqh>
| |
#include <TSN\\Std\\Misce\\BitReinterprete.mqh>
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
namespace TSN
| |
{
| |
//+------------------------------------------------------------------+
| |
//| Defines |
| |
//+------------------------------------------------------------------+
| |
//--- No (numero magico) por defecto 0.. si requier otro valor (ponlo)
| |
#ifndef NOT_MAGIC_NUMBER
| |
#define NOT_MAGIC_NUMBER 0
| |
#endif // NOT_MAGIC_NUMBER
| |
| |
//---
| |
/*
| |
void OnStart(void)
| |
{
| |
Print(POSITION_TYPE_BUY); // 0
| |
Print(POSITION_TYPE_SELL); // 1
| |
}
| |
*/
| |
| |
//---
| |
#define TSNMQLART_POSITION_HASN_FLAG(FLAGS, POS) (((FLAGS)&(1u<<(POS)))==0)
| |
| |
//--- positions
| |
#define FLAG_POSITION_TYPE_BUY (1<<(POSITION_TYPE_BUY))
| |
#define FLAG_POSITION_TYPE_SELL (1<<(POSITION_TYPE_SELL))
| |
// profit
| |
#define FLAG_CLOSE_ALL_PROFIT (4) // Flag indicating to close only operations with profit
| |
#define FLAG_CLOSE_ALL_LOSS (8) // Flag indicating to close only operations without profit
| |
| |
//---
| |
TSNSTD_STATIC_ASSERT(POSITION_TYPE_BUY == 0, mqlart_rm_d_b)
| |
TSNSTD_STATIC_ASSERT(POSITION_TYPE_SELL == 1, mqlart_rm_d_s)
| |
| |
//--- orders
| |
/*
| |
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
| |
*/
| |
| |
//---
| |
TSNSTD_STATIC_ASSERT(ORDER_TYPE_BUY == 0, tsnmqlart_rm_d_ord_bu)
| |
TSNSTD_STATIC_ASSERT(ORDER_TYPE_SELL == 1, tsnmqlart_rm_d_ord_se)
| |
TSNSTD_STATIC_ASSERT(ORDER_TYPE_BUY_LIMIT == 2, tsnmqlart_rm_d_ord_bu_l)
| |
TSNSTD_STATIC_ASSERT(ORDER_TYPE_SELL_LIMIT == 3, tsnmqlart_rm_d_ord_se_l)
| |
TSNSTD_STATIC_ASSERT(ORDER_TYPE_BUY_STOP == 4, tsnmqlart_rm_d_ord_bu_s)
| |
TSNSTD_STATIC_ASSERT(ORDER_TYPE_SELL_STOP == 5, tsnmqlart_rm_d_ord_se_s)
| |
TSNSTD_STATIC_ASSERT(ORDER_TYPE_BUY_STOP_LIMIT == 6, tsnmqlart_rm_d_ord_bu_sl)
| |
TSNSTD_STATIC_ASSERT(ORDER_TYPE_SELL_STOP_LIMIT == 7, tsnmqlart_rm_d_ord_se_sl)
| |
TSNSTD_STATIC_ASSERT(ORDER_TYPE_CLOSE_BY == 8, tsnmqlart_rm_d_ord_clo_by)
| |
| |
| |
//- to
| |
#define MQLArticles_OrderToFlag(v) (1<<(v))
| |
| |
//- is
| |
#define MQLArticles_IsPendingOrder(v) (v>1&&v<8)
| |
| |
//- f
| |
#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
| |
| |
| |
//--- Tickets
| |
#define INVALID_TICKET 0
| |
//+------------------------------------------------------------------+
| |
//| Enumerations |
| |
//+------------------------------------------------------------------+
| |
enum ENUM_LOTE_TYPE //lot type
| |
{
| |
Dinamico,//Dynamic
| |
Fijo//Fixed
| |
};
| |
| |
//--- 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
| |
};
| |
| |
//+------------------------------------------------------------------+
| |
//| Structures |
| |
//+------------------------------------------------------------------+
| |
//--- Positions
| |
struct pack(sizeof(double)) Position //remove pack if it increases to +4bytes
| |
{
| |
ulong ticket; //position ticket
| |
ulong magic; //magic number with which it was opened
| |
double profit; //last recorded profit
| |
double open_price; //opening price
| |
double sl; //stop loss
| |
double tp; //take profit
| |
datetime open_time; //opening time
| |
double volume;
| |
ENUM_POSITION_TYPE type; //position type
| |
};
| |
| |
// 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 pack(sizeof(double)) ROrder
| |
{
| |
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
| |
};
| |
| |
//---
| |
struct ROnOpenPosition
| |
{
| |
//--- Position
| |
Position position; // Position
| |
| |
//--- Deal
| |
ulong deal_ticket; // Ticket
| |
double deal_profit; // Profit
| |
ENUM_DEAL_REASON deal_reason; // Reason
| |
ENUM_DEAL_ENTRY deal_entry_type; // Entry type
| |
};
| |
| |
//---
| |
struct ROnClosePosition : ROnOpenPosition
| |
{
| |
ulong magic_number_closed; // Magic number at position close
| |
};
| |
| |
//+------------------------------------------------------------------+
| |
//| 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
| |
};
| |
*/
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
// Redondeo de lotaje en CPartials y LoteSizeCalc
| |
typedef double (*FTSNMQLArt_RoundStep)(double, double);
| |
#define TSNMQLART_ROUND_LOTSIZE_F(F, number, step) (F((number) / (step)) * (step))
| |
| |
//---
| |
__forceinline double MQLArtRM_RoundLotStepFloor(double number, double step) { return TSNMQLART_ROUND_LOTSIZE_F(MathFloor, number, step); }
| |
__forceinline double MQLArtRM_RoundLotStepNormal(double number, double step) { return TSNMQLART_ROUND_LOTSIZE_F(MathRound, number, step); }
| |
__forceinline double MQLArtRM_RoundLotStepCeil(double number, double step) { return TSNMQLART_ROUND_LOTSIZE_F(MathCeil, number, step); }
| |
| |
//---
| |
enum ENUM_TSNMQLART_RM_LOTSIZE_BASIC_ROTYPE
| |
{
| |
TSNMQLART_RM_LOTSIZE_BASIC_ROTYPE_FLOOR=0, // Floor-Rounded
| |
TSNMQLART_RM_LOTSIZE_BASIC_ROTYPE_NORMAL, // Normal-Rounded
| |
TSNMQLART_RM_LOTSIZE_BASIC_ROTYPE_CEIL, // Ceil-Rounded
| |
};
| |
| |
//---
| |
const FTSNMQLArt_RoundStep g_tsnmqlart_rmdef_lotsize_rtype[3] =
| |
{
| |
MQLArtRM_RoundLotStepFloor,
| |
MQLArtRM_RoundLotStepNormal,
| |
MQLArtRM_RoundLotStepCeil
| |
};
| |
}
| |
//+------------------------------------------------------------------+
| |
#endif // MQLARTICLES_ACCOUNT_RM_BASES_DEF_MQH
| |
//+------------------------------------------------------------------+
|