forked from nique_372/MQLArticles
135 lines
4.9 KiB
MQL5
135 lines
4.9 KiB
MQL5
//+------------------------------------------------------------------+
| |
//| 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 "..\\..\\..\\RM\\RiskManagement.mqh"
| |
#include "..\\..\\..\\Utils\\FA\\DiffCalc.mqh"
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
namespace TSN
| |
{
| |
//+------------------------------------------------------------------+
| |
//| Defines |
| |
//+------------------------------------------------------------------+
| |
#define CONDITIONAL_PARTIAL_ARR_MAIN_RESERVE 16
| |
#define CONDITIONAL_PARTIAL_ARR_TO_REMOVE_RESERVE 8
| |
| |
//+------------------------------------------------------------------+
| |
//| 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
| |
{
| |
//---
| |
bool delete_condition;
| |
IConditionPartial *condition;
| |
CDiff *min_distance_to_close_pos;
| |
string str_percentage_volume_to_close;
| |
string symbol;
| |
ulong magic_number;
| |
bool auto_mode;
| |
| |
//---
| |
ConditionalPartialConfig()
| |
: str_percentage_volume_to_close(""), symbol(_Symbol), magic_number(NOT_MAGIC_NUMBER),
| |
condition(NULL), min_distance_to_close_pos(NULL), auto_mode(true), delete_condition(true)
| |
{
| |
}
| |
| |
//---
| |
bool IsValid(string& error) const
| |
{
| |
if(!CheckPointer(condition))
| |
{
| |
error = "Invalid condition pointer";
| |
return false;
| |
}
| |
| |
if(!CheckPointer(min_distance_to_close_pos))
| |
{
| |
error = "Invalid min distance pointer";
| |
return false;
| |
}
| |
return true;
| |
}
| |
| |
//---
| |
bool ConvertStrToDoubleArr(ushort separator, double& out[], string& error) const
| |
{
| |
//--- Convert
| |
| |
const int size = CStringFunc::ToArr<double, CStringConvert>(str_percentage_volume_to_close, out, separator);
| |
if(size < 1)
| |
{
| |
error = StringFormat("When converting string:\n%s\nTo double array", str_percentage_volume_to_close);
| |
return false;
| |
}
| |
| |
//--- CheckSize
| |
ArrayResize(out, size);
| |
return true;
| |
}
| |
};
| |
| |
//--- Structure to store a trackable position (to which partial closes will be applied until its removal)
| |
struct pack(8) ConditionalPartialTrackedPosition
| |
{
| |
ulong ticket;
| |
double next_min_price;
| |
ENUM_POSITION_TYPE type;
| |
int next_index_to_close;
| |
};
| |
| |
| |
//+------------------------------------------------------------------+
| |
//| Enums |
| |
//+------------------------------------------------------------------+
| |
enum ENUM_TYPE_CONDITIONAL_PARTIAL_CLASS
| |
{
| |
CONDITIONAL_PARTIAL_CLASS_TYPE_BASE = 0, // Default conditional partial closures
| |
CONDITIONAL_PARTIAL_CLASS_TYPE_CONSTANT = 1 // Constant conditional partial closures
| |
};
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
#define MQLARTICLES_CPARTIALES_CHECK_RESIZE_IR \
| |
if(m_tracked_positions_size >= m_indexes_to_remove_r)\
| |
{\
| |
m_indexes_to_remove_r <<= 1;\
| |
ArrayResize(m_indexes_to_remove, m_indexes_to_remove_r, m_indexes_to_remove_r);\
| |
}
| |
//---
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
#endif // MQLARTICLES_POSMGMT_CONDPARTIALS_BASE_DEFINES_MQH
|