From 07c6645817790bfa629028f25e26b55c4b35ce0c Mon Sep 17 00:00:00 2001 From: Toh4iem9 Date: Sun, 2 Nov 2025 13:29:09 +0100 Subject: [PATCH] new files added --- Indicators/MyIndicators/DMIStochastic_Pro.mq5 | 122 ++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 Indicators/MyIndicators/DMIStochastic_Pro.mq5 diff --git a/Indicators/MyIndicators/DMIStochastic_Pro.mq5 b/Indicators/MyIndicators/DMIStochastic_Pro.mq5 new file mode 100644 index 0000000..e106b3b --- /dev/null +++ b/Indicators/MyIndicators/DMIStochastic_Pro.mq5 @@ -0,0 +1,122 @@ +//+------------------------------------------------------------------+ +//| DMIStochastic_Pro.mq5 | +//| Copyright 2025, xxxxxxxx| +//| | +//+------------------------------------------------------------------+ +#property copyright "Copyright 2025, xxxxxxxx" +#property link "" +#property version "1.21" // Fixed enum location for compilation +#property description "Barbara Star's DMI Stochastic Oscillator. Supports Standard and Heikin Ashi sources." + +#property indicator_separate_window +#property indicator_buffers 2 +#property indicator_plots 2 + +#property indicator_level1 20.0 +#property indicator_level2 50.0 +#property indicator_level3 80.0 +#property indicator_levelstyle STYLE_DOT + +//--- Plot 1: DMI Stoch %K (Main line) +#property indicator_label1 "%K" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrDodgerBlue +#property indicator_style1 STYLE_SOLID +#property indicator_width1 1 + +//--- Plot 2: DMI Stoch %D (Signal line) +#property indicator_label2 "%D" +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrOrangeRed +#property indicator_style2 STYLE_DOT +#property indicator_width2 1 + +//--- Include the calculator engine --- +// The enums are now defined inside this .mqh file +#include + +//--- Input Parameters --- +input ENUM_CANDLE_SOURCE InpCandleSource = CANDLE_STANDARD; // Candle source +input ENUM_DMI_OSC_TYPE InpOscType = OSC_PDI_MINUS_NDI; // Oscillator Formula +input int InpDMIPeriod = 10; // DMI Period +input int InpFastKPeriod = 10; // Stochastic %K Period +input int InpSlowKPeriod = 3; // Stochastic %K Slowing +input int InpSmoothPeriod = 3; // Stochastic %D Period (Signal) +input ENUM_MA_METHOD InpStochMethod = MODE_SMA; // MA Method for Stochastic + +//--- Indicator Buffers --- +double BufferK[]; +double BufferD[]; + +//--- Global calculator object --- +CDMIStochasticCalculator *g_calculator; + +//+------------------------------------------------------------------+ +//| Custom indicator initialization function | +//+------------------------------------------------------------------+ +int OnInit() + { + SetIndexBuffer(0, BufferK, INDICATOR_DATA); + SetIndexBuffer(1, BufferD, INDICATOR_DATA); + ArraySetAsSeries(BufferK, false); + ArraySetAsSeries(BufferD, false); + + if(InpCandleSource == CANDLE_HEIKIN_ASHI) + { + g_calculator = new CDMIStochasticCalculator_HA(); + } + else + { + g_calculator = new CDMIStochasticCalculator(); + } + + if(CheckPointer(g_calculator) == POINTER_INVALID || !g_calculator.Init(InpDMIPeriod, InpFastKPeriod, InpSlowKPeriod, InpSmoothPeriod, InpStochMethod, InpOscType)) + { + Print("Failed to create or initialize DMI Stochastic Calculator."); + return(INIT_FAILED); + } + + string short_name = StringFormat("DMI Stoch%s(%d,%d,%d,%d)", + (InpCandleSource == CANDLE_HEIKIN_ASHI ? " HA" : ""), + InpDMIPeriod, InpFastKPeriod, InpSlowKPeriod, InpSmoothPeriod); + IndicatorSetString(INDICATOR_SHORTNAME, short_name); + + int draw_begin = InpDMIPeriod + InpFastKPeriod + InpSlowKPeriod + InpSmoothPeriod - 2; + PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, draw_begin); + PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, draw_begin); + + return(INIT_SUCCEEDED); + } + +//+------------------------------------------------------------------+ +//| Custom indicator deinitialization function | +//+------------------------------------------------------------------+ +void OnDeinit(const int reason) + { + if(CheckPointer(g_calculator) != POINTER_INVALID) + delete g_calculator; + } + +//+------------------------------------------------------------------+ +//| Custom indicator calculation function | +//+------------------------------------------------------------------+ +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); + + g_calculator.Calculate(rates_total, open, high, low, close, BufferK, BufferD); + + return(rates_total); + } +//+------------------------------------------------------------------+ +//+------------------------------------------------------------------+