203 lines
7.3 KiB
MQL5
//+------------------------------------------------------------------+
| |||
//| SymbolIct.mqh |
| |||
//| Copyright 2026, Niquel Mendoza. |
| |||
//| https://www.mql5.com/ |
| |||
//+------------------------------------------------------------------+
| |||
#property copyright "Copyright 2026, Niquel Mendoza."
| |||
#property link "https://www.mql5.com/"
| |||
#property strict
| |||
| |||
| |||
#ifndef ICT_LIBRARY_BASE_CLASSDEF_MQH
| |||
#define ICT_LIBRARY_BASE_CLASSDEF_MQH
| |||
| |||
//+------------------------------------------------------------------+
| |||
//| |
| |||
//+------------------------------------------------------------------+
| |||
#include "Defines.mqh"
| |||
| |||
//+------------------------------------------------------------------+
| |||
//| Clase base para manejar simbolos |
| |||
//+------------------------------------------------------------------+
| |||
class CIctSymbol final
| |||
{
| |||
private:
| |||
int16_t obj_count;
| |||
| |||
public:
| |||
CIctSymbol(const string& symb);
| |||
~CIctSymbol() {}
| |||
| |||
//---
| |||
const string symbol;
| |||
MqlTick _tick;
| |||
const double point_value;
| |||
const int8_t _digits;
| |||
| |||
//---
| |||
__forceinline void GetTick(MqlTick& tick) const;
| |||
datetime tick_time; // Hora de la última actualización de precios
| |||
double tick_bid; // Precio actual Bid
| |||
double tick_ask; // Precio actual Ask
| |||
double tick_last; // Precio actual de la última transacción (Last)
| |||
ulong tick_volume; // Volumen para el precio actual Last
| |||
long tick_time_msc; // Hora de la última actualización de los precios en milisegundos
| |||
uint tick_flags; // Banderas de los tics
| |||
| |||
| |||
//--- Actulizacion data
| |||
void UpdateTick();
| |||
inline void IncrementCoount() { obj_count++; }
| |||
inline void DecrementCoount() { obj_count--; }
| |||
| |||
//--- Utilidades
| |||
inline double DistanceToPointDouble(double distance) const { return distance / point_value; }
| |||
inline long DistanceToPointLong(double distance) const { return long(::MathRound(distance / point_value)); }
| |||
| |||
//--- Getters
| |||
inline int GetCounter() const { return obj_count; }
| |||
__forceinline bool IsPriceEqual(const double v1, const double v2) const { return fabs(v1 - v2) < this.point_value; }
| |||
| |||
//--- Operadores
| |||
bool operator==(const CIctSymbol &other) const { return this.symbol == other.symbol; }
| |||
bool operator==(const CIctSymbol* other) const { return other == NULL ? false : this.symbol == other.symbol; }
| |||
};
| |||
| |||
//+------------------------------------------------------------------+
| |||
//| |
| |||
//+------------------------------------------------------------------+
| |||
CIctSymbol::CIctSymbol(const string& symb)
| |||
: symbol(symb), point_value(::SymbolInfoDouble(symb, SYMBOL_POINT)), _digits((int8_t)::SymbolInfoInteger(this.symbol, SYMBOL_DIGITS))
| |||
{
| |||
}
| |||
| |||
| |||
//+------------------------------------------------------------------+
| |||
//| |
| |||
//+------------------------------------------------------------------+
| |||
void CIctSymbol::UpdateTick(void)
| |||
{
| |||
::SymbolInfoTick(this.symbol, this._tick);
| |||
this.tick_ask = _tick.ask;
| |||
this.tick_bid = _tick.bid;
| |||
this.tick_flags = _tick.flags;
| |||
this.tick_last = _tick.last;
| |||
this.tick_time = _tick.time;
| |||
this.tick_time_msc = _tick.time_msc;
| |||
this.tick_volume = _tick.volume;
| |||
}
| |||
//+------------------------------------------------------------------+
| |||
__forceinline void CIctSymbol::GetTick(MqlTick &tick) const
| |||
{
| |||
tick = _tick;
| |||
}
| |||
| |||
//+------------------------------------------------------------------+
| |||
//| |
| |||
//+------------------------------------------------------------------+
| |||
interface IHandlerAddBlock
| |||
{
| |||
inline bool Add(Bloques &new_bloque, const ENUM_ORDERBLOCKS_TYPE type);
| |||
inline bool ShowObjects() const;
| |||
};
| |||
| |||
//+------------------------------------------------------------------+
| |||
//| |
| |||
//+------------------------------------------------------------------+
| |||
struct IctLibBloqueInitConfig
| |||
{
| |||
//--- Nombres y tooltips
| |||
string name_bull_toltip;
| |||
string name_bear_toltip;
| |||
string name_bull_toltip_50;
| |||
string name_bear_toltip_50;
| |||
string bull_code;
| |||
string bear_code;
| |||
| |||
//---
| |||
string obj_code;
| |||
| |||
//---
| |||
IHandlerAddBlock* handler;
| |||
CIctSymbol* symbol_info;
| |||
| |||
//---
| |||
int handle;
| |||
| |||
//--- Datos de dibujado
| |||
//-- Bloques
| |||
color clr_bloque_alcista;
| |||
color clr_bloque_bajista;
| |||
ENUM_LINE_STYLE style_block;
| |||
int width;
| |||
| |||
//-- Linea
| |||
ENUM_LINE_STYLE line_style_mitad;
| |||
int width_line_mitad;
| |||
color clr_mitad_bloque_alcista;
| |||
color clr_mitad_bloque_bajista;
| |||
| |||
//---
| |||
bool mostrar_la_mitad;
| |||
bool fill;
| |||
};
| |||
| |||
//---
| |||
class IIctLibCustomBlock : public CLoggerBase
| |||
{
| |||
protected:
| |||
//---
| |||
string m_obj_code;
| |||
| |||
//--- Nombres y tooltips
| |||
string m_name_bull_toltip;
| |||
string m_name_bear_toltip;
| |||
string m_name_bull_toltip_50;
| |||
string m_name_bear_toltip_50;
| |||
string m_bull_code;
| |||
string m_bear_code;
| |||
| |||
//---
| |||
IHandlerAddBlock* m_handler;
| |||
CIctSymbol* m_symbol_info;
| |||
| |||
//---
| |||
int m_handle;
| |||
| |||
//--- Datos de dibujado
| |||
//-- Bloques
| |||
color m_clr_bloque_alcista;
| |||
color m_clr_bloque_bajista;
| |||
ENUM_LINE_STYLE m_style_block;
| |||
bool m_fill;
| |||
int m_width;
| |||
| |||
//-- Linea
| |||
bool m_mostrar_la_mitad;
| |||
ENUM_LINE_STYLE m_line_style_mitad;
| |||
int m_width_line_mitad;
| |||
color m_clr_mitad_bloque_alcista;
| |||
color m_clr_mitad_bloque_bajista;
| |||
| |||
| |||
public:
| |||
IIctLibCustomBlock() {}
| |||
~IIctLibCustomBlock() { if(CheckPointer(m_handler) == POINTER_DYNAMIC) delete m_handler;}
| |||
| |||
//---
| |||
virtual void OnSummary() const {} // Cunado se llama a Summary
| |||
virtual void OnChangeTimeframe(const ENUM_TIMEFRAMES new_timeframe) { } // Cuando se llama a ChangeTimeframe
| |||
virtual void OnChangeDespuesChartId() {} // Cuando se cambia de grafico (llamar a las funciones espciales para saber el nuevo subwin o chart_id)
| |||
virtual void Init(const IctLibBloqueInitConfig& config) = 0;
| |||
virtual void OnDeleteAll() {}
| |||
virtual void OnGetBlocks(bool& prev_data_calculated, const datetime extra_time, const bool show_concepts) = 0;
| |||
| |||
| |||
//---
| |||
virtual inline int Id() const = 0; // Id para distinguir de otros bloques custom
| |||
virtual inline bool UpdateConcepts() const = 0; // Actuliza los conceptos (rectangulos)
| |||
virtual inline uint8_t ModifyFlags() const = 0; // Banderas de modificacion
| |||
};
| |||
| |||
#endif // ICT_LIBRARY_BASE_CLASSDEF_MQH
| |||
//+------------------------------------------------------------------+
|