refactor: Fixed initialization bug (Vertical Lines)

This commit is contained in:
Toh4iem9
2025-12-20 11:16:36 +01:00
parent 5445fbf7fb
commit 1266f28266
@@ -3,7 +3,7 @@
//| Copyright 2025, xxxxxxxx|
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, xxxxxxxx"
#property version "1.00"
#property version "1.10" // Fixed initialization bug (Vertical Lines)
#property description "Professional Linear Regression Channel (Straight Segment)"
#property description "Draws the regression channel for the most recent N bars."
@@ -104,6 +104,15 @@ int OnCalculate(const int rates_total,
if(CheckPointer(g_calculator) == POINTER_INVALID)
return 0;
// CRITICAL FIX: Initialize buffers on full recalculation (e.g. timeframe switch)
// This prevents "ghost" 0.0 values which cause vertical lines.
if(prev_calculated == 0)
{
ArrayInitialize(BufferUpper, EMPTY_VALUE);
ArrayInitialize(BufferLower, EMPTY_VALUE);
ArrayInitialize(BufferMiddle, EMPTY_VALUE);
}
ENUM_APPLIED_PRICE price_type = (InpSourcePrice <= PRICE_HA_CLOSE) ? (ENUM_APPLIED_PRICE)(-(int)InpSourcePrice) : (ENUM_APPLIED_PRICE)InpSourcePrice;
// Clear the buffer index just before the channel starts to create the visual "cut"