2025-11-10 09:32:46 -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
|
| | |
|
2025-11-12 07:42:02 -05:00 | | | #ifndef MQLARTICLES_POSMGMT_CONDPARTIALS_BASE_DEFINES_MQH
|
| | | #define MQLARTICLES_POSMGMT_CONDPARTIALS_BASE_DEFINES_MQH
|
2025-11-10 09:32:46 -05:00 | | |
|
| | | //+------------------------------------------------------------------+
|
2025-11-12 16:03:01 -05:00 | | | //| Include |
|
2025-11-10 09:32:46 -05:00 | | | //+------------------------------------------------------------------+
|
2026-09-06 20:42:03 -05:00 | | | #include "..\\..\\..\\RM\\RiskManagement.mqh"
|
| | | #include "..\\..\\..\\Utils\\FA\\DiffCalc.mqh"
|
2025-11-10 09:32:46 -05:00 | | |
|
2026-09-13 08:47:52 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | namespace TSN
|
| | | {
|
2025-11-10 09:32:46 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| Defines |
|
| | | //+------------------------------------------------------------------+
|
2026-08-04 17:02:36 -05:00 | | | #define CONDITIONAL_PARTIAL_ARR_MAIN_RESERVE 16
|
| | | #define CONDITIONAL_PARTIAL_ARR_TO_REMOVE_RESERVE 8
|
2025-11-10 09:32:46 -05:00 | | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| Interface for partial condition |
|
| | | //+------------------------------------------------------------------+
|
2026-01-29 08:19:47 -05:00 | | | class IConditionPartial : public CAllClassEventsBasic
|
2025-11-10 09:32:46 -05:00 | | | {
|
| | | public:
|
2026-01-31 19:44:40 -05:00 | | | IConditionPartial() {}
|
2026-01-29 08:19:47 -05:00 | | | ~IConditionPartial() {}
|
| | |
|
| | | virtual void OnInitPartials(double initial_price) = 0;
|
2026-02-14 17:00:45 -05:00 | | | virtual void Execute(const datetime current_time) = 0;
|
2026-01-29 08:19:47 -05:00 | | | virtual string Name() const = 0;
|
| | | virtual bool CloseBuy() = 0;
|
| | | virtual bool CloseSell() = 0;
|
2025-11-10 09:32:46 -05:00 | | | };
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| Structures |
|
| | | //+------------------------------------------------------------------+
|
| | | //--- Structure for partial configuration
|
| | | struct ConditionalPartialConfig
|
| | | {
|
| | | //---
|
2026-01-29 08:19:47 -05:00 | | | bool delete_condition;
|
2025-11-10 09:32:46 -05:00 | | | 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),
|
2026-01-29 08:19:47 -05:00 | | | condition(NULL), min_distance_to_close_pos(NULL), auto_mode(true), delete_condition(true)
|
2025-11-10 09:32:46 -05:00 | | | {
|
| | | }
|
| | |
|
| | | //---
|
| | | 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
|
| | |
|
2026-09-13 08:47:52 -05:00 | | | const int size = CStringFunc::ToArr<double, CStringConvert>(str_percentage_volume_to_close, out, separator);
|
2025-11-10 09:32:46 -05:00 | | | if(size < 1)
|
| | | {
|
2026-09-13 08:47:52 -05:00 | | | error = StringFormat("When converting string:\n%s\nTo double array", str_percentage_volume_to_close);
|
2025-11-10 09:32:46 -05:00 | | | return false;
|
| | | }
|
2026-09-13 08:47:52 -05:00 | | |
|
| | | //--- CheckSize
|
| | | ArrayResize(out, size);
|
2025-11-10 09:32:46 -05:00 | | | return true;
|
| | | }
|
| | | };
|
| | |
|
| | | //--- Structure to store a trackable position (to which partial closes will be applied until its removal)
|
2026-08-04 17:02:36 -05:00 | | | struct pack(8) ConditionalPartialTrackedPosition
|
2025-11-10 09:32:46 -05:00 | | | {
|
| | | ulong ticket;
|
| | | double next_min_price;
|
| | | ENUM_POSITION_TYPE type;
|
| | | int next_index_to_close;
|
| | | };
|
2026-01-29 08:19:47 -05:00 | | |
|
2025-11-12 07:42:02 -05:00 | | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| Enums |
|
| | | //+------------------------------------------------------------------+
|
| | | enum ENUM_TYPE_CONDITIONAL_PARTIAL_CLASS
|
2026-01-29 08:19:47 -05:00 | | | {
|
| | | CONDITIONAL_PARTIAL_CLASS_TYPE_BASE = 0, // Default conditional partial closures
|
| | | CONDITIONAL_PARTIAL_CLASS_TYPE_CONSTANT = 1 // Constant conditional partial closures
|
| | | };
|
| | |
|
2026-08-04 17:02:36 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | #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);\
|
| | | }
|
2026-09-13 08:47:52 -05:00 | | | //---
|
| | | }
|
2026-08-04 17:02:36 -05:00 | | |
|
2025-11-10 09:32:46 -05:00 | | | //+------------------------------------------------------------------+
|
2025-11-12 07:42:02 -05:00 | | | #endif // MQLARTICLES_POSMGMT_CONDPARTIALS_BASE_DEFINES_MQH
|