MQLArticles/PosMgmt/ConditionalPartial/Base/Defines.mqh
Nique_372 Nique_372 e4715a4e1c
2026-11-07 09:34:18 -05:00
//+------------------------------------------------------------------+
//| Defines.mqh |
//| Copyright 2025, Niquel Mendoza. |
//| https://www.mql5.com/es/users/nique_372/news |
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, Niquel Mendoza."
#property link "https://www.mql5.com/es/users/nique_372/news"
#property strict
#ifndef MQLARTICLES_POSMGMT_CONDPARTIALS_BASE_DEFINES_MQH
#define MQLARTICLES_POSMGMT_CONDPARTIALS_BASE_DEFINES_MQH
//+------------------------------------------------------------------+
//| Include |
//+------------------------------------------------------------------+
#include "..\\..\\..\\Account\\MoneyStatus\\Manager.mqh"
#include "..\\..\\..\\Utils\\FA\\DiffCalc.mqh"
#include <TSN\\Std\\Memory.mqh>
#include <TSN\\Std\\Basics\\ErrManager.mqh>
#include <TSN\\Std\\Misce\\BitReinterprete.mqh>
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
namespace TSN
{
//+------------------------------------------------------------------+
//| Defines |
//+------------------------------------------------------------------+
#ifndef CONDITIONAL_PARTIAL_ARR_MAIN_RESERVE
#define CONDITIONAL_PARTIAL_ARR_MAIN_RESERVE 16
#endif // CONDITIONAL_PARTIAL_ARR_MAIN_RESERVE
//+------------------------------------------------------------------+
//| Interface for partial condition |
//+------------------------------------------------------------------+
class IConditionPartial : public CAllClassEventsBasic
{
public:
IConditionPartial() {}
~IConditionPartial() {}
virtual void OnInitPartials(double initial_price) = 0;
virtual void Execute(const datetime current_time) = 0;
virtual string Name() const = 0;
virtual bool CloseBuy() = 0;
virtual bool CloseSell() = 0;
};
//+------------------------------------------------------------------+
//| Structures |
//+------------------------------------------------------------------+
//--- Structure for partial configuration
struct ConditionalPartialConfig
{
//---
string str_percentage_volume_to_close;
string symbol;
IConditionPartial *condition;
CDiff *min_distance_to_close_pos;
ulong magic_number;
bool delete_condition;
bool auto_mode;
bool constant;
bool forze_to_close;
//---
ConditionalPartialConfig()
: str_percentage_volume_to_close(NULL), symbol(_Symbol), magic_number(NOT_MAGIC_NUMBER),
condition(NULL), min_distance_to_close_pos(NULL), auto_mode(true), delete_condition(true),
constant(false), forze_to_close(false)
{
}
};
//--- Structure to store a trackable position (to which partial closes will be applied until its removal)
struct pack(8) ConditionalPartialTrackedPositionBase
{
ulong ticket;
double next_min_price;
ENUM_POSITION_TYPE type;
};
struct ConditionalPartialTrackedPosition : ConditionalPartialTrackedPositionBase
{
int next_index_to_close;
int try;
};
//---
enum ENUM_TSNQMLART_CONDPARTIAL_ERR
{
TSNQMLART_CONDPARTIAL_ERR_NOT,
TSNQMLART_CONDPARTIAL_ERR_INVALID_NUM_VOLTOCLOSE_ARR,
TSNQMLART_CONDPARTIAL_ERR_MALFORMED_VOLTOCLOSE, // algun volumen del string no se pudo convertir (ToArr devuelve negativo)
TSNQMLART_CONDPARTIAL_ERR_INVALID_VOLTOCLOSE_MUSTBE_0_100,
TSNQMLART_CONDPARTIAL_ERR_SELECT_POSITION,
TSNQMLART_CONDPARTIAL_ERR_INVALID_SYMBOL,
TSNQMLART_CONDPARTIAL_ERR_POSITION_NOT_FOUND,
};
//---
#define MQLART_CONDPARTIAL_CONSTANT (31)
#define MQLART_CONDPARTIAL_NO_CONSTANT (0)
//---
#define MQLART_CONDPARTIAL_PBUY uchar
#define MQLART_CONDPARTIAL_PSELL ushort
//+------------------------------------------------------------------+
//| Enums |
//+------------------------------------------------------------------+
enum ENUM_TYPE_CONDITIONAL_PARTIAL_CLASS
{
CONDITIONAL_PARTIAL_CLASS_TYPE_BASE = 0, // Default conditional partial closures
CONDITIONAL_PARTIAL_CLASS_TYPE_CONSTANT // Constant conditional partial closures
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//---
//--- Por defecto usaremos el round (para manteer compatiblidad)
#ifndef MQLART_POSMGMT_CONDPARTIALS_LOTROUND
#define MQLART_POSMGMT_CONDPARTIALS_LOTROUND(number, step) TSNMQLART_ROUND_LOTSIZE_F(MathRound, number, step)
#endif // MQLART_POSMGMT_CONDPARTIALS_LOTROUND
//---
#ifndef MQLART_POSMGMT_CONDPARTIALS_TRYDEF
#define MQLART_POSMGMT_CONDPARTIALS_TRYDEF (4)
#endif // MQLART_POSMGMT_CONDPARTIALS_TRYDEF
//---
}
//+------------------------------------------------------------------+
#endif // MQLARTICLES_POSMGMT_CONDPARTIALS_BASE_DEFINES_MQH