mirror of
https://github.com/softwaredevelop/mql5.git
synced 2026-08-19 15:28:06 +00:00
refactor: Selectable ER Source
This commit is contained in:
@@ -1,13 +1,13 @@
|
|||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
//| Stochastic_Adaptive_RSI_Pro.mq5 |
|
//| Stochastic_Adaptive_RSI_Pro.mq5 |
|
||||||
//| Copyright 2025, xxxxxxxx|
|
//| Copyright 2025, xxxxxxxx|
|
||||||
//| |
|
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
#property copyright "Copyright 2025, xxxxxxxx"
|
#property copyright "Copyright 2025, xxxxxxxx"
|
||||||
#property version "1.00"
|
#property version "3.00" // Selectable ER Source
|
||||||
#property description "Variable-Length Stochastic applied to an RSI series."
|
#property description "Variable-Length Stochastic applied to an RSI series."
|
||||||
#property description "Dynamically adjusts its period based on market trendiness (ER)."
|
#property description "Dynamically adjusts its period based on market trendiness (ER)."
|
||||||
|
|
||||||
|
//--- Indicator Window and Plot Properties ---
|
||||||
#property indicator_separate_window
|
#property indicator_separate_window
|
||||||
#property indicator_buffers 2
|
#property indicator_buffers 2
|
||||||
#property indicator_plots 2
|
#property indicator_plots 2
|
||||||
@@ -36,11 +36,15 @@ input int InpRSIPeriod = 14; // RSI Period
|
|||||||
input int InpErPeriod = 10; // Efficiency Ratio Period
|
input int InpErPeriod = 10; // Efficiency Ratio Period
|
||||||
input int InpMinStochPeriod= 5; // Minimum Stochastic Period on RSI
|
input int InpMinStochPeriod= 5; // Minimum Stochastic Period on RSI
|
||||||
input int InpMaxStochPeriod= 30; // Maximum Stochastic Period on RSI
|
input int InpMaxStochPeriod= 30; // Maximum Stochastic Period on RSI
|
||||||
|
// NEW: Adaptive Source Selection
|
||||||
|
input ENUM_ADAPTIVE_SOURCE InpAdaptiveSource= ADAPTIVE_SOURCE_STANDARD;
|
||||||
|
|
||||||
input group "Stochastic & Price Settings"
|
input group "Stochastic & Price Settings"
|
||||||
input int InpSlowingPeriod = 3;
|
input int InpSlowingPeriod = 3;
|
||||||
|
input ENUM_MA_TYPE InpSlowingMAType = SMA;
|
||||||
input int InpDPeriod = 3;
|
input int InpDPeriod = 3;
|
||||||
|
input ENUM_MA_TYPE InpDMAType = SMA;
|
||||||
input ENUM_APPLIED_PRICE_HA_ALL InpSourcePrice = PRICE_CLOSE_STD;
|
input ENUM_APPLIED_PRICE_HA_ALL InpSourcePrice = PRICE_CLOSE_STD;
|
||||||
input ENUM_MA_METHOD InpDMAType = MODE_SMA;
|
|
||||||
|
|
||||||
//--- Indicator Buffers ---
|
//--- Indicator Buffers ---
|
||||||
double BufferK[], BufferD[];
|
double BufferK[], BufferD[];
|
||||||
@@ -62,7 +66,7 @@ int OnInit()
|
|||||||
g_calculator = new CStochasticAdaptiveRSICalculator();
|
g_calculator = new CStochasticAdaptiveRSICalculator();
|
||||||
|
|
||||||
if(CheckPointer(g_calculator) == POINTER_INVALID ||
|
if(CheckPointer(g_calculator) == POINTER_INVALID ||
|
||||||
!g_calculator.Init(InpRSIPeriod, InpErPeriod, InpMinStochPeriod, InpMaxStochPeriod, InpSlowingPeriod, InpDPeriod, InpDMAType))
|
!g_calculator.Init(InpRSIPeriod, InpErPeriod, InpMinStochPeriod, InpMaxStochPeriod, InpSlowingPeriod, InpSlowingMAType, InpDPeriod, InpDMAType, InpAdaptiveSource))
|
||||||
{
|
{
|
||||||
Print("Failed to create or initialize Adaptive StochRSI Calculator.");
|
Print("Failed to create or initialize Adaptive StochRSI Calculator.");
|
||||||
return(INIT_FAILED);
|
return(INIT_FAILED);
|
||||||
@@ -81,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