diff --git a/Indicators/MyIndicators/Authors/Blau/Blau_Ergodic_SMI.mq5 b/Indicators/MyIndicators/Authors/Blau/Blau_Ergodic_SMI.mq5 new file mode 100644 index 0000000..c36ed0b --- /dev/null +++ b/Indicators/MyIndicators/Authors/Blau/Blau_Ergodic_SMI.mq5 @@ -0,0 +1,248 @@ +//+------------------------------------------------------------------+ +//| Blau_Ergodic_SMI.mq5 | +//| Copyright 2025, xxxxxxxx | +//| | +//+------------------------------------------------------------------+ +#property copyright "Copyright 2025, xxxxxxxx" +#property link "" +#property version "1.01" // Added full MA type support for signal line +#property description "Ergodic Stochastic Momentum Index (SMI) by William Blau." +#property description "Combines SMI with an optional, configurable signal line." + +//--- Indicator Window and Plot Properties --- +#property indicator_separate_window +#property indicator_buffers 2 // SMI and Signal Line +#property indicator_plots 2 +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrDodgerBlue +#property indicator_label1 "Ergodic SMI" +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrOrangeRed +#property indicator_label2 "Signal" +#property indicator_style2 STYLE_DOT +#property indicator_level1 -40.0 +#property indicator_level2 40.0 +#property indicator_level3 0.0 +#property indicator_levelstyle STYLE_DOT + +//--- Input Parameters --- +input int InpStochPeriod = 5; // Stochastic Period (%K) +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 = 5; // Signal Line Period +input ENUM_MA_METHOD InpSignalMAType = MODE_EMA; // Signal Line MA Type + +//--- Indicator Buffers --- +double BufferSMI[]; +double BufferSignal[]; + +//--- Global Variables --- +int g_ExtStochPeriod, g_ExtSlowPeriod, g_ExtFastPeriod, g_ExtSignalPeriod; + +//--- Forward declarations for helper functions --- +double Highest(const double &array[], int period, int current_pos); +double Lowest(const double &array[], int period, int current_pos); + +//+------------------------------------------------------------------+ +//| Custom indicator initialization function. | +//+------------------------------------------------------------------+ +int OnInit() + { + g_ExtStochPeriod = (InpStochPeriod < 1) ? 1 : InpStochPeriod; + g_ExtSlowPeriod = (InpSlowPeriod < 1) ? 1 : InpSlowPeriod; + g_ExtFastPeriod = (InpFastPeriod < 1) ? 1 : InpFastPeriod; + g_ExtSignalPeriod = (InpSignalPeriod < 1) ? 1 : InpSignalPeriod; + + SetIndexBuffer(0, BufferSMI, INDICATOR_DATA); + SetIndexBuffer(1, BufferSignal, INDICATOR_DATA); + + ArraySetAsSeries(BufferSMI, false); + ArraySetAsSeries(BufferSignal, false); + + int smi_draw_begin = g_ExtStochPeriod + g_ExtSlowPeriod + g_ExtFastPeriod - 2; + PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, smi_draw_begin); + PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, smi_draw_begin + g_ExtSignalPeriod - 1); + IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("Ergodic SMI(%d,%d,%d)", g_ExtStochPeriod, g_ExtSlowPeriod, g_ExtFastPeriod)); + IndicatorSetInteger(INDICATOR_DIGITS, 2); + + return(INIT_SUCCEEDED); + } + +//+------------------------------------------------------------------+ +//| Ergodic SMI 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_ExtStochPeriod + g_ExtSlowPeriod + g_ExtFastPeriod + g_ExtSignalPeriod - 2; + if(rates_total <= start_pos) + return(0); + +//--- STEP 1: Calculate Stochastic Momentum (SM) and Range + double sm[], range[]; + ArrayResize(sm, rates_total); + ArrayResize(range, rates_total); + for(int i = g_ExtStochPeriod - 1; i < rates_total; i++) + { + double highest_high = Highest(high, g_ExtStochPeriod, i); + double lowest_low = Lowest(low, g_ExtStochPeriod, i); + + sm[i] = close[i] - (highest_high + lowest_low) / 2.0; + range[i] = highest_high - lowest_low; + } + +//--- STEP 2: First EMA Smoothing (Slow Period) + double ema1_sm[], ema1_range[]; + ArrayResize(ema1_sm, rates_total); + ArrayResize(ema1_range, rates_total); + double pr_slow = 2.0 / (g_ExtSlowPeriod + 1.0); + int ema1_start_pos = g_ExtStochPeriod + g_ExtSlowPeriod - 2; + + for(int i = ema1_start_pos; i < rates_total; i++) + { + if(i == ema1_start_pos) + { + double sum_sm=0, sum_range=0; + for(int j=0; j0) + BufferSignal[i]=lwma_sum/weight_sum; + } + break; + default: // MODE_SMA + { + double sum=0; + for(int j=0; j array[current_pos - i]) + res = array[current_pos - i]; + } + return(res); + } +//+------------------------------------------------------------------+ +//+------------------------------------------------------------------+