mirror of
https://github.com/softwaredevelop/mql5.git
synced 2026-08-18 14:58:10 +00:00
refactor: Corrected object cleanup with stable prefix
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
//| |
|
//| |
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
#property copyright "Copyright 2025, xxxxxxxx"
|
#property copyright "Copyright 2025, xxxxxxxx"
|
||||||
#property version "1.10" // Added customizable colors
|
#property version "1.01" // Corrected object cleanup with stable prefix
|
||||||
#property description "Draws a single, moving Curvilinear Regression Channel using objects."
|
#property description "Draws a single, moving Curvilinear Regression Channel using objects."
|
||||||
|
|
||||||
#property indicator_chart_window
|
#property indicator_chart_window
|
||||||
@@ -14,16 +14,13 @@
|
|||||||
#include <MyIncludes\Polynomial_Regression_Object_Calculator.mqh>
|
#include <MyIncludes\Polynomial_Regression_Object_Calculator.mqh>
|
||||||
|
|
||||||
//--- Input Parameters ---
|
//--- Input Parameters ---
|
||||||
input group "Channel Settings"
|
|
||||||
input int InpPeriod = 50; // Regression Period
|
input int InpPeriod = 50; // Regression Period
|
||||||
input double InpDeviation = 2.0; // Deviation for bands
|
input double InpDeviation = 2.0; // Deviation for bands
|
||||||
|
input color InpMidlineColor = clrDeepSkyBlue; // Midline Color
|
||||||
|
input color InpUpperBandColor = clrDeepSkyBlue; // Upper Band Color
|
||||||
|
input color InpLowerBandColor = clrDeepSkyBlue; // Lower Band Color
|
||||||
input ENUM_APPLIED_PRICE_HA_ALL InpSourcePrice = PRICE_CLOSE_STD;
|
input ENUM_APPLIED_PRICE_HA_ALL InpSourcePrice = PRICE_CLOSE_STD;
|
||||||
|
|
||||||
input group "Color Settings"
|
|
||||||
input color InpMidlineColor = clrDeepSkyBlue; // Midline Color
|
|
||||||
input color InpUpperBandColor = clrDeepSkyBlue; // Upper Band Color
|
|
||||||
input color InpLowerBandColor = clrDeepSkyBlue; // Lower Band Color
|
|
||||||
|
|
||||||
//--- Global variables ---
|
//--- Global variables ---
|
||||||
CPolynomialRegressionObjectCalculator *g_calculator;
|
CPolynomialRegressionObjectCalculator *g_calculator;
|
||||||
string g_unique_prefix;
|
string g_unique_prefix;
|
||||||
@@ -31,7 +28,18 @@ string g_unique_prefix;
|
|||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
int OnInit()
|
int OnInit()
|
||||||
{
|
{
|
||||||
g_unique_prefix = StringFormat("PolyRegObj_%d_%d", ChartID(), GetTickCount());
|
//--- CORRECTED: Create a STABLE and unique prefix for our objects ---
|
||||||
|
long chart_id = ChartID();
|
||||||
|
// Find the subwindow where this indicator instance is running
|
||||||
|
int window_index = ChartWindowFind();
|
||||||
|
if(window_index < 0) // Safety check
|
||||||
|
{
|
||||||
|
Print("Error: Could not find indicator window.");
|
||||||
|
return(INIT_FAILED);
|
||||||
|
}
|
||||||
|
g_unique_prefix = StringFormat("PolyRegObj_%d_%d_", chart_id, window_index);
|
||||||
|
|
||||||
|
//--- This will now correctly find and delete old objects on re-init ---
|
||||||
ObjectsDeleteAll(0, g_unique_prefix);
|
ObjectsDeleteAll(0, g_unique_prefix);
|
||||||
|
|
||||||
if(InpSourcePrice <= PRICE_HA_CLOSE)
|
if(InpSourcePrice <= PRICE_HA_CLOSE)
|
||||||
@@ -39,7 +47,6 @@ int OnInit()
|
|||||||
else
|
else
|
||||||
g_calculator = new CPolynomialRegressionObjectCalculator();
|
g_calculator = new CPolynomialRegressionObjectCalculator();
|
||||||
|
|
||||||
//--- Pass the new color parameters to Init ---
|
|
||||||
if(CheckPointer(g_calculator) == POINTER_INVALID ||
|
if(CheckPointer(g_calculator) == POINTER_INVALID ||
|
||||||
!g_calculator.Init(InpPeriod, InpDeviation, g_unique_prefix, InpMidlineColor, InpUpperBandColor, InpLowerBandColor))
|
!g_calculator.Init(InpPeriod, InpDeviation, g_unique_prefix, InpMidlineColor, InpUpperBandColor, InpLowerBandColor))
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user