refactor: Optimized for incremental calculation

This commit is contained in:
Toh4iem9
2025-12-16 16:27:36 +01:00
parent 764c093795
commit d82cf41ccb
+14 -5
View File
@@ -1,10 +1,9 @@
//+------------------------------------------------------------------+
//| TDI_Pro.mq5|
//| Copyright 2025, xxxxxxxx|
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, xxxxxxxx"
#property version "3.01" // Corrected default input value to remove warning
#property version "3.10" // Optimized for incremental calculation
#property description "Professional Trader's Dynamic Index (TDI) with selectable"
#property description "price source (Standard or Heikin Ashi)."
@@ -115,9 +114,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)
return 0;
@@ -128,7 +136,8 @@ int OnCalculate(const int rates_total, const int, const datetime&[], const doubl
else
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,
BufferPriceLine, BufferSignalLine, BufferBaseLine, BufferUpperBand, BufferLowerBand);
return(rates_total);