refactor: Optimized for incremental calculation

This commit is contained in:
Toh4iem9
2025-12-17 09:07:09 +01:00
parent 6a41e0b3c2
commit 2bb062fcbf
+14 -5
View File
@@ -1,10 +1,9 @@
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
//| TSI_Oscillator_Pro.mq5 | //| TSI_Oscillator_Pro.mq5 |
//| Copyright 2025, xxxxxxxx| //| Copyright 2025, xxxxxxxx|
//| |
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
#property copyright "Copyright 2025, xxxxxxxx" #property copyright "Copyright 2025, xxxxxxxx"
#property version "2.01" // Final unified architecture #property version "2.10" // Optimized for incremental calculation
#property description "TSI Oscillator (Histogram of TSI vs Signal Line) with selectable" #property description "TSI Oscillator (Histogram of TSI vs Signal Line) with selectable"
#property description "price source (Standard and Heikin Ashi)." #property description "price source (Standard and Heikin Ashi)."
@@ -78,9 +77,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)
return 0; return 0;
@@ -91,7 +99,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, BufferOscillator); //--- Delegate calculation with prev_calculated optimization
g_calculator.Calculate(rates_total, prev_calculated, price_type, open, high, low, close, BufferOscillator);
return(rates_total); return(rates_total);
} }