refactor(indicators): Refactored to use RSI_Engine

This commit is contained in:
Toh4iem9
2026-01-12 15:47:36 +01:00
parent b97da8a5f7
commit 1cb56ffec4
+14 -14
View File
@@ -1,12 +1,12 @@
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
//| VIDYA_RSI_Calculator.mqh | //| VIDYA_RSI_Calculator.mqh |
//| VERSION 2.00: Integrated with RSI Engine. | //| VERSION 3.00: Refactored to use RSI_Engine. |
//| Copyright 2025, xxxxxxxx | //| Copyright 2025, xxxxxxxx |
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
#property copyright "Copyright 2025, xxxxxxxx" #property copyright "Copyright 2025, xxxxxxxx"
#include <MyIncludes\HeikinAshi_Tools.mqh> #include <MyIncludes\HeikinAshi_Tools.mqh>
#include <MyIncludes\RSI_Pro_Calculator.mqh> #include <MyIncludes\RSI_Engine.mqh>
//+==================================================================+ //+==================================================================+
//| CLASS 1: CVIDYARSICalculator (Base Class) | //| CLASS 1: CVIDYARSICalculator (Base Class) |
@@ -17,7 +17,7 @@ protected:
int m_rsi_period, m_ema_period; int m_rsi_period, m_ema_period;
//--- Composition: Use dedicated RSI engine //--- Composition: Use dedicated RSI engine
CRSIProCalculator *m_rsi_calculator; CRSIEngine *m_rsi_engine;
//--- Persistent Buffers //--- Persistent Buffers
double m_price[]; double m_price[];
@@ -45,7 +45,7 @@ public:
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
CVIDYARSICalculator::CVIDYARSICalculator(void) CVIDYARSICalculator::CVIDYARSICalculator(void)
{ {
m_rsi_calculator = NULL; m_rsi_engine = NULL;
} }
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
@@ -53,8 +53,8 @@ CVIDYARSICalculator::CVIDYARSICalculator(void)
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
CVIDYARSICalculator::~CVIDYARSICalculator(void) CVIDYARSICalculator::~CVIDYARSICalculator(void)
{ {
if(CheckPointer(m_rsi_calculator) != POINTER_INVALID) if(CheckPointer(m_rsi_engine) != POINTER_INVALID)
delete m_rsi_calculator; delete m_rsi_engine;
} }
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
@@ -62,7 +62,7 @@ CVIDYARSICalculator::~CVIDYARSICalculator(void)
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
void CVIDYARSICalculator::CreateRSIEngine(void) void CVIDYARSICalculator::CreateRSIEngine(void)
{ {
m_rsi_calculator = new CRSIProCalculator(); m_rsi_engine = new CRSIEngine();
} }
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
@@ -74,8 +74,11 @@ bool CVIDYARSICalculator::Init(int rsi_p, int ema_p)
m_ema_period = (ema_p < 1) ? 1 : ema_p; m_ema_period = (ema_p < 1) ? 1 : ema_p;
CreateRSIEngine(); CreateRSIEngine();
// Init RSI with dummy MA params (1, SMA, 2.0) as we only need the RSI line
if(CheckPointer(m_rsi_calculator) == POINTER_INVALID || !m_rsi_calculator.Init(m_rsi_period, 1, SMA, 2.0)) if(CheckPointer(m_rsi_engine) == POINTER_INVALID)
return false;
if(!m_rsi_engine.Init(m_rsi_period))
return false; return false;
return true; return true;
@@ -109,10 +112,7 @@ void CVIDYARSICalculator::Calculate(int rates_total, int prev_calculated, ENUM_A
// 2. Calculate RSI (Delegated to Engine) // 2. Calculate RSI (Delegated to Engine)
// Note: RSI engine handles its own price preparation internally! // Note: RSI engine handles its own price preparation internally!
// We pass the raw OHLC arrays and price_type. m_rsi_engine.Calculate(rates_total, prev_calculated, price_type, open, high, low, close, m_rsi_buffer);
double dummy1[], dummy2[], dummy3[];
m_rsi_calculator.Calculate(rates_total, prev_calculated, price_type, open, high, low, close,
m_rsi_buffer, dummy1, dummy2, dummy3);
// 3. Calculate VIDYA (Incremental Loop) // 3. Calculate VIDYA (Incremental Loop)
double alpha = 2.0 / (m_ema_period + 1.0); double alpha = 2.0 / (m_ema_period + 1.0);
@@ -196,7 +196,7 @@ protected:
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
void CVIDYARSICalculator_HA::CreateRSIEngine(void) void CVIDYARSICalculator_HA::CreateRSIEngine(void)
{ {
m_rsi_calculator = new CRSIProCalculator_HA(); m_rsi_engine = new CRSIEngine_HA();
} }
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+