diff --git a/Indicators/MyIndicators/LinearRegressionChannel.mq5 b/Indicators/MyIndicators/LinearRegressionChannel.mq5 index e716350..a228ce3 100644 --- a/Indicators/MyIndicators/LinearRegressionChannel.mq5 +++ b/Indicators/MyIndicators/LinearRegressionChannel.mq5 @@ -5,22 +5,20 @@ //+------------------------------------------------------------------+ #property copyright "Copyright 2025, xxxxxxxx" #property link "" -#property version "2.02" // Added selectable ray extensions -#property description "Draws a Linear Regression Channel with optional extensions." +#property version "2.02" // Removed non-functional Deviation parameter +#property description "Draws a clean Linear Regression Channel using the built-in object." #property indicator_chart_window #property indicator_buffers 0 #property indicator_plots 0 //--- Input Parameters --- -input int InpRegressionPeriod = 100; -input double InpDeviations = 2.0; -input group "Channel Extensions" -input bool InpRayRight = false; // Extend channel to the right -input bool InpRayLeft = false; // Extend channel to the left +input int InpRegressionPeriod = 100; // The number of bars to calculate the channel on +input group "Channel Extensions" +input bool InpRayRight = false; // Extend channel to the right +input bool InpRayLeft = false; // Extend channel to the left //--- Global Variables --- int g_ExtPeriod; -double g_ExtDeviations; string g_channel_name; datetime g_last_update_time; @@ -30,12 +28,11 @@ datetime g_last_update_time; int OnInit() { g_ExtPeriod = (InpRegressionPeriod < 2) ? 2 : InpRegressionPeriod; - g_ExtDeviations = (InpDeviations <= 0) ? 2.0 : InpDeviations; g_channel_name = "LinRegChannel_" + IntegerToString(ChartID()) + "_" + IntegerToString(GetTickCount()); 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); @@ -74,10 +71,8 @@ int OnCalculate(const int rates_total, const long &volume[], const int &spread[]) { - if(prev_calculated == 0) - { - UpdateRegressionChannel(); - } + if(rates_total < g_ExtPeriod) + return(0); datetime last_bar_time = time[rates_total - 1]; if(last_bar_time > g_last_update_time) @@ -108,13 +103,11 @@ void UpdateRegressionChannel() return; } + // Set visual properties only once on creation ObjectSetInteger(0, g_channel_name, OBJPROP_COLOR, clrRed); 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_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_LEFT, InpRayLeft); } @@ -122,8 +115,6 @@ void UpdateRegressionChannel() { ObjectSetInteger(0, g_channel_name, OBJPROP_TIME, 0, time1); 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_LEFT, InpRayLeft); }