ICTLibraryEasy/Src/Base/Data.mqh
Nique_372 11e9098787
2026-05-25 11:41:23 -05:00

95 lines
No EOL
4 KiB
MQL5

//+------------------------------------------------------------------+
//| Data.mqh |
//| Copyright 2025, Niquel Mendoza. |
//| https://www.mql5.com/es/users/nique_372/news |
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, Niquel Mendoza."
#property link "https://www.mql5.com/es/users/nique_372/news"
#property strict
#ifndef ICTLIBRARYEASY_SRC_BASE_DATA_MQH
#define ICTLIBRARYEASY_SRC_BASE_DATA_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;
}
//+------------------------------------------------------------------+
#endif // ICTLIBRARYEASY_SRC_BASE_DATA_MQH