From c50cd1a67179af439669fa34e8ce74af972f2d3e Mon Sep 17 00:00:00 2001 From: Toh4iem9 Date: Wed, 27 Aug 2025 13:36:15 +0200 Subject: [PATCH] new files added --- .../Authors/Blau/Blau_Ergodic_DTI.mq5 | 220 ++++++++++++++++++ 1 file changed, 220 insertions(+) create mode 100644 Indicators/MyIndicators/Authors/Blau/Blau_Ergodic_DTI.mq5 diff --git a/Indicators/MyIndicators/Authors/Blau/Blau_Ergodic_DTI.mq5 b/Indicators/MyIndicators/Authors/Blau/Blau_Ergodic_DTI.mq5 new file mode 100644 index 0000000..1dde05e --- /dev/null +++ b/Indicators/MyIndicators/Authors/Blau/Blau_Ergodic_DTI.mq5 @@ -0,0 +1,220 @@ +//+------------------------------------------------------------------+ +//| Blau_Ergodic_DTI.mq5 | +//| Copyright 2025, xxxxxxxx | +//| | +//+------------------------------------------------------------------+ +#property copyright "Copyright 2025, xxxxxxxx" +#property link "" +#property version "1.00" +#property description "Ergodic Directional Trend Index (DTI) by William Blau." +#property description "Combines DTI with an optional, configurable signal line." + +//--- Indicator Window and Plot Properties --- +#property indicator_separate_window +#property indicator_buffers 2 // DTI and Signal Line +#property indicator_plots 2 +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrDodgerBlue +#property indicator_label1 "Ergodic DTI" +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrOrangeRed +#property indicator_label2 "Signal" +#property indicator_style2 STYLE_DOT +#property indicator_level1 -25.0 +#property indicator_level2 25.0 +#property indicator_level3 0.0 +#property indicator_levelstyle STYLE_DOT + +//--- Input Parameters --- +input int InpMomentumPeriod = 1; // Momentum Period +input int InpSlowPeriod = 20; // Slow EMA Period (1st smoothing) +input int InpFastPeriod = 5; // Fast EMA Period (2nd smoothing) +input group "Signal Line Settings" +input int InpSignalPeriod = 3; // Signal Line Period +input ENUM_MA_METHOD InpSignalMAType = MODE_EMA; // Signal Line MA Type + +//--- Indicator Buffers --- +double BufferDTI[]; +double BufferSignal[]; + +//--- Global Variables --- +int g_ExtMomentumPeriod, g_ExtSlowPeriod, g_ExtFastPeriod, g_ExtSignalPeriod; + +//+------------------------------------------------------------------+ +//| Custom indicator initialization function. | +//+------------------------------------------------------------------+ +int OnInit() + { + g_ExtMomentumPeriod = (InpMomentumPeriod < 1) ? 1 : InpMomentumPeriod; + g_ExtSlowPeriod = (InpSlowPeriod < 1) ? 1 : InpSlowPeriod; + g_ExtFastPeriod = (InpFastPeriod < 1) ? 1 : InpFastPeriod; + g_ExtSignalPeriod = (InpSignalPeriod < 1) ? 1 : InpSignalPeriod; + + SetIndexBuffer(0, BufferDTI, INDICATOR_DATA); + SetIndexBuffer(1, BufferSignal, INDICATOR_DATA); + + ArraySetAsSeries(BufferDTI, false); + ArraySetAsSeries(BufferSignal, false); + + int dti_draw_begin = g_ExtMomentumPeriod + g_ExtSlowPeriod + g_ExtFastPeriod; + PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, dti_draw_begin); + PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, dti_draw_begin + g_ExtSignalPeriod - 1); + IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("Ergodic DTI(%d,%d,%d)", g_ExtSlowPeriod, g_ExtFastPeriod, g_ExtSignalPeriod)); + IndicatorSetInteger(INDICATOR_DIGITS, 2); + + return(INIT_SUCCEEDED); + } + +//+------------------------------------------------------------------+ +//| Ergodic DTI 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[]) + { + int start_pos = g_ExtMomentumPeriod + g_ExtSlowPeriod + g_ExtFastPeriod + g_ExtSignalPeriod; + if(rates_total <= start_pos) + return(0); + +//--- STEP 1: Calculate Composite High/Low Momentum and its Absolute Value + double hlm[], abs_hlm[]; + ArrayResize(hlm, rates_total); + ArrayResize(abs_hlm, rates_total); + for(int i = g_ExtMomentumPeriod; i < rates_total; i++) + { + double up_mtm = high[i] - high[i - g_ExtMomentumPeriod]; + if(up_mtm < 0) + up_mtm = 0; + + double down_mtm = low[i - g_ExtMomentumPeriod] - low[i]; + if(down_mtm < 0) + down_mtm = 0; + + hlm[i] = up_mtm - down_mtm; + abs_hlm[i] = MathAbs(hlm[i]); + } + +//--- STEP 2: First EMA Smoothing (Slow Period) + double ema1_hlm[], ema1_abs_hlm[]; + ArrayResize(ema1_hlm, rates_total); + ArrayResize(ema1_abs_hlm, rates_total); + double pr_slow = 2.0 / (g_ExtSlowPeriod + 1.0); + int ema1_start_pos = g_ExtMomentumPeriod + g_ExtSlowPeriod -1; + + for(int i = ema1_start_pos; i < rates_total; i++) + { + if(i == ema1_start_pos) + { + double sum_hlm=0, sum_abs_hlm=0; + for(int j=0; j 0) + { + BufferDTI[i] = 100 * (ema2_hlm[i] / ema2_abs_hlm[i]); + } + } + +//--- STEP 5: Calculate the Signal Line + int signal_start_pos = ema2_start_pos + g_ExtSignalPeriod - 1; + for(int i = signal_start_pos; i < rates_total; i++) + { + switch(InpSignalMAType) + { + case MODE_EMA: + case MODE_SMMA: + if(i == signal_start_pos) + { + double sum=0; + for(int j=0; j0) + BufferSignal[i]=lwma_sum/weight_sum; + } + break; + default: // MODE_SMA + { + double sum=0; + for(int j=0; j