refactor: Optimized for incremental calculation

This commit is contained in:
Toh4iem9
2025-12-08 12:49:19 +01:00
parent 11f0e8f64b
commit ee9ebe0ec6
@@ -1,10 +1,9 @@
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
//| Bollinger_Bands_Fibonacci.mq5 | //| Bollinger_Bands_Fibonacci.mq5 |
//| Copyright 2025, xxxxxxxx| //| Copyright 2025, xxxxxxxx|
//| |
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
#property copyright "Copyright 2025, xxxxxxxx" #property copyright "Copyright 2025, xxxxxxxx"
#property version "1.00" #property version "1.10" // Optimized for incremental calculation
#property description "Bollinger Bands with deviations based on Fibonacci Ratios." #property description "Bollinger Bands with deviations based on Fibonacci Ratios."
#property description "Includes a selectable price source with Heikin Ashi options." #property description "Includes a selectable price source with Heikin Ashi options."
@@ -127,9 +126,18 @@ void OnDeinit(const int reason)
} }
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
//| Custom indicator iteration function. | //| Custom indicator calculation function |
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
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, // <--- 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) if(CheckPointer(g_calculator) != POINTER_INVALID)
{ {
@@ -139,7 +147,8 @@ int OnCalculate(const int rates_total, const int, const datetime&[], const doubl
else else
price_type = (ENUM_APPLIED_PRICE)InpSourcePrice; price_type = (ENUM_APPLIED_PRICE)InpSourcePrice;
g_calculator.Calculate(rates_total, price_type, open, high, low, close, //--- Delegate calculation with prev_calculated optimization
g_calculator.Calculate(rates_total, prev_calculated, price_type, open, high, low, close,
BuffCenter, BuffUpper1, BuffLower1, BuffUpper2, BuffLower2, BuffUpper3, BuffLower3); BuffCenter, BuffUpper1, BuffLower1, BuffUpper2, BuffLower2, BuffUpper3, BuffLower3);
} }
return(rates_total); return(rates_total);