//+------------------------------------------------------------------+ //| Calc.mqh | //| | //| Helix for MetaTrader — Demo | //| | //| MIT License | //| Copyright (c) 2025 Douglas Rechia | //| | //| Common technical analysis functions built on knitpkg-mt4-bar. | //| Provides lightweight implementations of SMA, ATR, and other | //| indicators for use in Helix packages and MetaTrader projects. | //| | //| DISCLAIMER: | //| This code is provided AS-IS for educational purposes only. | //| No warranty is given. The author assumes no liability for any | //| damages or legal consequences arising from its use. | //| | //+------------------------------------------------------------------+ //------------------------------------------------------------------ // Development autocomplete — resolves dependencies and enables // MetaEditor IntelliSense; automatically neutralized by Helix // installer. // Run `kp-mt autocomplete` to regenerate. //------------------------------------------------------------------ #include "../../../autocomplete/autocomplete.mqh" //------------------------------------------------------------------ // Helix include directives — used by Helix installer at the time // this package is installed as a dependency into another Helix // project. //------------------------------------------------------------------ /* @knitpkg:include "douglasrechia/bar/TimeSeries.mqh" */ /* @knitpkg:include "douglasrechia/bar/Bar.mqh" */ //+------------------------------------------------------------------+ //| Simple Moving Average | //+------------------------------------------------------------------+ double SMA(ITimeSeries &series, int period, int shift = 0) { if(series.Size() < (period + shift)) return 0.0; double sum = 0.0; for(int i = shift; i < shift + period; i++) sum += series.ValueAtShift(i); return sum / period; } //+------------------------------------------------------------------+ //| Average True Range | //+------------------------------------------------------------------+ double ATR(IBar &bar, int period, int shift = 0) { if(bar.Size() < (period + shift + 1)) return 0.0; double sum = 0.0; for(int i = shift; i < shift + period; i++) { double tr = MathMax(bar.High(i) - bar.Low(i), MathMax(MathAbs(bar.High(i) - bar.Close(i+1)), MathAbs(bar.Low(i) - bar.Close(i+1)))); sum += tr; } return sum / period; } //+------------------------------------------------------------------+