From 3edd83847355fcf1ba3a9975ba9fa8e23e11c598 Mon Sep 17 00:00:00 2001 From: Toh4iem9 Date: Tue, 2 Dec 2025 23:03:41 +0100 Subject: [PATCH] refactor: Optimized for incremental calculation --- .../Polynomial_Regression_Object_Pro.mq5 | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Indicators/MyIndicators/Authors/Kaufman/Polynomial_Regression_Object_Pro.mq5 b/Indicators/MyIndicators/Authors/Kaufman/Polynomial_Regression_Object_Pro.mq5 index cd8b5e1..343c532 100644 --- a/Indicators/MyIndicators/Authors/Kaufman/Polynomial_Regression_Object_Pro.mq5 +++ b/Indicators/MyIndicators/Authors/Kaufman/Polynomial_Regression_Object_Pro.mq5 @@ -1,10 +1,9 @@ //+------------------------------------------------------------------+ //| Polynomial_Regression_Object_Pro.mq5 | //| Copyright 2025, xxxxxxxx| -//| | //+------------------------------------------------------------------+ #property copyright "Copyright 2025, xxxxxxxx" -#property version "1.01" // Corrected object cleanup with stable prefix +#property version "1.10" // Optimized for incremental calculation #property description "Draws a single, moving Curvilinear Regression Channel using objects." #property indicator_chart_window @@ -69,12 +68,22 @@ void OnDeinit(const int reason) } //+------------------------------------------------------------------+ -int OnCalculate(const int rates_total, const int, const datetime &time[], 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, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long&[], const long&[], const int&[]) { 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; + + ENUM_APPLIED_PRICE price_type; + if(InpSourcePrice <= PRICE_HA_CLOSE) + price_type = (ENUM_APPLIED_PRICE)(-(int)InpSourcePrice); + else + price_type = (ENUM_APPLIED_PRICE)InpSourcePrice; + +//--- Full Recalculation (No prev_calculated passed) g_calculator.Calculate(rates_total, time, price_type, open, high, low, close); + return(rates_total); } //+------------------------------------------------------------------+