refactor: harmonized input parameter names

This commit is contained in:
Toh4iem9
2025-08-28 14:29:34 +02:00
parent b0a73d0873
commit af095f1502
+16 -17
View File
@@ -5,7 +5,7 @@
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
#property copyright "Copyright 2025, xxxxxxxx" #property copyright "Copyright 2025, xxxxxxxx"
#property link "" #property link ""
#property version "2.00" // Refactored for stability and clarity #property version "2.01" // Harmonized input parameter names
#property description "Slow Stochastic Oscillator" #property description "Slow Stochastic Oscillator"
//--- Indicator Window and Level Properties --- //--- Indicator Window and Level Properties ---
@@ -32,9 +32,9 @@
#property indicator_width2 1 #property indicator_width2 1
//--- Input Parameters --- //--- Input Parameters ---
input int InpKPeriod = 5; // %K Period input int InpKPeriod = 5; // %K Period
input int InpDPeriod = 3; // %D Period (signal line smoothing) input int InpSlowingPeriod = 3; // Slowing Period
input int InpSlowing = 3; // Slowing (initial %K smoothing) input int InpDPeriod = 3; // %D Period (signal line smoothing)
//--- Indicator Buffers --- //--- Indicator Buffers ---
double BufferK[]; // Plotted buffer for the main (Slow) %K line double BufferK[]; // Plotted buffer for the main (Slow) %K line
@@ -42,7 +42,7 @@ double BufferD[]; // Plotted buffer for the signal %D line
double BufferRawK[]; // Calculation buffer for raw %K before slowing double BufferRawK[]; // Calculation buffer for raw %K before slowing
//--- Global Variables --- //--- Global Variables ---
int g_ExtKPeriod, g_ExtDPeriod, g_ExtSlowing; int g_ExtKPeriod, g_ExtDPeriod, g_ExtSlowingPeriod;
//--- Forward declarations for helper functions --- //--- Forward declarations for helper functions ---
double Highest(const double &array[], int period, int current_pos); double Highest(const double &array[], int period, int current_pos);
@@ -54,9 +54,9 @@ double Lowest(const double &array[], int period, int current_pos);
int OnInit() int OnInit()
{ {
//--- Validate and store input periods //--- Validate and store input periods
g_ExtKPeriod = (InpKPeriod < 1) ? 1 : InpKPeriod; g_ExtKPeriod = (InpKPeriod < 1) ? 1 : InpKPeriod;
g_ExtDPeriod = (InpDPeriod < 1) ? 1 : InpDPeriod; g_ExtDPeriod = (InpDPeriod < 1) ? 1 : InpDPeriod;
g_ExtSlowing = (InpSlowing < 1) ? 1 : InpSlowing; g_ExtSlowingPeriod = (InpSlowingPeriod < 1) ? 1 : InpSlowingPeriod;
//--- Map the buffers and set as non-timeseries //--- Map the buffers and set as non-timeseries
SetIndexBuffer(0, BufferK, INDICATOR_DATA); SetIndexBuffer(0, BufferK, INDICATOR_DATA);
@@ -69,9 +69,9 @@ int OnInit()
//--- Set indicator display properties //--- Set indicator display properties
IndicatorSetInteger(INDICATOR_DIGITS, 2); IndicatorSetInteger(INDICATOR_DIGITS, 2);
PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, g_ExtKPeriod + g_ExtSlowing - 2); PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, g_ExtKPeriod + g_ExtSlowingPeriod - 2);
PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, g_ExtKPeriod + g_ExtSlowing + g_ExtDPeriod - 3); PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, g_ExtKPeriod + g_ExtSlowingPeriod + g_ExtDPeriod - 3);
IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("Slow Stoch(%d,%d,%d)", g_ExtKPeriod, g_ExtDPeriod, g_ExtSlowing)); IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("Slow Stoch(%d,%d,%d)", g_ExtKPeriod, g_ExtSlowingPeriod, g_ExtDPeriod));
return(INIT_SUCCEEDED); return(INIT_SUCCEEDED);
} }
@@ -91,7 +91,7 @@ int OnCalculate(const int rates_total,
const int &spread[]) const int &spread[])
{ {
//--- Check if there is enough historical data //--- Check if there is enough historical data
int start_pos = g_ExtKPeriod + g_ExtSlowing + g_ExtDPeriod - 2; int start_pos = g_ExtKPeriod + g_ExtSlowingPeriod + g_ExtDPeriod - 2;
if(rates_total <= start_pos) if(rates_total <= start_pos)
return(0); return(0);
@@ -100,7 +100,6 @@ int OnCalculate(const int rates_total,
{ {
double highest_high = Highest(high, g_ExtKPeriod, i); double highest_high = Highest(high, g_ExtKPeriod, i);
double lowest_low = Lowest(low, g_ExtKPeriod, i); double lowest_low = Lowest(low, g_ExtKPeriod, i);
double range = highest_high - lowest_low; double range = highest_high - lowest_low;
if(range > 0) if(range > 0)
BufferRawK[i] = (close[i] - lowest_low) / range * 100.0; BufferRawK[i] = (close[i] - lowest_low) / range * 100.0;
@@ -109,19 +108,19 @@ int OnCalculate(const int rates_total,
} }
//--- STEP 2: Calculate Slow %K (Main Line) by smoothing Raw %K //--- STEP 2: Calculate Slow %K (Main Line) by smoothing Raw %K
int k_slow_start_pos = g_ExtKPeriod + g_ExtSlowing - 2; int k_slow_start_pos = g_ExtKPeriod + g_ExtSlowingPeriod - 2;
for(int i = k_slow_start_pos; i < rates_total; i++) for(int i = k_slow_start_pos; i < rates_total; i++)
{ {
double sum = 0; double sum = 0;
for(int j = 0; j < g_ExtSlowing; j++) for(int j = 0; j < g_ExtSlowingPeriod; j++)
{ {
sum += BufferRawK[i-j]; sum += BufferRawK[i-j];
} }
BufferK[i] = sum / g_ExtSlowing; BufferK[i] = sum / g_ExtSlowingPeriod;
} }
//--- STEP 3: Calculate %D (Signal Line) by smoothing Slow %K //--- STEP 3: Calculate %D (Signal Line) by smoothing Slow %K
int d_start_pos = g_ExtKPeriod + g_ExtSlowing + g_ExtDPeriod - 3; int d_start_pos = g_ExtKPeriod + g_ExtSlowingPeriod + g_ExtDPeriod - 3;
for(int i = d_start_pos; i < rates_total; i++) for(int i = d_start_pos; i < rates_total; i++)
{ {
double sum = 0; double sum = 0;