refactor: Overloaded Calculate to support VWMA

This commit is contained in:
Toh4iem9
2026-06-25 15:51:21 +02:00
parent f29bbc888e
commit 34b724a49b
@@ -1,9 +1,14 @@
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
//| Laguerre_Stoch_Fast_Calculator.mqh | //| Laguerre_Stoch_Fast_Calculator.mqh |
//| Laguerre Stochastic: Stoch calculation on L0-L3 components. | //| Laguerre Stochastic: Stoch calculation on L0-L3 components. |
//| VERSION 1.20: Overloaded Calculate to support VWMA. |
//| Copyright 2026, xxxxxxxx | //| Copyright 2026, xxxxxxxx |
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
#property copyright "Copyright 2026, xxxxxxxx" #property copyright "Copyright 2026, xxxxxxxx"
#property version "1.20"
#ifndef LAGUERRE_STOCH_FAST_CALCULATOR_MQH
#define LAGUERRE_STOCH_FAST_CALCULATOR_MQH
#include <MyIncludes\Laguerre_Engine.mqh> #include <MyIncludes\Laguerre_Engine.mqh>
#include <MyIncludes\MovingAverage_Engine.mqh> #include <MyIncludes\MovingAverage_Engine.mqh>
@@ -26,8 +31,14 @@ public:
bool Init(double gamma, int signal_period, ENUM_MA_TYPE signal_method); bool Init(double gamma, int signal_period, ENUM_MA_TYPE signal_method);
//--- Standard Calculate (Without volume)
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[], 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 &stoch_buffer[], double &signal_buffer[]); double &stoch_buffer[], double &signal_buffer[]);
//--- Overloaded Calculate (With volume to support VWMA Signal)
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[],
const long &volume[],
double &stoch_buffer[], double &signal_buffer[]);
}; };
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
@@ -76,7 +87,7 @@ bool CLaguerreStochFastCalculator::Init(double gamma, int signal_period, ENUM_MA
} }
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
//| Main Calculation | //| Calculate (Standard - No Volume) |
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
void CLaguerreStochFastCalculator::Calculate(int rates_total, int prev_calculated, ENUM_APPLIED_PRICE price_type, const double &open[], const double &high[], const double &low[], const double &close[], void CLaguerreStochFastCalculator::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 &stoch_buffer[], double &signal_buffer[]) double &stoch_buffer[], double &signal_buffer[])
@@ -97,30 +108,65 @@ void CLaguerreStochFastCalculator::Calculate(int rates_total, int prev_calculate
for(int i = start_index; i < rates_total; i++) for(int i = start_index; i < rates_total; i++)
{ {
// Find Highest High and Lowest Low among L0..L3
double hh = MathMax(MathMax(L0[i], L1[i]), MathMax(L2[i], L3[i])); double hh = MathMax(MathMax(L0[i], L1[i]), MathMax(L2[i], L3[i]));
double ll = MathMin(MathMin(L0[i], L1[i]), MathMin(L2[i], L3[i])); double ll = MathMin(MathMin(L0[i], L1[i]), MathMin(L2[i], L3[i]));
double diff = hh - ll; double diff = hh - ll;
if(diff > 0) if(diff > 0)
{
// Standard formula: (Current - Low) / (High - Low)
// Here "Current" is typically L0 (the most responsive component)
stoch_buffer[i] = ((L0[i] - ll) / diff) * 100.0; stoch_buffer[i] = ((L0[i] - ll) / diff) * 100.0;
}
else else
{
// Flat market or initialization
stoch_buffer[i] = (i > 0) ? stoch_buffer[i-1] : 50.0; stoch_buffer[i] = (i > 0) ? stoch_buffer[i-1] : 50.0;
}
} }
//--- 4. Calculate Signal Line //--- 4. Calculate Signal Line
// We pass stoch_buffer as the source for the MA
m_signal_engine.CalculateOnArray(rates_total, prev_calculated, stoch_buffer, signal_buffer); m_signal_engine.CalculateOnArray(rates_total, prev_calculated, stoch_buffer, signal_buffer);
} }
//+------------------------------------------------------------------+
//| Calculate (Overloaded - With Volume for VWMA Signal) |
//+------------------------------------------------------------------+
void CLaguerreStochFastCalculator::Calculate(int rates_total, int prev_calculated, ENUM_APPLIED_PRICE price_type, const double &open[], const double &high[], const double &low[], const double &close[],
const long &volume[],
double &stoch_buffer[], double &signal_buffer[])
{
if(rates_total < 2)
return;
//--- 1. Calculate Laguerre Components
double dummy_filt[];
m_laguerre_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_laguerre_engine.GetLBuffers(L0, L1, L2, L3);
//--- 3. Calculate Stochastic (Incremental Loop)
int start_index = (prev_calculated > 0) ? prev_calculated - 1 : 0;
for(int i = start_index; i < rates_total; i++)
{
double hh = MathMax(MathMax(L0[i], L1[i]), MathMax(L2[i], L3[i]));
double ll = MathMin(MathMin(L0[i], L1[i]), MathMin(L2[i], L3[i]));
double diff = hh - ll;
if(diff > 0)
stoch_buffer[i] = ((L0[i] - ll) / diff) * 100.0;
else
stoch_buffer[i] = (i > 0) ? stoch_buffer[i-1] : 50.0;
}
//--- 4. Convert long volume to double to support VWMA Signal
double vol_double[];
ArrayResize(vol_double, rates_total);
for(int j = start_index; j < rates_total; j++)
vol_double[j] = (double)volume[j];
//--- 5. Calculate Signal Line
m_signal_engine.CalculateOnArray(rates_total, prev_calculated, stoch_buffer, vol_double, signal_buffer);
}
//+==================================================================+ //+==================================================================+
//| CLASS 2: CLaguerreStochFastCalculator_HA | //| CLASS 2: CLaguerreStochFastCalculator_HA |
//+==================================================================+ //+==================================================================+
@@ -130,8 +176,6 @@ protected:
virtual void CreateEngines(void) override; virtual void CreateEngines(void) override;
}; };
//+------------------------------------------------------------------+
//| Factory Override |
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
void CLaguerreStochFastCalculator_HA::CreateEngines(void) void CLaguerreStochFastCalculator_HA::CreateEngines(void)
{ {
@@ -139,3 +183,5 @@ void CLaguerreStochFastCalculator_HA::CreateEngines(void)
m_signal_engine = new CMovingAverageCalculator(); m_signal_engine = new CMovingAverageCalculator();
} }
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
#endif // LAGUERRE_STOCH_FAST_CALCULATOR_MQH
//+------------------------------------------------------------------+