diff --git a/Indicators/MyIndicators/Authors/Blau/Blau_Ergodic_MACD.mq5 b/Indicators/MyIndicators/Authors/Blau/Blau_Ergodic_MACD.mq5 new file mode 100644 index 0000000..cac7448 --- /dev/null +++ b/Indicators/MyIndicators/Authors/Blau/Blau_Ergodic_MACD.mq5 @@ -0,0 +1,237 @@ +//+------------------------------------------------------------------+ +//| Blau_Ergodic_MACD.mq5 | +//| Copyright 2025, xxxxxxxx | +//| | +//+------------------------------------------------------------------+ +#property copyright "Copyright 2025, xxxxxxxx" +#property link "" +#property version "2.02" // Separated from Oscillator +#property description "Ergodic MACD Oscillator by William Blau (Lines)." +#property description "Applies double EMA smoothing to the classic MACD and Signal lines." + +//--- Indicator Window and Plot Properties --- +#property indicator_separate_window +#property indicator_buffers 2 // Ergodic MACD and Ergodic Signal +#property indicator_plots 2 +#property indicator_level1 0.0 +#property indicator_levelstyle STYLE_DOT + +//--- Plot 1: Smoothed MACD Line +#property indicator_label1 "Ergodic MACD" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrDodgerBlue +#property indicator_style1 STYLE_SOLID +#property indicator_width1 1 + +//--- Plot 2: Smoothed Signal Line +#property indicator_label2 "Ergodic Signal" +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrOrangeRed +#property indicator_style2 STYLE_SOLID +#property indicator_width2 1 + +//--- Input Parameters --- +input group "Classic MACD Settings" +input int InpFastEMAPeriod = 12; +input int InpSlowEMAPeriod = 26; +input int InpSignalEMAPeriod = 9; +input ENUM_APPLIED_PRICE InpAppliedPrice = PRICE_CLOSE; +input group "Ergodic Smoothing Settings" +input int InpSlowSmoothPeriod = 20; +input int InpFastSmoothPeriod = 5; + +//--- Indicator Buffers --- +double BufferErgodicMACD[]; +double BufferErgodicSignal[]; + +//--- Global Variables --- +int g_ExtFastEMA, g_ExtSlowEMA, g_ExtSignalEMA, g_ExtSlowSmooth, g_ExtFastSmooth; + +//+------------------------------------------------------------------+ +//| Custom indicator initialization function. | +//+------------------------------------------------------------------+ +int OnInit() + { + g_ExtFastEMA = (InpFastEMAPeriod < 1) ? 1 : InpFastEMAPeriod; + g_ExtSlowEMA = (InpSlowEMAPeriod < 1) ? 1 : InpSlowEMAPeriod; + g_ExtSignalEMA = (InpSignalEMAPeriod < 1) ? 1 : InpSignalEMAPeriod; + g_ExtSlowSmooth = (InpSlowSmoothPeriod < 1) ? 1 : InpSlowSmoothPeriod; + g_ExtFastSmooth = (InpFastSmoothPeriod < 1) ? 1 : InpFastSmoothPeriod; + + if(g_ExtFastEMA > g_ExtSlowEMA) + { + int temp = g_ExtFastEMA; + g_ExtFastEMA = g_ExtSlowEMA; + g_ExtSlowEMA = temp; + } + + SetIndexBuffer(0, BufferErgodicMACD, INDICATOR_DATA); + SetIndexBuffer(1, BufferErgodicSignal, INDICATOR_DATA); + + ArraySetAsSeries(BufferErgodicMACD, false); + ArraySetAsSeries(BufferErgodicSignal, false); + + int draw_begin = g_ExtSlowEMA + g_ExtSignalEMA + g_ExtSlowSmooth + g_ExtFastSmooth - 3; + PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, draw_begin); + PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, draw_begin); + IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("Ergodic MACD(%d,%d,%d,%d,%d)", g_ExtFastEMA, g_ExtSlowEMA, g_ExtSignalEMA, g_ExtSlowSmooth, g_ExtFastSmooth)); + IndicatorSetInteger(INDICATOR_DIGITS, _Digits); + + return(INIT_SUCCEEDED); + } + +//+------------------------------------------------------------------+ +//| Ergodic MACD 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_ExtSlowEMA + g_ExtSignalEMA + g_ExtSlowSmooth + g_ExtFastSmooth - 3; + if(rates_total <= start_pos) + return(0); + +//--- STEP 1: Calculate Classic MACD Line and Signal Line (internal buffers) --- + double classic_macd_line[], classic_signal_line[]; + ArrayResize(classic_macd_line, rates_total); + ArrayResize(classic_signal_line, rates_total); + +// Calculate Classic MACD Line + { + double price_source[]; + ArrayResize(price_source, rates_total); + for(int i=0; i