MQLArticles/RM/LossProfit/Manager.mqh

326 lines
22 KiB
MQL5

2026-01-28 12:07:14 -05:00
<EFBFBD><EFBFBD>//+------------------------------------------------------------------+
//| Manager.mqh |
//| Copyright 2025, Niquel Mendoza. |
//| https://www.mql5.com/es/users/nique_372 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, Niquel Mendoza."
#property link "https://www.mql5.com/es/users/nique_372"
#property strict
#ifndef MQLARTICLES_RM_LOSSPROFIT_MANAGERS_MQH
2026-01-29 08:19:03 -05:00
#define MQLARTICLES_RM_LOSSPROFIT_MANAGERS_MQH
2026-02-01 16:17:01 -05:00
2026-01-29 08:19:03 -05:00
//+------------------------------------------------------------------+
2026-01-28 12:07:14 -05:00
//| Include |
//+------------------------------------------------------------------+
#include "Basic\\MaxLosses.mqh"
#include "Basic\\MaxProfits.mqh"
//+------------------------------------------------------------------+
//| Manager class to work with different poses |
//+------------------------------------------------------------------+
// NOTA:
// Esta clase no recibe EVENTOS de ningun tipo.. solo se heredo de CAllClassEventsBasic, para propagar logs..
// Y el estado global
//---
2026-01-31 19:44:40 -05:00
class CLossProfitManager : public CAllClassEventsBasic
2026-01-28 12:07:14 -05:00
{
private:
//---
CLossProfit* empty_obj;
//---
CLossProfit* m_losses_profits[LOSS_PROFIT_COUNT];
bool m_is_add[LOSS_PROFIT_COUNT]; // Si esta a<EFBFBD>adido
//--- Indices validos
int m_valid_indexes[];
int m_valid_indexes_size;
//---
CLossProfit* m_profits[];
int m_profits_size;
int m_last_idx_profit_sup;
//---
CLossProfit* m_losses[];
2026-03-05 12:10:29 -05:00
int m_losses_size;
2026-01-28 12:07:14 -05:00
int m_last_idx_loss_sup;
public:
2026-01-31 19:44:40 -05:00
2026-01-28 12:07:14 -05:00
~CLossProfitManager();
CLossProfitManager();
//---
__forceinline int SizeValids() const { return m_valid_indexes_size; }
2026-01-31 19:44:40 -05:00
2026-01-28 12:07:14 -05:00
__forceinline int GetIndexValid(const int index) { return m_valid_indexes[index]; }
//---
inline bool IsAdd(const ENUM_TYPE_LOSS_PROFIT type) const { return m_is_add[type]; }
2026-02-01 16:17:01 -05:00
//--- Clear
2026-01-28 12:07:14 -05:00
void Clear();
//--- Add
bool Add(CLossProfit * new_loss_profit); // Add CLossProfit
//--- Is Superated
// Index
__forceinline int GetLastIndexSuperatedProfit() const { return m_last_idx_profit_sup; }
__forceinline int GetLastIndexSuperatedLoss() const { return m_last_idx_loss_sup; }
// Ptr
const CLossProfit* const GetLastLossSuperated() const { return m_losses[m_last_idx_loss_sup]; }
const CLossProfit* const GetLastProfitSuperated() const { return m_profits[m_last_idx_profit_sup]; }
// Type
__forceinline int GetLastLossSuperatedType() const { return m_losses[m_last_idx_loss_sup].Type(); }
__forceinline int GetLastProfitSuperatedType() const { return m_profits[m_last_idx_profit_sup].Type(); }
// Main
bool MaxProfitIsSuperated() const;
bool MaxLossIsSuperated() const;
//--- On
void SetNewChossenBalanceForDynamicsAndSet(double _chosen_balance, bool update);
void SetValues(); // Setear valores
void SetValuesAndDynamic(); // Valores y dinamicos
void CheckDynamic();
//---
void Summary() const;
//---
CLossProfit* operator[](const ENUM_TYPE_LOSS_PROFIT type) const;
CLossProfit* operator[](const int index) const { return m_losses_profits[index]; }
};
//+------------------------------------------------------------------+
//| Contructor y Destructor |
//+------------------------------------------------------------------+
CLossProfitManager::CLossProfitManager()
{
//---
m_valid_indexes_size = ArrayResize(m_valid_indexes, 0);
m_profits_size = ArrayResize(m_profits, 0);
m_losses_size = ArrayResize(m_losses, 0);
m_last_idx_profit_sup = -1;
m_last_idx_loss_sup = -1;
//---
empty_obj = new CLossLossGmlpo<CLossProfitMoney<CLossProfit>>(true, NULL);
for(int i = 0; i < LOSS_PROFIT_COUNT; i++)
{
m_losses_profits[i] = NULL;
m_is_add[i] = false;
}
}
//+------------------------------------------------------------------+
CLossProfitManager::~CLossProfitManager(void)
2026-02-01 16:17:01 -05:00
{
2026-01-28 12:07:14 -05:00
#ifdef MORE_INFO_LOSS_PROFIT_DEFINE
FastLog(FUNCION_ACTUAL, INFO_TEXT, "Eliminado en CLossProfitManager");
2026-03-05 12:10:29 -05:00
#endif
2026-01-28 12:07:14 -05:00
delete empty_obj;
Clear(); // Eliminamos todos los punteros
}
2026-01-28 13:02:22 -05:00
//+------------------------------------------------------------------+
2026-01-28 12:07:14 -05:00
//| |
//+------------------------------------------------------------------+
void CLossProfitManager::Summary(void) const
{
Print("------------");
Print("Number of losses to revise: ", m_losses_size);
Print("Number of profits to revise: ", m_profits_size);
Print("Total losses and profits: ", SizeValids());
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool CLossProfitManager::MaxProfitIsSuperated(void) const
{
for(int i = 0; i < m_profits_size; i++)
{
if(m_profits[i].IsSuperated())
{
2026-01-31 19:44:40 -05:00
((CLossProfitManager*)&this).m_last_idx_profit_sup = i;
2026-01-28 12:07:14 -05:00
return true;
}
}
return false;
}
//+------------------------------------------------------------------+
bool CLossProfitManager::MaxLossIsSuperated(void) const
{