refactor: Added customizable colors

This commit is contained in:
Toh4iem9
2025-11-18 14:11:45 +01:00
parent 8542eb96c8
commit 7261966fcc
@@ -4,20 +4,26 @@
//| | //| |
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
#property copyright "Copyright 2025, xxxxxxxx" #property copyright "Copyright 2025, xxxxxxxx"
#property version "1.00" #property version "1.10" // Added customizable colors
#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
#property indicator_buffers 0 // No buffers are used for plotting #property indicator_buffers 0
#property indicator_plots 0 #property indicator_plots 0
#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 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 = clrCrimson; // Midline Color
input color InpUpperBandColor = clrCrimson; // Upper Band Color
input color InpLowerBandColor = clrCrimson; // Lower Band Color
//--- Global variables --- //--- Global variables ---
CPolynomialRegressionObjectCalculator *g_calculator; CPolynomialRegressionObjectCalculator *g_calculator;
string g_unique_prefix; string g_unique_prefix;
@@ -25,10 +31,7 @@ string g_unique_prefix;
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
int OnInit() int OnInit()
{ {
//--- Create a unique prefix for our objects
g_unique_prefix = StringFormat("PolyRegObj_%d_%d", ChartID(), GetTickCount()); g_unique_prefix = StringFormat("PolyRegObj_%d_%d", ChartID(), GetTickCount());
//--- Clean up any leftover objects from a previous run
ObjectsDeleteAll(0, g_unique_prefix); ObjectsDeleteAll(0, g_unique_prefix);
if(InpSourcePrice <= PRICE_HA_CLOSE) if(InpSourcePrice <= PRICE_HA_CLOSE)
@@ -36,7 +39,9 @@ int OnInit()
else else
g_calculator = new CPolynomialRegressionObjectCalculator(); g_calculator = new CPolynomialRegressionObjectCalculator();
if(CheckPointer(g_calculator) == POINTER_INVALID || !g_calculator.Init(InpPeriod, InpDeviation, g_unique_prefix)) //--- Pass the new color parameters to Init ---
if(CheckPointer(g_calculator) == POINTER_INVALID ||
!g_calculator.Init(InpPeriod, InpDeviation, g_unique_prefix, InpMidlineColor, InpUpperBandColor, InpLowerBandColor))
{ {
Print("Failed to initialize Polynomial Regression Object Calculator."); Print("Failed to initialize Polynomial Regression Object Calculator.");
return(INIT_FAILED); return(INIT_FAILED);
@@ -51,9 +56,7 @@ int OnInit()
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
void OnDeinit(const int reason) void OnDeinit(const int reason)
{ {
//--- Clean up our graphical objects
ObjectsDeleteAll(0, g_unique_prefix); ObjectsDeleteAll(0, g_unique_prefix);
if(CheckPointer(g_calculator) != POINTER_INVALID) if(CheckPointer(g_calculator) != POINTER_INVALID)
delete g_calculator; delete g_calculator;
} }
@@ -64,10 +67,7 @@ int OnCalculate(const int rates_total, const int, const datetime &time[], const
if(CheckPointer(g_calculator) == POINTER_INVALID) if(CheckPointer(g_calculator) == POINTER_INVALID)
return 0; return 0;
ENUM_APPLIED_PRICE price_type = (InpSourcePrice <= PRICE_HA_CLOSE) ? (ENUM_APPLIED_PRICE)(-(int)InpSourcePrice) : (ENUM_APPLIED_PRICE)InpSourcePrice; ENUM_APPLIED_PRICE price_type = (InpSourcePrice <= PRICE_HA_CLOSE) ? (ENUM_APPLIED_PRICE)(-(int)InpSourcePrice) : (ENUM_APPLIED_PRICE)InpSourcePrice;
//--- The calculator now needs the time array for object placement
g_calculator.Calculate(rates_total, time, price_type, open, high, low, close); g_calculator.Calculate(rates_total, time, price_type, open, high, low, close);
return(rates_total); return(rates_total);
} }
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+