From 449ab7536bfa012f6a7ea22932da7de1272db568 Mon Sep 17 00:00:00 2001 From: Toh4iem9 Date: Mon, 20 Oct 2025 14:58:56 +0200 Subject: [PATCH] refactor: Heikin Ashi logic --- .../MyIndicators/Session_Analysis_Pro.mq5 | 61 ++++++++----------- 1 file changed, 26 insertions(+), 35 deletions(-) diff --git a/Indicators/MyIndicators/Session_Analysis_Pro.mq5 b/Indicators/MyIndicators/Session_Analysis_Pro.mq5 index 6e36e82..4d74cae 100644 --- a/Indicators/MyIndicators/Session_Analysis_Pro.mq5 +++ b/Indicators/MyIndicators/Session_Analysis_Pro.mq5 @@ -3,7 +3,7 @@ //| Copyright 2025, xxxxxxxx| //+------------------------------------------------------------------+ #property copyright "Copyright 2025, xxxxxxxx" -#property version "6.10" // REFACTORED: Improved object and buffer cleanup on re-init +#property version "6.30" // FIXED: Unified Heikin Ashi logic for all components #property description "Draws boxes, analytics, and session-based VWAP via high-performance buffers." #property indicator_chart_window // Buffers: M1(Pre A/B, Core A/B, Post A/B, Full A/B) = 8. Total for 3 markets = 24 @@ -77,7 +77,7 @@ enum ENUM_CANDLE_SOURCE input group "Global Settings" input bool InpFillBoxes = false; input ENUM_APPLIED_VOLUME InpVolumeType = VOLUME_TICK; -input ENUM_CANDLE_SOURCE InpCandleSource = CANDLE_STANDARD; // For VWAP +input ENUM_CANDLE_SOURCE InpCandleSource = CANDLE_STANDARD; // For VWAP and other analytics input ENUM_APPLIED_PRICE InpSourcePrice = PRICE_TYPICAL; // For Mean/LinReg //--- Market 1 Settings --- @@ -267,7 +267,7 @@ int OnInit() PlotIndexSetInteger(22, PLOT_LINE_COLOR, InpM3_FullDay_Color); PlotIndexSetInteger(23, PLOT_LINE_COLOR, InpM3_FullDay_Color); -// --- CORRECTED: Centralized Cleanup Logic --- +// --- Centralized Cleanup Logic --- MathSrand((int)TimeCurrent() + (int)ChartID()); string temp_short_name = StringFormat("SessPro_TempID_%d_%d", TimeCurrent(), MathRand()); IndicatorSetString(INDICATOR_SHORTNAME, temp_short_name); @@ -278,60 +278,51 @@ int OnInit() string unique_prefix = StringFormat("SessPro_%d_%d_", ChartID(), window_index); ObjectsDeleteAll(0, unique_prefix); +// --- Unified Initialization for both calculator types --- + bool is_ha_mode = (InpCandleSource == CANDLE_HEIKIN_ASHI); + for(int i=0; i 0 && time[rates_total - 1] == g_last_bar_time && Bars(_Symbol, _Period) == rates_total) + return(rates_total); + if(rates_total > 0) + g_last_bar_time = time[rates_total - 1]; + +// --- Explicitly clear all VWAP buffers at the start of each new bar calculation --- ArrayInitialize(BufferM1_Pre_A, EMPTY_VALUE); ArrayInitialize(BufferM1_Pre_B, EMPTY_VALUE); ArrayInitialize(BufferM1_Core_A, EMPTY_VALUE); @@ -381,11 +377,6 @@ int OnCalculate(const int rates_total, const int, const datetime& time[], const ArrayInitialize(BufferM3_Full_A, EMPTY_VALUE); ArrayInitialize(BufferM3_Full_B, EMPTY_VALUE); - if(rates_total > 0 && time[rates_total - 1] == g_last_bar_time && Bars(_Symbol, _Period) == rates_total) - return(rates_total); - if(rates_total > 0) - g_last_bar_time = time[rates_total - 1]; - // --- Object Drawing Logic (Boxes, etc.) --- for(int i=0; i