//+------------------------------------------------------------------+ //| Custom.mqh | //| Copyright 2000-2025, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #include "Indicator.mqh" //+------------------------------------------------------------------+ //| Class CiCustom. | //| Purpose: Class of custom indicators. | //| Derives from class CIndicator. | //+------------------------------------------------------------------+ class CiCustom : public CIndicator { protected: int m_num_params; // number of creation parameters MqlParam m_params[]; // creation parameters public: CiCustom(void); ~CiCustom(void); //--- methods of access to protected data bool NumBuffers(const int buffers); int NumParams(void) const { return(m_num_params); } ENUM_DATATYPE ParamType(const int ind) const; long ParamLong(const int ind) const; double ParamDouble(const int ind) const; string ParamString(const int ind) const; //--- method of identifying virtual int Type(void) const { return(IND_CUSTOM); } protected: //--- methods of tuning virtual bool Initialize(const string symbol,const ENUM_TIMEFRAMES period,const int num_params,const MqlParam ¶ms[]); }; //+------------------------------------------------------------------+ //| Constructor | //+------------------------------------------------------------------+ CiCustom::CiCustom(void) : m_num_params(0) { } //+------------------------------------------------------------------+ //| Destructor | //+------------------------------------------------------------------+ CiCustom::~CiCustom(void) { } //+------------------------------------------------------------------+ //| Set number of buffers of indicator | //+------------------------------------------------------------------+ bool CiCustom::NumBuffers(const int buffers) { bool result=true; //--- if(m_buffers_total==0) { m_buffers_total=buffers; return(true); } if(m_buffers_total!=buffers) { Shutdown(); result=CreateBuffers(m_symbol,m_period,buffers); if(result) { //--- create buffers for(int i=0;i=m_num_params) return(WRONG_VALUE); //--- return(m_params[ind].type); } //+------------------------------------------------------------------+ //| Get specified parameter of creatiob as a long value | //+------------------------------------------------------------------+ long CiCustom::ParamLong(const int ind) const { if(ind=m_num_params) return(EMPTY_VALUE); switch(m_params[ind].type) { case TYPE_DOUBLE: case TYPE_FLOAT: break; default: return(EMPTY_VALUE); } //--- return(m_params[ind].double_value); } //+------------------------------------------------------------------+ //| Get specified parameter of creation as a string value | //+------------------------------------------------------------------+ string CiCustom::ParamString(const int ind) const { if(ind>=m_num_params || m_params[ind].type!=TYPE_STRING) return(""); //--- return(m_params[ind].string_value); } //+------------------------------------------------------------------+ //| Initialize the indicator with universal parameters | //+------------------------------------------------------------------+ bool CiCustom::Initialize(const string symbol,const ENUM_TIMEFRAMES period,const int num_params,const MqlParam ¶ms[]) { int i; //--- tune if(m_buffers_total==0) m_buffers_total=256; if(CreateBuffers(symbol,period,m_buffers_total)) { //--- string of status of drawing m_name ="Custom "+params[0].string_value; m_status="("+symbol+","+PeriodDescription(); for(i=1;i"; break; } } m_status=m_status+") H="+IntegerToString(m_handle); //--- save settings ArrayResize(m_params,num_params); for(i=0;i