From 032a5a25975c34e38001b0023e9c21ad115e7ed4 Mon Sep 17 00:00:00 2001 From: Toh4iem9 Date: Thu, 18 Dec 2025 14:11:16 +0100 Subject: [PATCH] refactor: Dynamic Data Window Labels --- .../MovingAverage_Ribbon_MTF_Pro.mq5 | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/Indicators/MyIndicators/MovingAverage_Ribbon_MTF_Pro.mq5 b/Indicators/MyIndicators/MovingAverage_Ribbon_MTF_Pro.mq5 index 5982c7d..3ab4214 100644 --- a/Indicators/MyIndicators/MovingAverage_Ribbon_MTF_Pro.mq5 +++ b/Indicators/MyIndicators/MovingAverage_Ribbon_MTF_Pro.mq5 @@ -1,10 +1,9 @@ //+------------------------------------------------------------------+ //| MovingAverage_Ribbon_MTF_Pro.mq5 | -//| Copyright 2025, xxxxxxxx| -//| | +//| Copyright 2025, xxxxxxxx | //+------------------------------------------------------------------+ #property copyright "Copyright 2025, xxxxxxxx" -#property version "2.20" // Optimized for incremental calculation & Consolidated Engine +#property version "2.40" // Dynamic Data Window Labels #property description "A 4-line MA Ribbon calculated on a single, user-selected timeframe." #property indicator_chart_window @@ -12,21 +11,25 @@ #property indicator_plots 4 //--- Plot Properties +// Note: Labels defined here are defaults, overridden in OnInit #property indicator_label1 "MA 1" #property indicator_type1 DRAW_LINE #property indicator_color1 clrLightSkyBlue #property indicator_style1 STYLE_SOLID #property indicator_width1 1 + #property indicator_label2 "MA 2" #property indicator_type2 DRAW_LINE #property indicator_color2 clrSkyBlue #property indicator_style2 STYLE_SOLID #property indicator_width2 1 + #property indicator_label3 "MA 3" #property indicator_type3 DRAW_LINE #property indicator_color3 clrDodgerBlue #property indicator_style3 STYLE_SOLID #property indicator_width3 1 + #property indicator_label4 "MA 4" #property indicator_type4 DRAW_LINE #property indicator_color4 clrRoyalBlue @@ -38,8 +41,8 @@ //--- Input Parameters input group "Timeframe & Price Source" -input ENUM_TIMEFRAMES InpUpperTimeframe = PERIOD_H1; -input ENUM_APPLIED_PRICE_HA_ALL InpSourcePrice = PRICE_CLOSE_STD; +input ENUM_TIMEFRAMES InpUpperTimeframe = PERIOD_H1; // Calculation Timeframe +input ENUM_APPLIED_PRICE_HA_ALL InpSourcePrice = PRICE_CLOSE_STD; // Price Source input group "MA 1 Settings" input int InpPeriod1 = 8; @@ -74,7 +77,7 @@ int OnInit() SetIndexBuffer(2, BufferMA3, INDICATOR_DATA); SetIndexBuffer(3, BufferMA4, INDICATOR_DATA); -//--- Set as non-timeseries for standard loop +//--- Set as non-timeseries for standard loop logic ArraySetAsSeries(BufferMA1, false); ArraySetAsSeries(BufferMA2, false); ArraySetAsSeries(BufferMA3, false); @@ -86,7 +89,6 @@ int OnInit() bool is_ha = (InpSourcePrice <= PRICE_HA_CLOSE); //--- Initialize with parameters -//--- Note: We pass the same InpUpperTimeframe to all 4 lines as per this specific indicator design if(CheckPointer(g_calculator) == POINTER_INVALID || !g_calculator.Init(InpUpperTimeframe, InpPeriod1, InpMAType1, InpUpperTimeframe, InpPeriod2, InpMAType2, @@ -98,17 +100,19 @@ int OnInit() return(INIT_FAILED); } -//--- Set Short Name +//--- Set Short Name (Indicator Window Title) ENUM_TIMEFRAMES calc_tf = (InpUpperTimeframe == PERIOD_CURRENT) ? (ENUM_TIMEFRAMES)Period() : InpUpperTimeframe; - IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("MA Ribbon MTF%s(%s)", (is_ha ? " HA" : ""), EnumToString(calc_tf))); + string short_name = StringFormat("MA Ribbon MTF%s(%s)", (is_ha ? " HA" : ""), EnumToString(calc_tf)); + IndicatorSetString(INDICATOR_SHORTNAME, short_name); -//--- Set Labels +//--- Set Dynamic Data Window Labels +//--- This ensures the Data Window shows "EMA(8)", "SMA(20)" etc. instead of "MA 1" PlotIndexSetString(0, PLOT_LABEL, StringFormat("%s(%d)", EnumToString(InpMAType1), InpPeriod1)); PlotIndexSetString(1, PLOT_LABEL, StringFormat("%s(%d)", EnumToString(InpMAType2), InpPeriod2)); PlotIndexSetString(2, PLOT_LABEL, StringFormat("%s(%d)", EnumToString(InpMAType3), InpPeriod3)); PlotIndexSetString(3, PLOT_LABEL, StringFormat("%s(%d)", EnumToString(InpMAType4), InpPeriod4)); -//--- Set Draw Begin +//--- Set Draw Begin (Hide initial unstable bars) int max_period = MathMax(InpPeriod1, MathMax(InpPeriod2, MathMax(InpPeriod3, InpPeriod4))); PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, max_period); PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, max_period); @@ -148,10 +152,12 @@ int OnCalculate(const int rates_total, ENUM_APPLIED_PRICE price_type = (InpSourcePrice <= PRICE_HA_CLOSE) ? (ENUM_APPLIED_PRICE)(-(int)InpSourcePrice) : (ENUM_APPLIED_PRICE)InpSourcePrice; -//--- Delegate calculation with prev_calculated optimization +//--- Delegate calculation to the Engine +//--- The Engine handles MTF logic, Data Fetching, and Calculation internally. g_calculator.Calculate(rates_total, prev_calculated, time, price_type, open, high, low, close, BufferMA1, BufferMA2, BufferMA3, BufferMA4); return(rates_total); } //+------------------------------------------------------------------+ +//+------------------------------------------------------------------+