mirror of
https://github.com/softwaredevelop/mql5.git
synced 2026-08-17 14:28:07 +00:00
refactor: Refactored to use MovingAverage_Engine
This commit is contained in:
@@ -1,10 +1,9 @@
|
|||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
//| Stochastic_Adaptive_Pro.mq5 |
|
//| Stochastic_Adaptive_Pro.mq5 |
|
||||||
//| Copyright 2025, xxxxxxxx|
|
//| Copyright 2025, xxxxxxxx|
|
||||||
//| |
|
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
#property copyright "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 "Frank Key's Variable-Length Stochastic, using Kaufman's ER."
|
||||||
#property description "Dynamically adjusts its period based on market trendiness."
|
#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 InpErPeriod = 10; // Efficiency Ratio Period
|
||||||
input int InpMinStochPeriod= 5; // Minimum Stochastic Period
|
input int InpMinStochPeriod= 5; // Minimum Stochastic Period
|
||||||
input int InpMaxStochPeriod= 30; // Maximum Stochastic Period
|
input int InpMaxStochPeriod= 30; // Maximum Stochastic Period
|
||||||
|
|
||||||
input group "Stochastic & Price Settings"
|
input group "Stochastic & Price Settings"
|
||||||
input int InpSlowingPeriod = 3;
|
input int InpSlowingPeriod = 3;
|
||||||
|
// UPDATED: Use ENUM_MA_TYPE
|
||||||
|
input ENUM_MA_TYPE InpSlowingMAType = SMA;
|
||||||
input int InpDPeriod = 3;
|
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_MA_TYPE InpDMAType = SMA;
|
||||||
|
input ENUM_APPLIED_PRICE_HA_ALL InpSourcePrice = PRICE_CLOSE_STD;
|
||||||
|
|
||||||
//--- Indicator Buffers ---
|
//--- Indicator Buffers ---
|
||||||
double BufferK[], BufferD[];
|
double BufferK[], BufferD[];
|
||||||
@@ -63,7 +66,7 @@ int OnInit()
|
|||||||
g_calculator = new CStochasticAdaptiveCalculator();
|
g_calculator = new CStochasticAdaptiveCalculator();
|
||||||
|
|
||||||
if(CheckPointer(g_calculator) == POINTER_INVALID ||
|
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.");
|
Print("Failed to create or initialize Adaptive Stochastic Calculator.");
|
||||||
return(INIT_FAILED);
|
return(INIT_FAILED);
|
||||||
@@ -82,12 +85,28 @@ int OnInit()
|
|||||||
void OnDeinit(const int reason) { if(CheckPointer(g_calculator) != POINTER_INVALID) delete g_calculator; }
|
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)
|
if(CheckPointer(g_calculator) == POINTER_INVALID)
|
||||||
return 0;
|
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);
|
return(rates_total);
|
||||||
}
|
}
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
|
|||||||
Reference in New Issue
Block a user