refactor: Refactored to use MovingAverage_Engine

This commit is contained in:
Toh4iem9
2025-12-21 00:28:23 +01:00
parent 57e3282f93
commit 32d50dc0f9
@@ -1,10 +1,9 @@
//+------------------------------------------------------------------+
//| Stochastic_Adaptive_Pro.mq5 |
//| Copyright 2025, xxxxxxxx|
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, xxxxxxxx"
#property version "1.00"
#property version "2.00" // Refactored to use MovingAverage_Engine
#property description "Frank Key's Variable-Length Stochastic, using Kaufman's ER."
#property description "Dynamically adjusts its period based on market trendiness."
@@ -37,11 +36,15 @@ input group "Adaptive Settings"
input int InpErPeriod = 10; // Efficiency Ratio Period
input int InpMinStochPeriod= 5; // Minimum Stochastic Period
input int InpMaxStochPeriod= 30; // Maximum Stochastic Period
input group "Stochastic & Price Settings"
input int InpSlowingPeriod = 3;
// UPDATED: Use ENUM_MA_TYPE
input ENUM_MA_TYPE InpSlowingMAType = SMA;
input int InpDPeriod = 3;
input ENUM_APPLIED_PRICE_HA_ALL InpSourcePrice = PRICE_CLOSE_STD;
// UPDATED: Use ENUM_MA_TYPE
input ENUM_MA_TYPE InpDMAType = SMA;
input ENUM_APPLIED_PRICE_HA_ALL InpSourcePrice = PRICE_CLOSE_STD;
//--- Indicator Buffers ---
double BufferK[], BufferD[];
@@ -63,7 +66,7 @@ int OnInit()
g_calculator = new CStochasticAdaptiveCalculator();
if(CheckPointer(g_calculator) == POINTER_INVALID ||
!g_calculator.Init(InpErPeriod, InpMinStochPeriod, InpMaxStochPeriod, InpSlowingPeriod, InpDPeriod, InpDMAType))
!g_calculator.Init(InpErPeriod, InpMinStochPeriod, InpMaxStochPeriod, InpSlowingPeriod, InpSlowingMAType, InpDPeriod, InpDMAType))
{
Print("Failed to create or initialize Adaptive Stochastic Calculator.");
return(INIT_FAILED);
@@ -82,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);
}
//+------------------------------------------------------------------+