MQLArticles/Utils/TfI/Base.mqh

86 lines
3.6 KiB
MQL5

2026-07-31 13:43:33 -05:00
//+------------------------------------------------------------------+
//| Base.mqh |
//| Copyright 2026, Niquel Mendoza |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2026, Niquel Mendoza"
#property link "https://www.mql5.com"
#property strict
#ifndef MQLARITCLES_UTILS_TFI_BASE_MQH
#define MQLARITCLES_UTILS_TFI_BASE_MQH
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
#include "Main.mqh"
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
namespace TSN
{
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
class CTimeframe
{
public:
CTimeframe(void) {}
~CTimeframe(void) {}
//--- To Idx
static __forceinline char ToIdx(ENUM_TIMEFRAMES v);
static __forceinline char ToIdxWVer(const ENUM_TIMEFRAMES v);
//--- Period second fast
static __forceinline int PeriodSecondsFast(ENUM_TIMEFRAMES tf);
static __forceinline int PeriodSecondsFastSeg(const ENUM_TIMEFRAMES tf);
//--- Funciones de utilidad
static __forceinline string ToStrUpper(ENUM_TIMEFRAMES tf) { return g_mqlarticles_tfi_desc[ToIdx(tf)].short_name_up; }
static __forceinline string ToStrLower(ENUM_TIMEFRAMES tf) { return g_mqlarticles_tfi_desc[ToIdx(tf)].short_name_lo; }
static __forceinline string ToStrEnum(ENUM_TIMEFRAMES tf) { return g_mqlarticles_tfi_desc[ToIdx(tf)].full_name; }
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
static __forceinline char CTimeframe::ToIdx(ENUM_TIMEFRAMES v)
2026-07-31 13:43:33 -05:00
{
if(v == PERIOD_CURRENT)
v = _Period;
ulong h = ((ulong)v ^ g_mqlarticles_tfi_out_seeds[int(v & MQLARTICLES_TFI_BUCKETS_SIZE_L)]) * 0x9E3779B97F4A7C15;
h ^= h >> 32;
2026-07-31 13:54:24 -05:00
return char(h & MQLARTICLES_TFI_FINAL_TSIZE_L);
}
//+------------------------------------------------------------------+
static __forceinline char CTimeframe::ToIdxWVer(const ENUM_TIMEFRAMES v)
2026-07-31 13:54:24 -05:00
{
ulong h = ((ulong)v ^ g_mqlarticles_tfi_out_seeds[int(v & MQLARTICLES_TFI_BUCKETS_SIZE_L)]) * 0x9E3779B97F4A7C15;
h ^= h >> 32;
return char(h & MQLARTICLES_TFI_FINAL_TSIZE_L);
2026-07-31 13:43:33 -05:00
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
// Referencia: iCanvas_CB.mqh
static __forceinline int CTimeframe::PeriodSecondsFast(ENUM_TIMEFRAMES tf)
{
if(tf == PERIOD_CURRENT)
tf = _Period;
const int tff = tf >> 14;
return (tff == 0) ? (tf & 0x0FFF) * 60 : (tff == 1) ? (tf & 0x0FFF) * 3600 : (tff == 2) ? 604800 : 2592000;
}
//+------------------------------------------------------------------+
static __forceinline int CTimeframe::PeriodSecondsFastSeg(const ENUM_TIMEFRAMES tf)
{
const int tff = tf >> 14;
return (tff == 0) ? (tf & 0x0FFF) * 60 : (tff == 1) ? (tf & 0x0FFF) * 3600 : (tff == 2) ? 604800 : 2592000;
}
2026-07-31 13:43:33 -05:00
}
#endif // MQLARITCLES_UTILS_TFI_BASE_MQH