Utils/FA
Shared building blocks used across the ecosystem: ATR access, new-bar detection, ATR/points diffs and day/week/month events. Everything lives in namespace TSN.
Main features
- ATR (
Atr/, includeAtr/All.mqh):CAtrwraps aniATRhandle with a cached buffer. The calculated-by-hand family lives inAtr/Emb:CAtrOptimizedZero(bar index 0) andCAtrOptimizedNonZero(index > 0), both deriving fromCAtrOptimized, andCAtrEmbCreator::Createreturns the right one. - New-bar detection:
CBarControler(any timeframe) plus faster variants (CBarControlerFast,CBarControlerFastW1,CBarControlerFastMN1and the per-timeframe familyCBarControlerFastMinors_<TF>, e.g.CBarControlerFastMinors_D1). - Diffs: a distance that is either fixed points or ATR × multiplier (
CDiff,CDiffPoint,CDiffAtr, created withCreateDiffptr). - Day / week / month events: register an object once and get
OnNewDay/OnNewWeek/OnNewMonth(CBasicEvents,CAllClassEventsBasic). - Misc:
CSuspendChecker(detects the terminal being suspended) andCGraphConversion(price ↔ pixels).
Basic usage
New bar
TSN::CBarControler bar_ctrl(PERIOD_H1);
void OnTick()
{
if(bar_ctrl.IsNewBar(TimeCurrent()))
{
// new H1 bar
}
}
ATR
Two ways to get it:
CAtr: use it when you need a buffer with history or several bar indexes (it reads aniATRhandle).CAtrOptimizedZero/CAtrOptimizedNonZero: use them when you only need the ATR value of one bar index; they calculate it on each new bar without an indicator handle.
// Calculated by hand: the creator picks Zero (index 0) or NonZero (index > 0)
TSN::CAtrOptimized* g_atr_opt = TSN::CAtrEmbCreator::Create(_Period, _Symbol, 0, 14); // timeframe, symbol, bar index, period
// on every tick:
double atr = g_atr_opt.GetAtrValue(TimeCurrent());
// the caller owns the pointer: delete it when done
ATR and diff
TSN::CAtr g_atr;
g_atr.Create(_Period, _Symbol, 14, true); // timeframe, symbol, period, execute_on_bar
TSN::CDiff* diff = TSN::CreateDiffptr(TSN::MODE_DIFF_BY_ATR, _Symbol, &g_atr, 0, 1.5); // idx 0, ATR x 1.5
// on every new bar:
diff.OnNewBar();
double distance = diff.Diff();
Layout
Atr/:CAtr(Ind.mqh) andAtr/Emb/(CAtrOptimized*+CAtrEmbCreator). IncludeAtr/All.mqhfor everything.BarControler.mqh: new-bar detection.DiffCalc.mqh:CDiffand derived (includesAtr/All.mqh).Events.mqh,Managers.mqh,ClasesBases.mqh: events, manager base classes, misc.
CNewBarManageris not part of FA: it lives inUtils/TFManager.mqh. Only the most representative classes are shown here.