geforkt von nique_372/MQLArticles
//+------------------------------------------------------------------+
| |
//| Atr.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_ATR_MQH
| |
#define MQLARTICLES_POSMGMT_BE_IMP_ATR_MQH
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
#include "..\\Base\\BEBase.mqh"
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
namespace TSN
| |
{
| |
//+------------------------------------------------------------------+
| |
//| Class to apply break even based on atr |
| |
//+------------------------------------------------------------------+
| |
#define TSNMQLART_POSMGMT_BE_ATR_NPARAMS (3)
| |
#define TSNMQLART_POSMGMT_BE_ATR_I_ATRPTR (0)
| |
#define TSNMQLART_POSMGMT_BE_ATR_I_ATRMUL (1)
| |
#define TSNMQLART_POSMGMT_BE_ATR_I_ATR_EMUL (2)
| |
| |
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
class CBreakEvenAtr : public CBreakEvenBase
| |
{
| |
private:
| |
CAtrOptimized* m_atr_ultra;
| |
double m_atr_multiplier_be;
| |
double m_atr_multiplier_extra_be;
| |
| |
public:
| |
CBreakEvenAtr(string symbol_, ulong magic_)
| |
: CBreakEvenBase(symbol_, magic_, TSNMQLART_POSMGMT_BE_ATR_NPARAMS),
| |
m_atr_ultra(NULL), m_atr_multiplier_be(1.0), m_atr_multiplier_extra_be(1.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 ¶ms[]) override final;
| |
};
| |
| |
//+------------------------------------------------------------------+
| |
//| Function to set CBreakEvenAtr variables with MqlParams array |
| |
//+------------------------------------------------------------------+
| |
bool CBreakEvenAtr::Set(const BreakEvenParams ¶ms[])
| |
{
| |
//---
| |
m_atr_ultra = params[TSNMQLART_POSMGMT_BE_ATR_I_ATRPTR].atr_pointer_value;
| |
m_atr_multiplier_be = params[TSNMQLART_POSMGMT_BE_ATR_I_ATRMUL].double_value;
| |
m_atr_multiplier_extra_be = params[TSNMQLART_POSMGMT_BE_ATR_I_ATR_EMUL].double_value;
| |
| |
//---
| |
if(m_atr_multiplier_extra_be >= m_atr_multiplier_be)
| |
return CErrorTrace::FailInit<CBasicBEFormater>(TSNMQLART_BE_TYPES_ERR_ATR_INVALID_EXTRABE_VAL, CBitsReinterprete::ToBasic<ulong, double>(m_atr_multiplier_extra_be));
| |
if(CheckPointer(m_atr_ultra) == POINTER_INVALID)
| |
return CErrorTrace::FailInit<CBasicBEFormater>(TSNMQLART_BE_TYPES_ERR_ATR_PTR_INVALID, 0);
| |
return true;
| |
}
| |
| |
| |
//+------------------------------------------------------------------+
| |
//| Function to add an element to the positions array |
| |
//+------------------------------------------------------------------+
| |
bool CBreakEvenAtr::Add(ulong post_ticket, double open_price, double sl_price, ENUM_POSITION_TYPE position_type, datetime open_time, const string & sym)
| |
{
| |
if(sym != m_symbol)
| |
return CErrorTrace::FailInit<CBasicBEFormater>(TSNMQLART_BE_TYPES_ERR_INV_SYMBOL, post_ticket);
| |
| |
//---
| |
MQLARTICLES_BREAKEVEN_PROLOGO(position_type, post_ticket)
| |
| |
//---
| |
const double val = m_atr_ultra.GetAtrValue(open_time);
| |
m_pos_be[m_pos_be_s].breakeven_price = position_type == POSITION_TYPE_BUY ? open_price + (val * m_atr_multiplier_extra_be) : open_price - (val * m_atr_multiplier_extra_be);
| |
m_pos_be[m_pos_be_s].price_to_beat = position_type == POSITION_TYPE_BUY ? open_price + (val * m_atr_multiplier_be) : open_price - (val * m_atr_multiplier_be);
| |
| |
//---
| |
m_pos_be_s++;
| |
| |
//---
| |
return true;
| |
}
| |
}
| |
| |
#endif // MQLARTICLES_POSMGMT_BE_IMP_ATR_MQH
|