Files
mql5/Include/MyIncludes/Laguerre_RSI_Calculator.mqh
T

90 lines
3.5 KiB
Plaintext
Raw Normal View History

2025-10-18 17:48:38 +02:00
//+------------------------------------------------------------------+
//| Laguerre_RSI_Calculator.mqh |
2025-10-19 10:19:57 +02:00
//| Adapter for the Laguerre RSI indicator. |
2025-10-18 17:48:38 +02:00
//| Copyright 2025, xxxxxxxx |
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, xxxxxxxx"
2025-10-19 10:19:57 +02:00
#include "Laguerre_Engine.mqh"
2025-10-18 17:48:38 +02:00
//+==================================================================+
//| |
//| CLASS 1: CLaguerreRSICalculator (Base Class) |
//| |
//+==================================================================+
class CLaguerreRSICalculator
{
protected:
2025-10-19 10:19:57 +02:00
CLaguerreEngine *m_engine;
2025-10-18 17:48:38 +02:00
public:
2025-10-19 10:19:57 +02:00
CLaguerreRSICalculator(void) { m_engine = new CLaguerreEngine(); };
virtual ~CLaguerreRSICalculator(void) { if(CheckPointer(m_engine) != POINTER_INVALID) delete m_engine; };
2025-10-18 17:48:38 +02:00
bool Init(double gamma);
void Calculate(int rates_total, ENUM_APPLIED_PRICE price_type, const double &open[], const double &high[], const double &low[], const double &close[], double &lrsi_buffer[]);
};
2025-10-19 10:19:57 +02:00
bool CLaguerreRSICalculator::Init(double gamma) { return m_engine.Init(gamma); }
2025-10-18 17:48:38 +02:00
//+------------------------------------------------------------------+
2025-10-19 10:19:57 +02:00
//| |
2025-10-18 17:48:38 +02:00
//+------------------------------------------------------------------+
void CLaguerreRSICalculator::Calculate(int rates_total, ENUM_APPLIED_PRICE price_type, const double &open[], const double &high[], const double &low[], const double &close[], double &lrsi_buffer[])
{
if(rates_total < 2)
return;
2025-10-19 10:19:57 +02:00
double L0[], L1[], L2[], L3[];
2025-10-19 13:44:51 +02:00
double dummy_filt[]; // Dummy buffer to satisfy the engine's new signature
m_engine.CalculateFilter(rates_total, price_type, open, high, low, close, L0, L1, L2, L3, dummy_filt);
2025-10-18 17:48:38 +02:00
for(int i = 1; i < rates_total; i++)
{
2025-10-19 10:19:57 +02:00
double cu = 0.0, cd = 0.0;
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];
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];
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
2025-10-19 10:19:57 +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;
lrsi_buffer[i] = lrsi_value;
}
}
//+==================================================================+
//| |
2025-10-19 10:19:57 +02:00
//| CLASS 2: CLaguerreRSICalculator_HA (Heikin Ashi) |
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
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+