From 962549b377bd401b2df0fb3d0f22c8813c72464e Mon Sep 17 00:00:00 2001 From: Toh4iem9 Date: Sun, 30 Nov 2025 10:38:51 +0100 Subject: [PATCH] refactor: Optimized for incremental calculation --- .../Laguerre_RSI_Adaptive_Pro.mq5 | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/Indicators/MyIndicators/Authors/Ehlers/2_Oscillators/Laguerre_RSI_Adaptive_Pro.mq5 b/Indicators/MyIndicators/Authors/Ehlers/2_Oscillators/Laguerre_RSI_Adaptive_Pro.mq5 index 10afc47..a31c709 100644 --- a/Indicators/MyIndicators/Authors/Ehlers/2_Oscillators/Laguerre_RSI_Adaptive_Pro.mq5 +++ b/Indicators/MyIndicators/Authors/Ehlers/2_Oscillators/Laguerre_RSI_Adaptive_Pro.mq5 @@ -1,10 +1,9 @@ //+------------------------------------------------------------------+ //| Laguerre_RSI_Adaptive_Pro.mq5 | //| Copyright 2025, xxxxxxxx| -//| | //+------------------------------------------------------------------+ #property copyright "Copyright 2025, xxxxxxxx" -#property version "1.10" // Added signal line and fixed state management +#property version "1.20" // Optimized for incremental calculation #property description "John Ehlers' Adaptive Laguerre RSI with an optional signal line." #property indicator_separate_window @@ -81,16 +80,32 @@ int OnInit() void OnDeinit(const int reason) { if(CheckPointer(g_calculator) != POINTER_INVALID) delete g_calculator; } //+------------------------------------------------------------------+ -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&[]) +//| Custom indicator calculation function | +//+------------------------------------------------------------------+ +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; - ENUM_APPLIED_PRICE price_type = (InpSourcePrice <= PRICE_HA_CLOSE) ? (ENUM_APPLIED_PRICE)(-(int)InpSourcePrice) : (ENUM_APPLIED_PRICE)InpSourcePrice; - g_calculator.Calculate(rates_total, price_type, open, high, low, close, BufferLRSI, BufferSignal); + ENUM_APPLIED_PRICE price_type = (InpSourcePrice <= PRICE_HA_CLOSE) ? (ENUM_APPLIED_PRICE)(-(int)InpSourcePrice) : (ENUM_APPLIED_PRICE)InpSourcePrice; + +//--- Delegate calculation with prev_calculated optimization + g_calculator.Calculate(rates_total, prev_calculated, price_type, open, high, low, close, BufferLRSI, BufferSignal); + +//--- Hide Signal if needed (Optimized loop) if(InpDisplayMode == DISPLAY_LRSI_ONLY) { - for(int i=0; i 0) ? prev_calculated - 1 : 0; + for(int i = start_index; i < rates_total; i++) BufferSignal[i] = EMPTY_VALUE; }