refactor: removed non-functional Deviation parameter

This commit is contained in:
Toh4iem9
2025-08-30 11:53:09 +02:00
parent d54458c580
commit d4b9cf3de6
@@ -5,22 +5,20 @@
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
#property copyright "Copyright 2025, xxxxxxxx" #property copyright "Copyright 2025, xxxxxxxx"
#property link "" #property link ""
#property version "2.02" // Added selectable ray extensions #property version "2.02" // Removed non-functional Deviation parameter
#property description "Draws a Linear Regression Channel with optional extensions." #property description "Draws a clean Linear Regression Channel using the built-in object."
#property indicator_chart_window #property indicator_chart_window
#property indicator_buffers 0 #property indicator_buffers 0
#property indicator_plots 0 #property indicator_plots 0
//--- Input Parameters --- //--- Input Parameters ---
input int InpRegressionPeriod = 100; input int InpRegressionPeriod = 100; // The number of bars to calculate the channel on
input double InpDeviations = 2.0; input group "Channel Extensions"
input group "Channel Extensions" input bool InpRayRight = false; // Extend channel to the right
input bool InpRayRight = false; // Extend channel to the right input bool InpRayLeft = false; // Extend channel to the left
input bool InpRayLeft = false; // Extend channel to the left
//--- Global Variables --- //--- Global Variables ---
int g_ExtPeriod; int g_ExtPeriod;
double g_ExtDeviations;
string g_channel_name; string g_channel_name;
datetime g_last_update_time; datetime g_last_update_time;
@@ -30,12 +28,11 @@ datetime g_last_update_time;
int OnInit() int OnInit()
{ {
g_ExtPeriod = (InpRegressionPeriod < 2) ? 2 : InpRegressionPeriod; g_ExtPeriod = (InpRegressionPeriod < 2) ? 2 : InpRegressionPeriod;
g_ExtDeviations = (InpDeviations <= 0) ? 2.0 : InpDeviations;
g_channel_name = "LinRegChannel_" + IntegerToString(ChartID()) + "_" + IntegerToString(GetTickCount()); g_channel_name = "LinRegChannel_" + IntegerToString(ChartID()) + "_" + IntegerToString(GetTickCount());
g_last_update_time = 0; g_last_update_time = 0;
IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("LinReg(%d, %.1f)", g_ExtPeriod, g_ExtDeviations)); IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("LinReg(%d)", g_ExtPeriod));
EventSetTimer(1); EventSetTimer(1);
@@ -74,10 +71,8 @@ int OnCalculate(const int rates_total,
const long &volume[], const long &volume[],
const int &spread[]) const int &spread[])
{ {
if(prev_calculated == 0) if(rates_total < g_ExtPeriod)
{ return(0);
UpdateRegressionChannel();
}
datetime last_bar_time = time[rates_total - 1]; datetime last_bar_time = time[rates_total - 1];
if(last_bar_time > g_last_update_time) if(last_bar_time > g_last_update_time)
@@ -108,13 +103,11 @@ void UpdateRegressionChannel()
return; return;
} }
// Set visual properties only once on creation
ObjectSetInteger(0, g_channel_name, OBJPROP_COLOR, clrRed); ObjectSetInteger(0, g_channel_name, OBJPROP_COLOR, clrRed);
ObjectSetInteger(0, g_channel_name, OBJPROP_STYLE, STYLE_SOLID); ObjectSetInteger(0, g_channel_name, OBJPROP_STYLE, STYLE_SOLID);
ObjectSetDouble(0, g_channel_name, OBJPROP_DEVIATION, g_ExtDeviations);
ObjectSetInteger(0, g_channel_name, OBJPROP_FILL, false); ObjectSetInteger(0, g_channel_name, OBJPROP_FILL, false);
ObjectSetInteger(0, g_channel_name, OBJPROP_SELECTABLE, false); ObjectSetInteger(0, g_channel_name, OBJPROP_SELECTABLE, false);
// --- FIX: Set ray properties on creation based on inputs ---
ObjectSetInteger(0, g_channel_name, OBJPROP_RAY_RIGHT, InpRayRight); ObjectSetInteger(0, g_channel_name, OBJPROP_RAY_RIGHT, InpRayRight);
ObjectSetInteger(0, g_channel_name, OBJPROP_RAY_LEFT, InpRayLeft); ObjectSetInteger(0, g_channel_name, OBJPROP_RAY_LEFT, InpRayLeft);
} }
@@ -122,8 +115,6 @@ void UpdateRegressionChannel()
{ {
ObjectSetInteger(0, g_channel_name, OBJPROP_TIME, 0, time1); ObjectSetInteger(0, g_channel_name, OBJPROP_TIME, 0, time1);
ObjectSetInteger(0, g_channel_name, OBJPROP_TIME, 1, time2); ObjectSetInteger(0, g_channel_name, OBJPROP_TIME, 1, time2);
// --- FIX: Also update ray properties on subsequent updates ---
// This allows the user to change them in the indicator properties window
ObjectSetInteger(0, g_channel_name, OBJPROP_RAY_RIGHT, InpRayRight); ObjectSetInteger(0, g_channel_name, OBJPROP_RAY_RIGHT, InpRayRight);
ObjectSetInteger(0, g_channel_name, OBJPROP_RAY_LEFT, InpRayLeft); ObjectSetInteger(0, g_channel_name, OBJPROP_RAY_LEFT, InpRayLeft);
} }