refactor: Optimized for incremental calculation

This commit is contained in:
Toh4iem9
2025-12-06 20:44:21 +01:00
parent f99b15aeee
commit cacc13f429
@@ -3,7 +3,7 @@
//| Copyright 2025, xxxxxxxx|
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, xxxxxxxx"
#property version "1.10" // Reverted to Full Recalc for consistency
#property version "1.30" // Optimized for incremental calculation
#property description "John Ehlers' MESA Adaptive Moving Average (MAMA) and FAMA."
#property indicator_chart_window
@@ -80,7 +80,16 @@ void OnDeinit(const int reason)
//+------------------------------------------------------------------+
//| Custom indicator calculation function |
//+------------------------------------------------------------------+
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&[])
int OnCalculate(const int rates_total,
const int prev_calculated, // <--- Now used!
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
if(CheckPointer(g_calculator) == POINTER_INVALID)
return 0;
@@ -91,8 +100,8 @@ int OnCalculate(const int rates_total, const int prev_calculated, const datetime
else
price_type = (ENUM_APPLIED_PRICE)InpSourcePrice;
// Full Recalc (no prev_calculated passed)
g_calculator.Calculate(rates_total, price_type, open, high, low, close, BufferMAMA, BufferFAMA);
//--- Delegate calculation with prev_calculated optimization
g_calculator.Calculate(rates_total, prev_calculated, price_type, open, high, low, close, BufferMAMA, BufferFAMA);
return(rates_total);
}