| [← Utils](../README.md)
|
|
|
| # 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/`, include `Atr/All.mqh`): `CAtr` wraps an `iATR` handle with a cached buffer. The calculated-by-hand family lives in `Atr/Emb`: `CAtrOptimizedZero` (bar index 0) and `CAtrOptimizedNonZero` (index > 0), both deriving from `CAtrOptimized`, and `CAtrEmbCreator::Create` returns the right one.
|
| - **New-bar detection**: `CBarControler` (any timeframe) plus faster variants (`CBarControlerFast`, `CBarControlerFastW1`, `CBarControlerFastMN1` and the per-timeframe family `CBarControlerFastMinors_<TF>`, e.g. `CBarControlerFastMinors_D1`).
|
| - **Diffs**: a distance that is either fixed points or ATR × multiplier (`CDiff`, `CDiffPoint`, `CDiffAtr`, created with `CreateDiffptr`).
|
| - **Day / week / month events**: register an object once and get `OnNewDay` / `OnNewWeek` / `OnNewMonth` (`CBasicEvents`, `CAllClassEventsBasic`).
|
| - **Misc**: `CSuspendChecker` (detects the terminal being suspended) and `CGraphConversion` (price ↔ pixels).
|
|
|
| ## Basic usage
|
|
|
| ### New bar
|
| ```mql5
|
| 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 an `iATR` handle).
|
| - **`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.
|
|
|
| ```mql5
|
| // 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
|
| ```mql5
|
| 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`) and `Atr/Emb/` (`CAtrOptimized*` + `CAtrEmbCreator`). Include `Atr/All.mqh` for everything.
|
| - `BarControler.mqh`: new-bar detection.
|
| - `DiffCalc.mqh`: `CDiff` and derived (includes `Atr/All.mqh`).
|
| - `Events.mqh`, `Managers.mqh`, `ClasesBases.mqh`: events, manager base classes, misc.
|
|
|
| > `CNewBarManager` is not part of FA: it lives in `Utils/TFManager.mqh`.
|
| > Only the most representative classes are shown here.
|