From 971cbb44e9c05b13f7aec6f79a771f2531c44ee7 Mon Sep 17 00:00:00 2001 From: Toh4iem9 Date: Tue, 16 Dec 2025 21:37:36 +0100 Subject: [PATCH] refactor: Optimized for incremental calculation --- .../MyIndicators/Authors/Kaufman/KAMA_Pro.mq5 | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/Indicators/MyIndicators/Authors/Kaufman/KAMA_Pro.mq5 b/Indicators/MyIndicators/Authors/Kaufman/KAMA_Pro.mq5 index 5fe9b0e..5b08e5e 100644 --- a/Indicators/MyIndicators/Authors/Kaufman/KAMA_Pro.mq5 +++ b/Indicators/MyIndicators/Authors/Kaufman/KAMA_Pro.mq5 @@ -1,10 +1,9 @@ //+------------------------------------------------------------------+ //| KAMA_Pro.mq5| //| Copyright 2025, xxxxxxxx| -//| | //+------------------------------------------------------------------+ #property copyright "Copyright 2025, xxxxxxxx" -#property version "1.00" +#property version "2.10" // Optimized for incremental calculation #property description "Perry Kaufman's Adaptive Moving Average (KAMA)." #property description "Adapts its speed based on market volatility." @@ -64,12 +63,31 @@ 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, BufferKAMA); + + ENUM_APPLIED_PRICE price_type; + if(InpSourcePrice <= PRICE_HA_CLOSE) + price_type = (ENUM_APPLIED_PRICE)(-(int)InpSourcePrice); + else + price_type = (ENUM_APPLIED_PRICE)InpSourcePrice; + +//--- Delegate calculation with prev_calculated optimization + g_calculator.Calculate(rates_total, prev_calculated, price_type, open, high, low, close, BufferKAMA); + return(rates_total); } //+------------------------------------------------------------------+