refactor: Optimized for incremental calculation

This commit is contained in:
Toh4iem9
2025-12-16 13:02:38 +01:00
parent e88a209570
commit e920fbf8d5
+5 -10
View File
@@ -1,11 +1,9 @@
//+------------------------------------------------------------------+
//| HMA_Pro.mq5|
//| Copyright 2025, xxxxxxxx|
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, xxxxxxxx"
#property link ""
#property version "4.00"
#property version "4.10" // Optimized for incremental calculation
#property description "Professional Hull Moving Average (HMA) with selectable"
#property description "price source (Standard and Heikin Ashi)."
@@ -81,10 +79,10 @@ void OnDeinit(const int reason)
}
//+------------------------------------------------------------------+
//| Custom indicator calculation function. |
//| Custom indicator calculation function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const int prev_calculated, // <--- Now used!
const datetime &time[],
const double &open[],
const double &high[],
@@ -94,21 +92,18 @@ int OnCalculate(const int rates_total,
const long &volume[],
const int &spread[])
{
//--- Ensure the calculator object is valid
if(CheckPointer(g_calculator) == POINTER_INVALID)
return 0;
//--- Convert our custom enum to the standard ENUM_APPLIED_PRICE
ENUM_APPLIED_PRICE price_type;
if(InpSourcePrice <= PRICE_HA_CLOSE)
price_type = (ENUM_APPLIED_PRICE)(-(int)InpSourcePrice);
else
price_type = (ENUM_APPLIED_PRICE)InpSourcePrice;
//--- Delegate the entire calculation to our calculator object
g_calculator.Calculate(rates_total, open, high, low, close, price_type, BufferHMA);
//--- Delegate calculation with prev_calculated optimization
g_calculator.Calculate(rates_total, prev_calculated, price_type, open, high, low, close, BufferHMA);
//--- Return rates_total for a full recalculation, ensuring stability
return(rates_total);
}
//+------------------------------------------------------------------+