2025-10-18 17:48:38 +02:00
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//| Laguerre_RSI_Calculator.mqh |
|
2026-06-25 10:27:02 +02:00
|
|
|
//| VERSION 1.30: Added volume-weighted Calculate overload. |
|
|
|
|
|
//| Copyright 2026, xxxxxxxx |
|
2025-10-18 17:48:38 +02:00
|
|
|
//+------------------------------------------------------------------+
|
2026-06-25 10:27:02 +02:00
|
|
|
#property copyright "Copyright 2026, xxxxxxxx"
|
|
|
|
|
#property version "1.30" // Refactored to support volume arrays for VWMA signal lines
|
|
|
|
|
|
|
|
|
|
#ifndef LAGUERRE_RSI_CALCULATOR_MQH
|
|
|
|
|
#define LAGUERRE_RSI_CALCULATOR_MQH
|
2025-10-18 17:48:38 +02:00
|
|
|
|
2025-11-11 08:40:52 +01:00
|
|
|
#include <MyIncludes\Laguerre_Engine.mqh>
|
2025-11-28 19:42:44 +01:00
|
|
|
#include <MyIncludes\MovingAverage_Engine.mqh>
|
2025-10-18 17:48:38 +02:00
|
|
|
|
2026-06-25 10:27:02 +02:00
|
|
|
//+==================================================================+
|
|
|
|
|
//| CLASS: CLaguerreRSICalculator |
|
2025-10-18 17:48:38 +02:00
|
|
|
//+==================================================================+
|
|
|
|
|
class CLaguerreRSICalculator
|
|
|
|
|
{
|
|
|
|
|
protected:
|
2025-10-19 10:19:57 +02:00
|
|
|
CLaguerreEngine *m_engine;
|
2025-11-23 00:16:41 +01:00
|
|
|
int m_signal_period;
|
|
|
|
|
ENUM_MA_TYPE m_signal_ma_type;
|
|
|
|
|
|
2025-11-28 19:42:44 +01:00
|
|
|
//--- Internal MA Calculator for Signal Line (Optimization)
|
|
|
|
|
CMovingAverageCalculator *m_ma_calculator;
|
2025-10-18 17:48:38 +02:00
|
|
|
|
|
|
|
|
public:
|
2025-11-28 19:42:44 +01:00
|
|
|
CLaguerreRSICalculator(void);
|
|
|
|
|
virtual ~CLaguerreRSICalculator(void);
|
2025-10-18 17:48:38 +02:00
|
|
|
|
2025-11-23 00:16:41 +01:00
|
|
|
bool Init(double gamma, int signal_p, ENUM_MA_TYPE signal_ma);
|
2025-11-28 19:42:44 +01:00
|
|
|
|
2026-06-25 10:27:02 +02:00
|
|
|
//--- Standard Calculate (Without volume data)
|
|
|
|
|
void Calculate(int rates_total, int prev_calculated, ENUM_APPLIED_PRICE price_type, const double &open[], const double &high[], const double &low[], const double &close[],
|
|
|
|
|
double &lrsi_buffer[], double &signal_buffer[]);
|
|
|
|
|
|
|
|
|
|
//--- NEW: Overloaded Calculate with Volume (Specifically for VWMA support)
|
2025-11-28 19:42:44 +01:00
|
|
|
void Calculate(int rates_total, int prev_calculated, ENUM_APPLIED_PRICE price_type, const double &open[], const double &high[], const double &low[], const double &close[],
|
2026-06-25 10:27:02 +02:00
|
|
|
const long &volume[],
|
2025-11-23 00:16:41 +01:00
|
|
|
double &lrsi_buffer[], double &signal_buffer[]);
|
2025-10-18 17:48:38 +02:00
|
|
|
};
|
|
|
|
|
|
2025-11-28 19:42:44 +01:00
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//| Constructor |
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
CLaguerreRSICalculator::CLaguerreRSICalculator(void)
|
|
|
|
|
{
|
|
|
|
|
m_engine = new CLaguerreEngine();
|
|
|
|
|
m_ma_calculator = new CMovingAverageCalculator();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//| Destructor |
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
CLaguerreRSICalculator::~CLaguerreRSICalculator(void)
|
|
|
|
|
{
|
|
|
|
|
if(CheckPointer(m_engine) != POINTER_INVALID)
|
|
|
|
|
delete m_engine;
|
|
|
|
|
if(CheckPointer(m_ma_calculator) != POINTER_INVALID)
|
|
|
|
|
delete m_ma_calculator;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//| Init |
|
2025-11-23 00:16:41 +01:00
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
bool CLaguerreRSICalculator::Init(double gamma, int signal_p, ENUM_MA_TYPE signal_ma)
|
|
|
|
|
{
|
|
|
|
|
m_signal_period = (signal_p < 1) ? 1 : signal_p;
|
|
|
|
|
m_signal_ma_type = signal_ma;
|
2025-11-28 19:42:44 +01:00
|
|
|
|
|
|
|
|
if(!m_engine.Init(gamma, SOURCE_PRICE))
|
|
|
|
|
return false;
|
|
|
|
|
if(!m_ma_calculator.Init(m_signal_period, m_signal_ma_type))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
2025-11-23 00:16:41 +01:00
|
|
|
}
|
2025-10-18 17:48:38 +02:00
|
|
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
2026-06-25 10:27:02 +02:00
|
|
|
//| Calculate (Standard - No Volume) |
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
void CLaguerreRSICalculator::Calculate(int rates_total, int prev_calculated, ENUM_APPLIED_PRICE price_type, const double &open[], const double &high[], const double &low[], const double &close[],
|
|
|
|
|
double &lrsi_buffer[], double &signal_buffer[])
|
|
|
|
|
{
|
|
|
|
|
if(rates_total < 2)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
//--- 1. Calculate Laguerre Components (Incremental)
|
|
|
|
|
double dummy_filt[];
|
|
|
|
|
m_engine.CalculateFilter(rates_total, prev_calculated, price_type, open, high, low, close, dummy_filt);
|
|
|
|
|
|
|
|
|
|
//--- 2. Retrieve L0..L3 buffers
|
|
|
|
|
double L0[], L1[], L2[], L3[];
|
|
|
|
|
m_engine.GetLBuffers(L0, L1, L2, L3);
|
|
|
|
|
|
|
|
|
|
//--- 3. Calculate LRSI (Incremental Loop)
|
|
|
|
|
int start_index = (prev_calculated > 0) ? prev_calculated - 1 : 1;
|
|
|
|
|
if(start_index < 1)
|
|
|
|
|
start_index = 1;
|
|
|
|
|
|
|
|
|
|
for(int i = start_index; i < rates_total; i++)
|
|
|
|
|
{
|
|
|
|
|
double cu = 0.0, cd = 0.0;
|
|
|
|
|
|
|
|
|
|
if(L0[i] >= L1[i])
|
|
|
|
|
cu = L0[i] - L1[i];
|
|
|
|
|
else
|
|
|
|
|
cd = L1[i] - L0[i];
|
|
|
|
|
|
|
|
|
|
if(L1[i] >= L2[i])
|
|
|
|
|
cu += L1[i] - L2[i];
|
|
|
|
|
else
|
|
|
|
|
cd += L2[i] - L1[i];
|
|
|
|
|
|
|
|
|
|
if(L2[i] >= L3[i])
|
|
|
|
|
cu += L2[i] - L3[i];
|
|
|
|
|
else
|
|
|
|
|
cd += L3[i] - L2[i];
|
|
|
|
|
|
|
|
|
|
double lrsi_value;
|
|
|
|
|
if(cu + cd > 0.0)
|
|
|
|
|
lrsi_value = 100.0 * cu / (cu + cd);
|
|
|
|
|
else
|
|
|
|
|
lrsi_value = (i > 0) ? lrsi_buffer[i-1] : 50.0;
|
|
|
|
|
|
|
|
|
|
if(lrsi_value > 100.0)
|
|
|
|
|
lrsi_value = 100.0;
|
|
|
|
|
if(lrsi_value < 0.0)
|
|
|
|
|
lrsi_value = 0.0;
|
|
|
|
|
|
|
|
|
|
lrsi_buffer[i] = lrsi_value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--- 4. Calculate Signal Line (Without Volume)
|
|
|
|
|
m_ma_calculator.Calculate(rates_total, prev_calculated, PRICE_CLOSE,
|
|
|
|
|
lrsi_buffer, lrsi_buffer, lrsi_buffer, lrsi_buffer,
|
|
|
|
|
signal_buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//| Calculate (Overloaded - With Volume for VWMA) |
|
2025-11-28 19:42:44 +01:00
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
void CLaguerreRSICalculator::Calculate(int rates_total, int prev_calculated, ENUM_APPLIED_PRICE price_type, const double &open[], const double &high[], const double &low[], const double &close[],
|
2026-06-25 10:27:02 +02:00
|
|
|
const long &volume[],
|
2025-11-23 00:16:41 +01:00
|
|
|
double &lrsi_buffer[], double &signal_buffer[])
|
2025-10-18 17:48:38 +02:00
|
|
|
{
|
|
|
|
|
if(rates_total < 2)
|
|
|
|
|
return;
|
|
|
|
|
|
2025-11-28 19:42:44 +01:00
|
|
|
//--- 1. Calculate Laguerre Components (Incremental)
|
2026-06-25 10:27:02 +02:00
|
|
|
double dummy_filt[];
|
2025-11-28 19:42:44 +01:00
|
|
|
m_engine.CalculateFilter(rates_total, prev_calculated, price_type, open, high, low, close, dummy_filt);
|
2025-10-18 17:48:38 +02:00
|
|
|
|
2025-11-28 19:42:44 +01:00
|
|
|
//--- 2. Retrieve L0..L3 buffers
|
|
|
|
|
double L0[], L1[], L2[], L3[];
|
|
|
|
|
m_engine.GetLBuffers(L0, L1, L2, L3);
|
|
|
|
|
|
|
|
|
|
//--- 3. Calculate LRSI (Incremental Loop)
|
|
|
|
|
int start_index = (prev_calculated > 0) ? prev_calculated - 1 : 1;
|
|
|
|
|
if(start_index < 1)
|
|
|
|
|
start_index = 1;
|
|
|
|
|
|
|
|
|
|
for(int i = start_index; i < rates_total; i++)
|
2025-10-18 17:48:38 +02:00
|
|
|
{
|
2025-10-19 10:19:57 +02:00
|
|
|
double cu = 0.0, cd = 0.0;
|
2025-11-28 19:42:44 +01:00
|
|
|
|
2025-10-19 10:19:57 +02:00
|
|
|
if(L0[i] >= L1[i])
|
|
|
|
|
cu = L0[i] - L1[i];
|
2025-10-18 17:48:38 +02:00
|
|
|
else
|
2025-10-19 10:19:57 +02:00
|
|
|
cd = L1[i] - L0[i];
|
2025-11-28 19:42:44 +01:00
|
|
|
|
2025-10-19 10:19:57 +02:00
|
|
|
if(L1[i] >= L2[i])
|
|
|
|
|
cu += L1[i] - L2[i];
|
2025-10-18 17:48:38 +02:00
|
|
|
else
|
2025-10-19 10:19:57 +02:00
|
|
|
cd += L2[i] - L1[i];
|
2025-11-28 19:42:44 +01:00
|
|
|
|
2025-10-19 10:19:57 +02:00
|
|
|
if(L2[i] >= L3[i])
|
|
|
|
|
cu += L2[i] - L3[i];
|
2025-10-18 17:48:38 +02:00
|
|
|
else
|
2025-10-19 10:19:57 +02:00
|
|
|
cd += L3[i] - L2[i];
|
2025-10-18 17:48:38 +02:00
|
|
|
|
|
|
|
|
double lrsi_value;
|
|
|
|
|
if(cu + cd > 0.0)
|
|
|
|
|
lrsi_value = 100.0 * cu / (cu + cd);
|
|
|
|
|
else
|
2026-06-25 10:27:02 +02:00
|
|
|
lrsi_value = (i > 0) ? lrsi_buffer[i-1] : 50.0;
|
2025-10-18 17:48:38 +02:00
|
|
|
|
|
|
|
|
if(lrsi_value > 100.0)
|
|
|
|
|
lrsi_value = 100.0;
|
|
|
|
|
if(lrsi_value < 0.0)
|
|
|
|
|
lrsi_value = 0.0;
|
2025-11-28 19:42:44 +01:00
|
|
|
|
2025-10-18 17:48:38 +02:00
|
|
|
lrsi_buffer[i] = lrsi_value;
|
|
|
|
|
}
|
2025-11-23 00:16:41 +01:00
|
|
|
|
2026-06-25 10:27:02 +02:00
|
|
|
//--- 4. Calculate Signal Line (With Volume)
|
2025-11-28 19:42:44 +01:00
|
|
|
m_ma_calculator.Calculate(rates_total, prev_calculated, PRICE_CLOSE,
|
|
|
|
|
lrsi_buffer, lrsi_buffer, lrsi_buffer, lrsi_buffer,
|
2026-06-25 10:27:02 +02:00
|
|
|
volume,
|
2025-11-28 19:42:44 +01:00
|
|
|
signal_buffer);
|
2025-10-18 17:48:38 +02:00
|
|
|
}
|
|
|
|
|
|
2025-11-28 19:42:44 +01:00
|
|
|
//+==================================================================+
|
|
|
|
|
//| CLASS 2: CLaguerreRSICalculator_HA |
|
2025-10-18 17:48:38 +02:00
|
|
|
//+==================================================================+
|
|
|
|
|
class CLaguerreRSICalculator_HA : public CLaguerreRSICalculator
|
|
|
|
|
{
|
2025-10-19 10:19:57 +02:00
|
|
|
public:
|
|
|
|
|
CLaguerreRSICalculator_HA(void)
|
2025-10-18 17:48:38 +02:00
|
|
|
{
|
2025-10-19 10:19:57 +02:00
|
|
|
if(CheckPointer(m_engine) != POINTER_INVALID)
|
|
|
|
|
delete m_engine;
|
|
|
|
|
m_engine = new CLaguerreEngine_HA();
|
|
|
|
|
};
|
|
|
|
|
};
|
2025-10-18 17:48:38 +02:00
|
|
|
//+------------------------------------------------------------------+
|
2026-06-25 10:27:02 +02:00
|
|
|
#endif // LAGUERRE_RSI_CALCULATOR_MQH
|
|
|
|
|
//+------------------------------------------------------------------+
|