refactor(indicators): Pure DMI-based Adaptivity

This commit is contained in:
Toh4iem9
2026-02-17 09:57:50 +01:00
parent c19a57eb16
commit ef018baa06
@@ -3,9 +3,9 @@
//| Copyright 2026, xxxxxxxx| //| Copyright 2026, xxxxxxxx|
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
#property copyright "Copyright 2026, xxxxxxxx" #property copyright "Copyright 2026, xxxxxxxx"
#property version "1.01" #property version "2.00" // Pure DMI-based Adaptivity
#property description "Adaptive Stochastic Oscillator applied to DMI." #property description "Adaptive Stochastic applied to DMI Oscillator."
#property description "Dynamically adjusts lookback based on DMI volatility." #property description "Adapts lookback based on DMI's own volatility."
#property indicator_separate_window #property indicator_separate_window
#property indicator_buffers 2 #property indicator_buffers 2
@@ -32,35 +32,31 @@
#property indicator_minimum 0.0 #property indicator_minimum 0.0
#property indicator_maximum 100.0 #property indicator_maximum 100.0
//--- Includes (Fixed: Correct path)
#include <MyIncludes\Stochastic_Adaptive_on_DMI_Calculator.mqh> #include <MyIncludes\Stochastic_Adaptive_on_DMI_Calculator.mqh>
//--- Input Parameters //--- Input Parameters
input group "Source Settings" input group "DMI Settings"
// Declared in Calculator.mqh now input int InpDMIPeriod = 10;
input ENUM_CANDLE_SOURCE InpCandleSource = CANDLE_STANDARD; input ENUM_DMI_OSC_TYPE InpOscType = OSC_PDI_MINUS_NDI;
input ENUM_DMI_ADAPTIVE_OSC_TYPE InpOscType = OSC_PDI_MINUS_NDI;
input int InpDMIPeriod = 14;
//+------------------------------------------------------------------+ input group "Adaptive Settings"
//| | input int InpErPeriod = 10; // Efficiency Ratio Period
//+------------------------------------------------------------------+
input group "Adaptive Logic (ER)"
input int InpERPeriod = 10; // Efficiency Ratio Period
input int InpMinStochPeriod= 5; // Min Dynamic Period input int InpMinStochPeriod= 5; // Min Dynamic Period
input int InpMaxStochPeriod= 30; // Max Dynamic Period input int InpMaxStochPeriod= 30; // Max Dynamic Period
input group "Smoothing" input group "Stochastic Settings"
input int InpSlowingK = 3; // %K Slowing Period input int InpSlowingPeriod = 3;
input ENUM_MA_TYPE InpSlowingMethod = SMA; // %K Method input ENUM_MA_TYPE InpSlowingMAType = SMA;
input int InpSignalD = 3; // %D Period input int InpDPeriod = 3;
input ENUM_MA_TYPE InpSignalMethod = SMA; // %D Method input ENUM_MA_TYPE InpDMAType = SMA;
input group "Price Source"
input ENUM_CANDLE_SOURCE InpCandleSource = CANDLE_STANDARD; // Controls DMI Input
//--- Buffers //--- Buffers
double BufferK[]; double BufferK[], BufferD[];
double BufferD[];
//--- Calculator //--- Global Object
CStochAdaptiveOnDMICalculator *g_calculator; CStochAdaptiveOnDMICalculator *g_calculator;
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
@@ -68,32 +64,29 @@ CStochAdaptiveOnDMICalculator *g_calculator;
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
int OnInit() int OnInit()
{ {
// 1. Buffer Mapping
SetIndexBuffer(0, BufferK, INDICATOR_DATA); SetIndexBuffer(0, BufferK, INDICATOR_DATA);
SetIndexBuffer(1, BufferD, INDICATOR_DATA); SetIndexBuffer(1, BufferD, INDICATOR_DATA);
ArraySetAsSeries(BufferK, false); ArraySetAsSeries(BufferK, false);
ArraySetAsSeries(BufferD, false); ArraySetAsSeries(BufferD, false);
// 2. Initialize Engine // Factory Logic based on Source
if(InpCandleSource == CANDLE_HEIKIN_ASHI) if(InpCandleSource == CANDLE_HEIKIN_ASHI)
g_calculator = new CStochAdaptiveOnDMICalculator_HA(); g_calculator = new CStochAdaptiveOnDMICalculator_HA();
else else
g_calculator = new CStochAdaptiveOnDMICalculator(); g_calculator = new CStochAdaptiveOnDMICalculator();
if(!g_calculator.Init(InpDMIPeriod, InpERPeriod, InpMinStochPeriod, InpMaxStochPeriod, if(CheckPointer(g_calculator) == POINTER_INVALID ||
InpSlowingK, InpSlowingMethod, InpSignalD, InpSignalMethod, InpOscType)) !g_calculator.Init(InpDMIPeriod, InpOscType, InpErPeriod, InpMinStochPeriod, InpMaxStochPeriod, InpSlowingPeriod, InpSlowingMAType, InpDPeriod, InpDMAType))
{ {
Print("Init Failed."); Print("Failed to initialize Calculator.");
return(INIT_FAILED); return(INIT_FAILED);
} }
// 3. Metadata string name = StringFormat("StochAdaptiveDMI(%d, ER:%d)", InpDMIPeriod, InpErPeriod);
string name = StringFormat("StochAdaptiveDMI(%d, ER:%d, Dyn:%d-%d)",
InpDMIPeriod, InpERPeriod, InpMinStochPeriod, InpMaxStochPeriod);
IndicatorSetString(INDICATOR_SHORTNAME, name); IndicatorSetString(INDICATOR_SHORTNAME, name);
IndicatorSetInteger(INDICATOR_DIGITS, 2); IndicatorSetInteger(INDICATOR_DIGITS, 2);
int draw_begin = InpDMIPeriod + InpERPeriod + InpMaxStochPeriod + InpSlowingK + InpSignalD; int draw_begin = InpDMIPeriod + InpErPeriod + InpMaxStochPeriod + InpSlowingPeriod + InpDPeriod;
PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, draw_begin); PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, draw_begin);
PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, draw_begin); PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, draw_begin);
@@ -126,6 +119,7 @@ int OnCalculate(const int rates_total,
if(rates_total < InpDMIPeriod + InpMaxStochPeriod) if(rates_total < InpDMIPeriod + InpMaxStochPeriod)
return 0; return 0;
// We pass standard OHLC, the HA calculator will convert internally if needed
g_calculator.Calculate(rates_total, prev_calculated, open, high, low, close, BufferK, BufferD); g_calculator.Calculate(rates_total, prev_calculated, open, high, low, close, BufferK, BufferD);
return(rates_total); return(rates_total);