주시
1
0
포크
이미 MQLArticles을(를) 포크했습니다
0
원본 프로젝트 nique_372/MQLArticles
MQLArticles/Utils/FA/README.md
60 라인
2.7 KiB
Markdown
Nique_372
2026-09-06 11:15:27 -05:00
[← Utils](../README.md)
# Utils/FA
Nique_372
2026-10-22 10:28:48 -05:00
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`.
Nique_372
2026-09-06 11:15:27 -05:00
## Main features
Nique_372
2026-10-25 11:50:52 -05:00
- **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.
Nique_372
2026-10-30 09:44:06 -05:00
- **New-bar detection**: `CBarControler` (any timeframe) plus faster variants (`CBarControlerFast`, `CBarControlerFastW1`, `CBarControlerFastMN1` and the per-timeframe family `CBarControlerFastMinors_<TF>`, e.g. `CBarControlerFastMinors_D1`).
Nique_372
2026-10-22 10:28:48 -05:00
- **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).
Nique_372
2026-09-06 11:15:27 -05:00
## Basic usage
Nique_372
2026-10-22 10:28:48 -05:00
### New bar
Nique_372
2026-09-06 11:15:27 -05:00
```mql5
Nique_372
2026-10-22 10:28:48 -05:00
TSN::CBarControler bar_ctrl(PERIOD_H1);
void OnTick()
{
if(bar_ctrl.IsNewBar(TimeCurrent()))
{
// new H1 bar
}
}
Nique_372
2026-09-06 11:15:27 -05:00
```
Nique_372
2026-10-25 11:50:52 -05:00
### 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.
Nique_372
2026-10-22 10:28:48 -05:00
Nique_372
2026-10-25 11:50:52 -05:00
```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
Nique_372
2026-09-06 11:15:27 -05:00
```
Nique_372
2026-10-22 10:28:48 -05:00
### ATR and diff
Nique_372
2026-09-06 11:15:27 -05:00
```mql5
Nique_372
2026-10-22 10:28:48 -05:00
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();
Nique_372
2026-09-06 11:15:27 -05:00
```
Nique_372
2026-10-25 11:50:52 -05:00
## 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`.
Nique_372
2026-09-06 11:15:27 -05:00
> Only the most representative classes are shown here.