refactor(indicators): Optimized for incremental calculation

This commit is contained in:
Toh4iem9
2026-01-03 09:27:29 +01:00
parent e2d9fd1fa0
commit 8af52ff709
@@ -1,10 +1,9 @@
//+------------------------------------------------------------------+
//| Polynomial_Regression_Slope_Pro.mq5 |
//| Copyright 2025, xxxxxxxx|
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, xxxxxxxx"
#property version "1.00"
#property version "2.00" // Optimized for incremental calculation
#property description "Calculates the slope (1st derivative) of a moving Polynomial Regression."
#property description "Functions as a smooth, zero-lag momentum oscillator."
@@ -60,12 +59,14 @@ int OnInit()
void OnDeinit(const int reason) { if(CheckPointer(g_calculator) != POINTER_INVALID) delete g_calculator; }
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total, const int, const datetime&[], const double &open[], const double &high[], const double &low[], const double &close[], const long&[], const long&[], const int&[])
int OnCalculate(const int rates_total, const int prev_calculated, const datetime&[], const double &open[], const double &high[], const double &low[], const double &close[], const long&[], const long&[], const int&[])
{
if(CheckPointer(g_calculator) == POINTER_INVALID)
return 0;
ENUM_APPLIED_PRICE price_type = (InpSourcePrice <= PRICE_HA_CLOSE) ? (ENUM_APPLIED_PRICE)(-(int)InpSourcePrice) : (ENUM_APPLIED_PRICE)InpSourcePrice;
g_calculator.Calculate(rates_total, price_type, open, high, low, close, BufferSlope);
g_calculator.Calculate(rates_total, prev_calculated, price_type, open, high, low, close, BufferSlope);
return(rates_total);
}
//+------------------------------------------------------------------+