2026-10-29 11:36:56 -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_POSMGMT_BE_BASE_DEF_MQH
# define MQLARTICLES_POSMGMT_BE_BASE_DEF_MQH
/ / + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
//| Include |
//+------------------------------------------------------------------+
# include "..\\..\\..\\Account\\MoneyStatus\\Manager.mqh"
# include "..\\..\\..\\Utils\\FA\\Atr\\All.mqh"
2026-11-05 17:37:12 -05:00
# include <TSN\\Std\\Basics\\ErrManager.mqh>
# include <TSN\\Std\\Misce\\BitReinterprete.mqh>
2026-10-29 11:36:56 -05:00
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
namespace TSN
{
//+------------------------------------------------------------------+
//| Break Even Structs |
//+------------------------------------------------------------------+
2026-11-01 17:28:51 -05:00
struct position_be
2026-10-29 11:36:56 -05:00
{
2026-11-01 17:28:51 -05:00
ulong ticket ; // Position Ticket
double breakeven_price ; // Be price
double price_to_beat ; // Price to exceed to reach break even
ENUM_POSITION_TYPE type ; // Position type
int try ; // Intentos
2026-10-29 11:36:56 -05:00
} ;
//---
enum ENUM_BREAKEVEN_TYPE
{
BREAKEVEN_TYPE_RR = 0 , //By RR
BREAKEVEN_TYPE_FIXED_POINTS , //By FixedPoints
BREAKEVEN_TYPE_ATR , //By Atr
BREAKEVEN_T_TOTAL ,
} ;
//---
const string g_breakevens_types_str [ 3 ]
{
" Breakeven by rr " ,
" Breakeven by fixed points " ,
" Breakeven by atr "
} ;
//---
struct BreakEvenParams
{
long integer_value ;
double double_value ;
CAtrOptimized * atr_pointer_value ;
} ;
//--
# ifndef MQLARTICLES_BREAKEVEN_CHECK_RE
2026-10-30 13:24:14 -05:00
// Crece m_pos_be y su array paralelo de marcas (m_pos_be_remove) juntos; la cola nueva de marcas se inicia en false
# define MQLARTICLES_BREAKEVEN_CHECK_RE \
if(m_pos_be_s>=m_pos_be_r) \
{ \
const int old_r = m_pos_be_r; \
m_pos_be_r<<=1; \
ArrayResize(m_pos_be, m_pos_be_r,m_pos_be_r); \
ArrayResize(m_pos_be_remove, m_pos_be_r,m_pos_be_r); \
for(int i_re = old_r; i_re < m_pos_be_r; i_re++) \
m_pos_be_remove[i_re] = false; \
2026-10-29 11:36:56 -05:00
}
# endif // MQLARTICLES_BREAKEVEN_CHECK_RE
2026-10-29 17:44:49 -05:00
//---
2026-11-01 15:00:25 -05:00
# ifndef CBREAKEVEN_RESERVE_ARR
2026-10-29 11:36:56 -05:00
# define CBREAKEVEN_RESERVE_ARR 16
2026-11-01 15:00:25 -05:00
# endif // CBREAKEVEN_RESERVE_ARR
2026-10-29 11:36:56 -05:00
2026-11-01 17:28:51 -05:00
//---
# ifndef CBREAKEVEN_DEFAULT_POS_MOD_TRY
# define CBREAKEVEN_DEFAULT_POS_MOD_TRY ( 4 )
# endif // CBREAKEVEN_DEFAULT_POS_MOD_TRY
//---
# define MQLARTICLES_BREAKEVEN_PROLOGO(TYPE, TICKET ) \
MQLARTICLES_BREAKEVEN_CHECK_RE \
m_pos_be[m_pos_be_s].type = TYPE; \
2026-11-02 07:16:20 -05:00
m_pos_be[m_pos_be_s].ticket = TICKET; \
m_pos_be[m_pos_be_s].try = m_be_try;
2026-11-01 17:28:51 -05:00
2026-11-05 17:37:12 -05:00
//--- Errores propios de CBreakEvenBase (rango [0 - 99])
2026-10-29 11:36:56 -05:00
enum ENUM_TSNMQLART_BE_ERR
{
TSNMQLART_BE_ERR_NOT ,
TSNMQLART_BE_ERR_SELECT_POSITION ,
2026-11-02 15:21:28 -05:00
TSNMQLART_BE_ERR_POSITION_NOT_FOUND ,
2026-11-05 17:37:12 -05:00
} ;
//--- Errores de los tipos de breakeven (Imp\), desde 100 para no pisar los de la base
# define TSNMQLART_BE_TYPES_ERR_START ( 100 )
enum ENUM_TSNMQLART_BE_TYPES_ERR
{
TSNMQLART_BE_TYPES_ERR_NOT = TSNMQLART_BE_TYPES_ERR_START ,
//--- commons
TSNMQLART_BE_TYPES_ERR_INV_SYMBOL ,
TSNMQLART_BE_TYPES_ERR_INV_SL_PRICE ,
TSNMQLART_BE_TYPES_ERR_SL_INSUFICCENT_DIST ,
//--- atr
TSNMQLART_BE_TYPES_ERR_ATR_INVALID_EXTRABE_VAL ,
TSNMQLART_BE_TYPES_ERR_ATR_PTR_INVALID ,
//--- rr
TSNMQLART_BE_TYPES_ERR_RR_INVALID_ATPPTR_RR ,
TSNMQLART_BE_TYPES_ERR_RR_INVALID_TYPE_EXTRA ,
TSNMQLART_BE_TYPES_ERR_RR_INVALID_RR ,
TSNMQLART_BE_TYPES_ERR_RR_INVALID_ATRMUL_OR_POINTS ,
//--- fixed points
TSNMQLART_BE_TYPES_ERR_BPOINTS_INV_EPOINTSBE ,
TSNMQLART_BE_TYPES_ERR_BPOINTS_EPOINTS_MUSTBE_MINOR_PNORM ,
} ;
2026-10-29 11:36:56 -05:00
2026-11-05 17:37:12 -05:00
//+------------------------------------------------------------------+
//| Formater de los errores de los tipos de breakeven (Imp) |
//+------------------------------------------------------------------+
class CBasicBEFormater
{
public :
2026-11-06 10:40:44 -05:00
static void FormatTrace ( const TSNErrorFrame & trace [ ] , int & trace_idx , string & out ) ;
2026-10-29 11:36:56 -05:00
} ;
2026-11-05 17:37:12 -05:00
//+------------------------------------------------------------------+
2026-11-06 10:40:44 -05:00
static void CBasicBEFormater::FormatTrace ( const TSNErrorFrame & trace [ ] , int & trace_idx , string & out )
2026-11-05 17:37:12 -05:00
{
TSNSTD_ERRMAN_PUSHINI ( out , trace_idx )
switch ( trace [ trace_idx ] . code )
{
case TSNMQLART_BE_TYPES_ERR_NOT :
TSNSTD_ERRMAN_PUSHOUT ( out , " Not error " , trace_idx )
break ;
case TSNMQLART_BE_TYPES_ERR_INV_SYMBOL :
TSNSTD_ERRMAN_PUSHOUT ( out , StringFormat ( " Invalid symbol for the position [ticket = %I64u] (must be equal to the symbol of the breakeven) " , trace [ trace_idx ] . info ) , trace_idx )
break ;
case TSNMQLART_BE_TYPES_ERR_INV_SL_PRICE :
TSNSTD_ERRMAN_PUSHOUT ( out , StringFormat ( " Invalid sl price [%.5f] (the position must have a stop loss) " , CBitsReinterprete : : ToBasic < double , ulong > ( trace [ trace_idx ] . info ) ) , trace_idx )
break ;
case TSNMQLART_BE_TYPES_ERR_SL_INSUFICCENT_DIST :
TSNSTD_ERRMAN_PUSHOUT ( out , StringFormat ( " The distance between the open price and the stop loss [%.5f] is not enough to trigger the breakeven " ,
CBitsReinterprete : : ToBasic < double , ulong > ( trace [ trace_idx ] . info ) ) , trace_idx )
break ;
case TSNMQLART_BE_TYPES_ERR_ATR_INVALID_EXTRABE_VAL :
TSNSTD_ERRMAN_PUSHOUT ( out , StringFormat ( " Atr breakeven, the extra atr multiplier [%.4f] must be lower than the atr multiplier " ,
CBitsReinterprete : : ToBasic < double , ulong > ( trace [ trace_idx ] . info ) ) , trace_idx )
break ;
case TSNMQLART_BE_TYPES_ERR_ATR_PTR_INVALID :
TSNSTD_ERRMAN_PUSHOUT ( out , " Atr breakeven, invalid atr pointer " , trace_idx )
break ;
case TSNMQLART_BE_TYPES_ERR_RR_INVALID_ATPPTR_RR :
TSNSTD_ERRMAN_PUSHOUT ( out , " RR breakeven, the extra type is by atr but the atr pointer is invalid " , trace_idx )
break ;
case TSNMQLART_BE_TYPES_ERR_RR_INVALID_TYPE_EXTRA :
TSNSTD_ERRMAN_PUSHOUT ( out , StringFormat ( " RR breakeven, invalid extra type [%d] " , int ( trace [ trace_idx ] . info ) ) , trace_idx )
break ;
case TSNMQLART_BE_TYPES_ERR_RR_INVALID_RR :
TSNSTD_ERRMAN_PUSHOUT ( out , StringFormat ( " RR breakeven, invalid rr coefficient [%.4f] (must be > 0) " , CBitsReinterprete : : ToBasic < double , ulong > ( trace [ trace_idx ] . info ) ) , trace_idx )
break ;
case TSNMQLART_BE_TYPES_ERR_RR_INVALID_ATRMUL_OR_POINTS :
TSNSTD_ERRMAN_PUSHOUT ( out , StringFormat ( " RR breakeven, invalid extra atr multiplier or points [%.4f] (must be > 0) " ,
CBitsReinterprete : : ToBasic < double , ulong > ( trace [ trace_idx ] . info ) ) , trace_idx )
break ;
case TSNMQLART_BE_TYPES_ERR_BPOINTS_INV_EPOINTSBE :
TSNSTD_ERRMAN_PUSHOUT ( out , StringFormat ( " Fixed points breakeven, invalid extra points [%d] (must be >= 0) " , int ( trace [ trace_idx ] . info ) ) , trace_idx )
break ;
case TSNMQLART_BE_TYPES_ERR_BPOINTS_EPOINTS_MUSTBE_MINOR_PNORM :
TSNSTD_ERRMAN_PUSHOUT ( out , StringFormat ( " Fixed points breakeven, extra points [%d] must be lower than points [%d] " ,
int ( trace [ trace_idx ] . info ) , int ( trace [ trace_idx ] . info > > 32 ) ) , trace_idx )
break ;
default :
TSNSTD_ERRMAN_PUSHOUT ( out , " Unknow error " , trace_idx )
break ;
}
}
2026-10-29 11:36:56 -05:00
//---
//#define TSNMQLART_POSMGMT_BE_ELOGS
//---
}
# endif // MQLARTICLES_POSMGMT_BE_BASE_DEF_MQH
//+------------------------------------------------------------------+