mql4-calc/knitpkg/include/douglasrechia/calc/Calc.mqh

71 lines
3.3 KiB
MQL5
Raw Permalink Normal View History

2026-01-05 17:01:03 -03:00
//+------------------------------------------------------------------+
//| Calc.mqh |
//| |
//| Helix for MetaTrader — Demo |
//| |
//| MIT License |
//| Copyright (c) 2025 Douglas Rechia |
//| |
2026-01-07 16:47:34 -03:00
//| Common technical analysis functions built on knitpkg-mt4-bar. |
2026-01-05 17:01:03 -03:00
//| 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.
2026-01-07 16:47:34 -03:00
// Run `kp-mt autocomplete` to regenerate.
2026-01-05 17:01:03 -03:00
//------------------------------------------------------------------
#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.
//------------------------------------------------------------------
2026-02-03 10:50:36 -03:00
/* @knitpkg:include "douglasrechia/bar/TimeSeries.mqh" */
/* @knitpkg:include "douglasrechia/bar/Bar.mqh" */
2026-01-05 17:01:03 -03:00
//+------------------------------------------------------------------+
//| Simple Moving Average |
//+------------------------------------------------------------------+
double SMA(ITimeSeries<double> &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;
2026-02-15 16:03:46 -03:00
for(int i = shift; i < shift + period; i++)
2026-01-05 17:01:03 -03:00
{
2026-02-15 16:03:46 -03:00
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))));
2026-01-05 17:01:03 -03:00
sum += tr;
}
return sum / period;
}
//+------------------------------------------------------------------+