From ddd850d20a9b8dd935e3f87fa638fbc3e2e44b47 Mon Sep 17 00:00:00 2001 From: Toh4iem9 Date: Sun, 21 Dec 2025 12:09:24 +0100 Subject: [PATCH] refactor: Selectable ER Source --- .../Kaufman/Stochastic_Adaptive_RSI_Pro.mq5 | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/Indicators/MyIndicators/Authors/Kaufman/Stochastic_Adaptive_RSI_Pro.mq5 b/Indicators/MyIndicators/Authors/Kaufman/Stochastic_Adaptive_RSI_Pro.mq5 index 081cda1..6a1f01b 100644 --- a/Indicators/MyIndicators/Authors/Kaufman/Stochastic_Adaptive_RSI_Pro.mq5 +++ b/Indicators/MyIndicators/Authors/Kaufman/Stochastic_Adaptive_RSI_Pro.mq5 @@ -1,13 +1,13 @@ //+------------------------------------------------------------------+ //| Stochastic_Adaptive_RSI_Pro.mq5 | //| Copyright 2025, xxxxxxxx| -//| | //+------------------------------------------------------------------+ #property copyright "Copyright 2025, xxxxxxxx" -#property version "1.00" +#property version "3.00" // Selectable ER Source #property description "Variable-Length Stochastic applied to an RSI series." #property description "Dynamically adjusts its period based on market trendiness (ER)." +//--- Indicator Window and Plot Properties --- #property indicator_separate_window #property indicator_buffers 2 #property indicator_plots 2 @@ -36,11 +36,15 @@ input int InpRSIPeriod = 14; // RSI Period input int InpErPeriod = 10; // Efficiency Ratio Period input int InpMinStochPeriod= 5; // Minimum Stochastic Period on RSI input int InpMaxStochPeriod= 30; // Maximum Stochastic Period on RSI +// NEW: Adaptive Source Selection +input ENUM_ADAPTIVE_SOURCE InpAdaptiveSource= ADAPTIVE_SOURCE_STANDARD; + input group "Stochastic & Price Settings" input int InpSlowingPeriod = 3; +input ENUM_MA_TYPE InpSlowingMAType = SMA; input int InpDPeriod = 3; +input ENUM_MA_TYPE InpDMAType = SMA; input ENUM_APPLIED_PRICE_HA_ALL InpSourcePrice = PRICE_CLOSE_STD; -input ENUM_MA_METHOD InpDMAType = MODE_SMA; //--- Indicator Buffers --- double BufferK[], BufferD[]; @@ -62,7 +66,7 @@ int OnInit() g_calculator = new CStochasticAdaptiveRSICalculator(); if(CheckPointer(g_calculator) == POINTER_INVALID || - !g_calculator.Init(InpRSIPeriod, InpErPeriod, InpMinStochPeriod, InpMaxStochPeriod, InpSlowingPeriod, InpDPeriod, InpDMAType)) + !g_calculator.Init(InpRSIPeriod, InpErPeriod, InpMinStochPeriod, InpMaxStochPeriod, InpSlowingPeriod, InpSlowingMAType, InpDPeriod, InpDMAType, InpAdaptiveSource)) { Print("Failed to create or initialize Adaptive StochRSI Calculator."); return(INIT_FAILED); @@ -81,12 +85,28 @@ int OnInit() void OnDeinit(const int reason) { if(CheckPointer(g_calculator) != POINTER_INVALID) delete g_calculator; } //+------------------------------------------------------------------+ -int OnCalculate(const int rates_total, const int, const datetime&[], const double &open[], const double &high[], const double &low[], const double &close[], const long&[], const long&[], const int&[]) +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[]) { if(CheckPointer(g_calculator) == POINTER_INVALID) return 0; - ENUM_APPLIED_PRICE price_type = (InpSourcePrice <= PRICE_HA_CLOSE) ? (ENUM_APPLIED_PRICE)(-(int)InpSourcePrice) : (ENUM_APPLIED_PRICE)InpSourcePrice; - g_calculator.Calculate(rates_total, open, high, low, close, price_type, BufferK, BufferD); + + ENUM_APPLIED_PRICE price_type; + if(InpSourcePrice <= PRICE_HA_CLOSE) + price_type = (ENUM_APPLIED_PRICE)(-(int)InpSourcePrice); + else + price_type = (ENUM_APPLIED_PRICE)InpSourcePrice; + + g_calculator.Calculate(rates_total, prev_calculated, open, high, low, close, price_type, BufferK, BufferD); + return(rates_total); } //+------------------------------------------------------------------+