refactor: Upgraded with 3-digit Gamma precision and strict chronological state safety

This commit is contained in:
Toh4iem9
2026-06-30 14:47:54 +02:00
parent 1c3cef4bb6
commit 19e71bfdc4
@@ -3,7 +3,7 @@
//| Copyright 2026, xxxxxxxx|
//+------------------------------------------------------------------+
#property copyright "Copyright 2026, xxxxxxxx"
#property version "1.00" // Dynamic Multi-Timeframe Laguerre Channel with flat-force step-alignment
#property version "1.10" // Upgraded with 3-digit Gamma precision and strict chronological state safety
#property description "Multi-Timeframe (MTF) John Ehlers' Laguerre Channel (Keltner Concept)."
#property description "Displays HTF Laguerre baseline and ATR bands cleanly on current chart without live-bar warping."
@@ -11,14 +11,14 @@
#property indicator_buffers 3
#property indicator_plots 3
//--- Plot 1: Upper Band
//--- Plot 1: Upper Band MTF
#property indicator_label1 "Upper Band MTF"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrMediumPurple
#property indicator_style1 STYLE_DOT
#property indicator_width1 1
//--- Plot 2: Lower Band
//--- Plot 2: Lower Band MTF
#property indicator_label2 "Lower Band MTF"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrMediumPurple
@@ -40,7 +40,7 @@ input group "Timeframe Settings"
input ENUM_TIMEFRAMES InpUpperTimeframe = PERIOD_H1; // Target Higher Timeframe
input group "Laguerre Settings"
input double InpGamma = 0.7; // Gamma (0.0 - 1.0)
input double InpGamma = 0.7; // Gamma (0.0 - 1.0, e.g. 0.236, 0.382)
input ENUM_APPLIED_PRICE_HA_ALL InpSourcePrice = PRICE_CLOSE_STD; // Price Source
//+------------------------------------------------------------------+
@@ -135,10 +135,10 @@ int OnInit()
return(INIT_FAILED);
}
//--- 4. Set Shortname
//--- 4. Set Shortname - Updated format string to %.3f to support exact Fibonacci decimals
string type = (InpSourcePrice <= PRICE_HA_CLOSE) ? " HA" : "";
string tf_str = g_is_mtf_mode ? (" " + EnumToString(g_calc_timeframe)) : "";
IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("Laguerre Ch%s%s(%.2f, ATR %d)", type, tf_str, InpGamma, InpAtrPeriod));
IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("Laguerre Ch%s%s(%.3f, ATR %d)", type, tf_str, InpGamma, InpAtrPeriod));
// Draw begin logic
int draw_begin = InpAtrPeriod;
@@ -184,6 +184,16 @@ int OnCalculate(const int rates_total,
if(rates_total < 2)
return(0);
if(CheckPointer(g_calculator) == POINTER_INVALID)
return(0);
//--- Force strict chronological indexing for state-safety on input price arrays
ArraySetAsSeries(time, false);
ArraySetAsSeries(open, false);
ArraySetAsSeries(high, false);
ArraySetAsSeries(low, false);
ArraySetAsSeries(close, false);
ENUM_APPLIED_PRICE price_type = (InpSourcePrice <= PRICE_HA_CLOSE) ?
(ENUM_APPLIED_PRICE)(-(int)InpSourcePrice) :
(ENUM_APPLIED_PRICE)InpSourcePrice;
@@ -239,6 +249,13 @@ int OnCalculate(const int rates_total,
ArrayResize(h_res_up, g_htf_count);
ArrayResize(h_res_lo, g_htf_count);
// Force chronological array alignment on HTF caches after resize
ArraySetAsSeries(h_time, false);
ArraySetAsSeries(h_open, false);
ArraySetAsSeries(h_high, false);
ArraySetAsSeries(h_low, false);
ArraySetAsSeries(h_close, false);
if(CopyTime(_Symbol, g_calc_timeframe, 0, g_htf_count, h_time) != g_htf_count ||
CopyOpen(_Symbol, g_calc_timeframe, 0, g_htf_count, h_open) != g_htf_count ||
CopyHigh(_Symbol, g_calc_timeframe, 0, g_htf_count, h_high) != g_htf_count ||
@@ -348,4 +365,3 @@ void OnTimer()
}
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+