From b13fe0512d87ad79d11b1aef8d29ec6d2be75a43 Mon Sep 17 00:00:00 2001 From: Toh4iem9 Date: Sat, 20 Dec 2025 11:17:40 +0100 Subject: [PATCH] refactor: Fixed initialization bug --- .../MyIndicators/LinearRegression_Moving_Pro.mq5 | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Indicators/MyIndicators/LinearRegression_Moving_Pro.mq5 b/Indicators/MyIndicators/LinearRegression_Moving_Pro.mq5 index 287b0cf..bc642c9 100644 --- a/Indicators/MyIndicators/LinearRegression_Moving_Pro.mq5 +++ b/Indicators/MyIndicators/LinearRegression_Moving_Pro.mq5 @@ -3,7 +3,7 @@ //| Copyright 2025, xxxxxxxx| //+------------------------------------------------------------------+ #property copyright "Copyright 2025, xxxxxxxx" -#property version "3.00" // True Moving Linear Regression +#property version "3.10" // Fixed initialization bug #property description "Professional Moving Linear Regression (Curve)." #property description "Plots the end-point of the regression line for every bar." @@ -122,6 +122,14 @@ int OnCalculate(const int rates_total, if(CheckPointer(g_calculator) == POINTER_INVALID) return 0; +// CRITICAL FIX: Initialize buffers on full recalculation + if(prev_calculated == 0) + { + ArrayInitialize(BufferUpper, EMPTY_VALUE); + ArrayInitialize(BufferLower, EMPTY_VALUE); + ArrayInitialize(BufferMiddle, EMPTY_VALUE); + } + ENUM_APPLIED_PRICE price_type; if(InpSourcePrice <= PRICE_HA_CLOSE) price_type = (ENUM_APPLIED_PRICE)(-(int)InpSourcePrice); @@ -129,7 +137,6 @@ int OnCalculate(const int rates_total, price_type = (ENUM_APPLIED_PRICE)InpSourcePrice; //--- Delegate calculation with prev_calculated optimization -//--- Using CalculateMoving for the continuous curve g_calculator.CalculateMoving(rates_total, prev_calculated, open, high, low, close, price_type, BufferMiddle, BufferUpper, BufferLower); return(rates_total);