MQLArticles/PosMgmt/BE/Imp/BasicPoints.mqh
90 行
4.1 KiB
MQL5
Nique_372
2026-10-29 11:36:56 -05:00
//+------------------------------------------------------------------+
//| BasicPoints.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_IMP_BASICPOINTS_MQH
#define MQLARTICLES_POSMGMT_BE_IMP_BASICPOINTS_MQH
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
#include "..\\Base\\BEBase.mqh"
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
namespace TSN
{
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
#define TSNMQLART_POSMGMT_BE_BPOINTS_NPARMS (2)
#define TSNMQLART_POSMGMT_BE_BPOINTS_I_POINT_BE (0)
#define TSNMQLART_POSMGMT_BE_BPOINTS_I_EPOINT_BE (1)
//+------------------------------------------------------------------+
//| class CBreakEvenSimple |
//+------------------------------------------------------------------+
class CBreakEvenSimple : public CBreakEvenBase
{
private:
int m_extra_points_be, m_points_be;
public:
CBreakEvenSimple(string symbol_, ulong magic_)
: CBreakEvenBase(symbol_, magic_, TSNMQLART_POSMGMT_BE_BPOINTS_NPARMS), m_extra_points_be(0), m_points_be(0) {}
//---
bool Add(ulong post_ticket, double open_price, double sl_price, ENUM_POSITION_TYPE position_type, datetime open_time, const string& sym) override final;
bool Set(const BreakEvenParams &params[]) override final;
};
//+------------------------------------------------------------------+
//| Set attributes of CBreakEvenSimple class with MqlParam array |
//+------------------------------------------------------------------+
bool CBreakEvenSimple::Set(const BreakEvenParams &params[])
{
//---
m_points_be = (int)params[TSNMQLART_POSMGMT_BE_BPOINTS_I_POINT_BE].integer_value; //0
m_extra_points_be = (int)params[TSNMQLART_POSMGMT_BE_BPOINTS_I_EPOINT_BE].integer_value; //1
//---
if(m_extra_points_be < 0)
Nique_372
2026-11-06 10:40:44 -05:00
return CErrorTrace::FailInit<CBasicBEFormater>(TSNMQLART_BE_TYPES_ERR_BPOINTS_INV_EPOINTSBE, m_extra_points_be);
Nique_372
2026-10-29 11:36:56 -05:00
if(m_extra_points_be >= m_points_be)
Nique_372
2026-11-06 10:40:44 -05:00
return CErrorTrace::FailInit<CBasicBEFormater>(TSNMQLART_BE_TYPES_ERR_BPOINTS_EPOINTS_MUSTBE_MINOR_PNORM, ulong(uint(m_extra_points_be)) | ulong(uint(m_points_be)) << 32);
Nique_372
2026-10-29 11:36:56 -05:00
return true;
}
Nique_372
2026-10-29 17:44:49 -05:00
//+----------------------------------------------------------------------------------------------+
//| Create a new structure and add it to the main array using the 'AddToArrayBe' function |
//+----------------------------------------------------------------------------------------------+
Nique_372
2026-10-29 21:39:16 -05:00
bool CBreakEvenSimple::Add(ulong post_ticket, double open_price, double sl_price, ENUM_POSITION_TYPE position_type, datetime open_time, const string& sym)
Nique_372
2026-10-29 17:44:49 -05:00
{
Nique_372
2026-10-29 21:39:16 -05:00
//---
Nique_372
2026-10-29 17:44:49 -05:00
if(sym != m_symbol)
Nique_372
2026-11-06 10:40:44 -05:00
return CErrorTrace::FailInit<CBasicBEFormater>(TSNMQLART_BE_TYPES_ERR_INV_SYMBOL, post_ticket);
Nique_372
2026-10-29 17:44:49 -05:00
//---
Nique_372
2026-11-01 17:28:51 -05:00
MQLARTICLES_BREAKEVEN_PROLOGO(position_type, post_ticket)
//---
Nique_372
2026-10-29 17:44:49 -05:00
m_pos_be[m_pos_be_s].breakeven_price = position_type == POSITION_TYPE_BUY ? open_price + (m_point_value * m_extra_points_be) : open_price - (m_point_value * m_extra_points_be);
m_pos_be[m_pos_be_s].price_to_beat = position_type == POSITION_TYPE_BUY ? open_price + (m_point_value * m_points_be) : open_price - (m_point_value * m_points_be) ;
Nique_372
2026-11-01 17:28:51 -05:00
//---
m_pos_be_s++;
Nique_372
2026-10-29 17:44:49 -05:00
//---
return true;
}
Nique_372
2026-10-29 11:36:56 -05:00
//---
}
#endif // MQLARTICLES_POSMGMT_BE_IMP_BASICPOINTS_MQH