mirror of
https://github.com/softwaredevelop/mql5.git
synced 2026-08-03 07:37:43 +00:00
refactor(indicators): Pure DMI-based Adaptivity
This commit is contained in:
@@ -3,9 +3,9 @@
|
||||
//| Copyright 2026, xxxxxxxx|
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2026, xxxxxxxx"
|
||||
#property version "1.01"
|
||||
#property description "Adaptive Stochastic Oscillator applied to DMI."
|
||||
#property description "Dynamically adjusts lookback based on DMI volatility."
|
||||
#property version "2.00" // Pure DMI-based Adaptivity
|
||||
#property description "Adaptive Stochastic applied to DMI Oscillator."
|
||||
#property description "Adapts lookback based on DMI's own volatility."
|
||||
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 2
|
||||
@@ -32,35 +32,31 @@
|
||||
#property indicator_minimum 0.0
|
||||
#property indicator_maximum 100.0
|
||||
|
||||
//--- Includes (Fixed: Correct path)
|
||||
#include <MyIncludes\Stochastic_Adaptive_on_DMI_Calculator.mqh>
|
||||
|
||||
//--- Input Parameters
|
||||
input group "Source Settings"
|
||||
// Declared in Calculator.mqh now
|
||||
input ENUM_CANDLE_SOURCE InpCandleSource = CANDLE_STANDARD;
|
||||
input ENUM_DMI_ADAPTIVE_OSC_TYPE InpOscType = OSC_PDI_MINUS_NDI;
|
||||
input int InpDMIPeriod = 14;
|
||||
input group "DMI Settings"
|
||||
input int InpDMIPeriod = 10;
|
||||
input ENUM_DMI_OSC_TYPE InpOscType = OSC_PDI_MINUS_NDI;
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
input group "Adaptive Logic (ER)"
|
||||
input int InpERPeriod = 10; // Efficiency Ratio Period
|
||||
input group "Adaptive Settings"
|
||||
input int InpErPeriod = 10; // Efficiency Ratio Period
|
||||
input int InpMinStochPeriod= 5; // Min Dynamic Period
|
||||
input int InpMaxStochPeriod= 30; // Max Dynamic Period
|
||||
|
||||
input group "Smoothing"
|
||||
input int InpSlowingK = 3; // %K Slowing Period
|
||||
input ENUM_MA_TYPE InpSlowingMethod = SMA; // %K Method
|
||||
input int InpSignalD = 3; // %D Period
|
||||
input ENUM_MA_TYPE InpSignalMethod = SMA; // %D Method
|
||||
input group "Stochastic Settings"
|
||||
input int InpSlowingPeriod = 3;
|
||||
input ENUM_MA_TYPE InpSlowingMAType = SMA;
|
||||
input int InpDPeriod = 3;
|
||||
input ENUM_MA_TYPE InpDMAType = SMA;
|
||||
|
||||
input group "Price Source"
|
||||
input ENUM_CANDLE_SOURCE InpCandleSource = CANDLE_STANDARD; // Controls DMI Input
|
||||
|
||||
//--- Buffers
|
||||
double BufferK[];
|
||||
double BufferD[];
|
||||
double BufferK[], BufferD[];
|
||||
|
||||
//--- Calculator
|
||||
//--- Global Object
|
||||
CStochAdaptiveOnDMICalculator *g_calculator;
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -68,32 +64,29 @@ CStochAdaptiveOnDMICalculator *g_calculator;
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
// 1. Buffer Mapping
|
||||
SetIndexBuffer(0, BufferK, INDICATOR_DATA);
|
||||
SetIndexBuffer(1, BufferD, INDICATOR_DATA);
|
||||
ArraySetAsSeries(BufferK, false);
|
||||
ArraySetAsSeries(BufferD, false);
|
||||
|
||||
// 2. Initialize Engine
|
||||
// Factory Logic based on Source
|
||||
if(InpCandleSource == CANDLE_HEIKIN_ASHI)
|
||||
g_calculator = new CStochAdaptiveOnDMICalculator_HA();
|
||||
else
|
||||
g_calculator = new CStochAdaptiveOnDMICalculator();
|
||||
|
||||
if(!g_calculator.Init(InpDMIPeriod, InpERPeriod, InpMinStochPeriod, InpMaxStochPeriod,
|
||||
InpSlowingK, InpSlowingMethod, InpSignalD, InpSignalMethod, InpOscType))
|
||||
if(CheckPointer(g_calculator) == POINTER_INVALID ||
|
||||
!g_calculator.Init(InpDMIPeriod, InpOscType, InpErPeriod, InpMinStochPeriod, InpMaxStochPeriod, InpSlowingPeriod, InpSlowingMAType, InpDPeriod, InpDMAType))
|
||||
{
|
||||
Print("Init Failed.");
|
||||
Print("Failed to initialize Calculator.");
|
||||
return(INIT_FAILED);
|
||||
}
|
||||
|
||||
// 3. Metadata
|
||||
string name = StringFormat("StochAdaptiveDMI(%d, ER:%d, Dyn:%d-%d)",
|
||||
InpDMIPeriod, InpERPeriod, InpMinStochPeriod, InpMaxStochPeriod);
|
||||
string name = StringFormat("StochAdaptiveDMI(%d, ER:%d)", InpDMIPeriod, InpErPeriod);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, name);
|
||||
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(1, PLOT_DRAW_BEGIN, draw_begin);
|
||||
|
||||
@@ -126,6 +119,7 @@ int OnCalculate(const int rates_total,
|
||||
if(rates_total < InpDMIPeriod + InpMaxStochPeriod)
|
||||
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);
|
||||
|
||||
return(rates_total);
|
||||
|
||||
Reference in New Issue
Block a user