2025-10-01 12:22:08 -05:00
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//| BarControler.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
|
|
|
|
|
|
2025-11-10 09:33:53 -05:00
|
|
|
#ifndef MQLARTICLES_UTILS_FA_BARCONTROLER_MQH
|
|
|
|
|
#define MQLARTICLES_UTILS_FA_BARCONTROLER_MQH
|
2025-10-01 12:22:08 -05:00
|
|
|
|
|
|
|
|
#include "FuncionesBases.mqh"
|
|
|
|
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//| Class to control the opening of a candle |
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
class CBarControler
|
|
|
|
|
{
|
|
|
|
|
private:
|
2025-11-07 12:13:47 -05:00
|
|
|
const string symbol;
|
2025-10-01 12:22:08 -05:00
|
|
|
datetime next_time;
|
|
|
|
|
datetime prev_time;
|
2025-11-07 12:13:47 -05:00
|
|
|
const ENUM_TIMEFRAMES bar_timeframe;
|
|
|
|
|
const int period_in_seconds;
|
2025-10-01 12:22:08 -05:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
CBarControler(ENUM_TIMEFRAMES _timeframe, string _symbol);
|
|
|
|
|
inline int PeriodsInSeconds()const { return period_in_seconds; }
|
|
|
|
|
inline ENUM_TIMEFRAMES Timeframe() const { return bar_timeframe; }
|
2025-11-07 12:13:47 -05:00
|
|
|
bool IsNewBar(datetime curr_time);
|
2025-10-01 12:22:08 -05:00
|
|
|
inline datetime GetNextPrevBarTime() const { return prev_time; }
|
|
|
|
|
};
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
CBarControler::CBarControler(ENUM_TIMEFRAMES _timeframe, string _symbol)
|
2025-11-07 12:13:47 -05:00
|
|
|
: next_time(wrong_datetime), prev_time(wrong_datetime), period_in_seconds(PeriodSeconds(_timeframe)), symbol(_symbol), bar_timeframe(_timeframe)
|
2025-10-01 12:22:08 -05:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
//+------------------------------------------------------------------+
|
2025-11-07 12:13:47 -05:00
|
|
|
bool CBarControler::IsNewBar(datetime curr_time)
|
2025-10-01 12:22:08 -05:00
|
|
|
{
|
|
|
|
|
if(curr_time >= next_time)
|
|
|
|
|
{
|
|
|
|
|
prev_time = next_time;
|
2025-11-07 12:13:47 -05:00
|
|
|
next_time = iTime(symbol, bar_timeframe, 0) + (bar_timeframe == PERIOD_MN1 ? SecondsInMonth(curr_time) : period_in_seconds);
|
2025-10-01 12:22:08 -05:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//| Class to control the opening of a candle ("fast") |
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
class CBarControlerFast
|
|
|
|
|
{
|
|
|
|
|
private:
|
2025-11-07 12:13:47 -05:00
|
|
|
const string symbol;
|
2025-10-01 12:22:08 -05:00
|
|
|
datetime next_time;
|
2025-11-07 12:13:47 -05:00
|
|
|
const ENUM_TIMEFRAMES bar_timeframe;
|
|
|
|
|
const int period_in_seconds;
|
|
|
|
|
const bool is_mn1;
|
2025-10-01 12:22:08 -05:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
CBarControlerFast(ENUM_TIMEFRAMES _timeframe, string _symbol);
|
|
|
|
|
inline ENUM_TIMEFRAMES Timeframe() const { return bar_timeframe; }
|
2025-11-07 12:13:47 -05:00
|
|
|
bool IsNewBar(datetime curr_time);
|
2025-10-01 12:22:08 -05:00
|
|
|
};
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
CBarControlerFast::CBarControlerFast(ENUM_TIMEFRAMES _timeframe, string _symbol)
|
2025-11-07 12:13:47 -05:00
|
|
|
: next_time(wrong_datetime), period_in_seconds(PeriodSeconds(_timeframe)), bar_timeframe(_timeframe), symbol(_symbol), is_mn1((_timeframe == PERIOD_MN1))
|
2025-10-01 12:22:08 -05:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
bool CBarControlerFast::IsNewBar(datetime curr_time)
|
|
|
|
|
{
|
|
|
|
|
if(curr_time >= next_time)
|
|
|
|
|
{
|
|
|
|
|
next_time = iTime(symbol, bar_timeframe, 0) + (!is_mn1 ? period_in_seconds : SecondsInMonth(curr_time));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-10 09:33:53 -05:00
|
|
|
#endif // MQLARTICLES_UTILS_FA_BARCONTROLER_MQH
|
2025-11-07 12:13:47 -05:00
|
|
|
//+------------------------------------------------------------------+
|