From c7d30c2dc994200ba94650256378c874338a3604 Mon Sep 17 00:00:00 2001 From: Toh4iem9 Date: Fri, 3 Jul 2026 21:00:04 +0200 Subject: [PATCH] new files added --- .../Butterworth_Bands_Pro.mq5 | 143 ++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 Indicators/MyIndicators/Authors/Ehlers/4_Channels_and_Bands/Butterworth_Bands_Pro.mq5 diff --git a/Indicators/MyIndicators/Authors/Ehlers/4_Channels_and_Bands/Butterworth_Bands_Pro.mq5 b/Indicators/MyIndicators/Authors/Ehlers/4_Channels_and_Bands/Butterworth_Bands_Pro.mq5 new file mode 100644 index 0000000..1df9704 --- /dev/null +++ b/Indicators/MyIndicators/Authors/Ehlers/4_Channels_and_Bands/Butterworth_Bands_Pro.mq5 @@ -0,0 +1,143 @@ +//+------------------------------------------------------------------+ +//| Butterworth_Bands_Pro.mq5 | +//| Copyright 2026, xxxxxxxx| +//+------------------------------------------------------------------+ +#property copyright "Copyright 2026, xxxxxxxx" +#property version "1.00" // High-performance John Ehlers' Butterworth Bands with 3-digit precision +#property description "Butterworth Bands (Bollinger Concept): Butterworth Filter Middle Line" +#property description "with Standard Deviation based bands." + +#property indicator_chart_window +#property indicator_buffers 3 +#property indicator_plots 3 + +//--- Plot 1: Upper Band +#property indicator_label1 "Upper Band" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrCornflowerBlue +#property indicator_style1 STYLE_SOLID +#property indicator_width1 1 + +//--- Plot 2: Lower Band +#property indicator_label2 "Lower Band" +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrCornflowerBlue +#property indicator_style2 STYLE_SOLID +#property indicator_width2 1 + +//--- Plot 3: Middle Band (Butterworth) +#property indicator_label3 "Middle" +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrCrimson +#property indicator_style3 STYLE_SOLID +#property indicator_width3 1 + +#include + +//--- Input Parameters +input group "Butterworth Settings" +input int InpButterPeriod = 20; // Filter Period +input ENUM_BUTTERWORTH_POLES InpPoles = POLES_TWO; // Filter Poles (2 or 3) +input ENUM_APPLIED_PRICE_HA_ALL InpSourcePrice = PRICE_CLOSE_STD; // Price Source + +//+------------------------------------------------------------------+ +//| | +//+------------------------------------------------------------------+ +input group "Bands (StdDev) Settings" +input int InpPeriod = 20; // Standard Deviation Period (N) +input double InpDeviation = 2.0; // Deviation Multiplier (d) + +//--- Buffers +double BufferUpper[]; +double BufferLower[]; +double BufferMiddle[]; + +//--- Global Object +CButterworthBandsCalculator *g_calculator; + +//+------------------------------------------------------------------+ +//| OnInit | +//+------------------------------------------------------------------+ +int OnInit() + { + SetIndexBuffer(0, BufferUpper, INDICATOR_DATA); + SetIndexBuffer(1, BufferLower, INDICATOR_DATA); + SetIndexBuffer(2, BufferMiddle, INDICATOR_DATA); + ArraySetAsSeries(BufferUpper, false); + ArraySetAsSeries(BufferLower, false); + ArraySetAsSeries(BufferMiddle, false); + +//--- Factory Logic + if(InpSourcePrice <= PRICE_HA_CLOSE) + g_calculator = new CButterworthBandsCalculator_HA(); + else + g_calculator = new CButterworthBandsCalculator(); + +//--- Initialize + if(CheckPointer(g_calculator) == POINTER_INVALID || + !g_calculator.Init(InpPeriod, InpDeviation, InpButterPeriod, InpPoles)) + { + Print("Failed to initialize Butterworth Bands Calculator."); + return(INIT_FAILED); + } + +//--- Shortname - Dynamic 3-digit Gamma precision (%.3f) + string type = (InpSourcePrice <= PRICE_HA_CLOSE) ? " HA" : ""; + IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("Butterworth Bands%s(%d,%d,%.1f)", type, InpButterPeriod, InpPeriod, InpDeviation)); + +//--- Visuals + int draw_begin = InpPeriod; + PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, draw_begin); + PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, draw_begin); + PlotIndexSetInteger(2, PLOT_DRAW_BEGIN, 2); // Smoother warms up fast + IndicatorSetInteger(INDICATOR_DIGITS, _Digits); + + return(INIT_SUCCEEDED); + } + +//+------------------------------------------------------------------+ +//| OnDeinit | +//+------------------------------------------------------------------+ +void OnDeinit(const int reason) + { + if(CheckPointer(g_calculator) != POINTER_INVALID) + delete g_calculator; + } + +//+------------------------------------------------------------------+ +//| OnCalculate | +//+------------------------------------------------------------------+ +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(rates_total < InpPeriod) + return(0); + + if(CheckPointer(g_calculator) == POINTER_INVALID) + return(0); + +//--- Force strict chronological indexing for state-safety on input price arrays + ArraySetAsSeries(time, false); + ArraySetAsSeries(open, false); + ArraySetAsSeries(high, false); + ArraySetAsSeries(low, false); + ArraySetAsSeries(close, false); + + ENUM_APPLIED_PRICE price_type = (InpSourcePrice <= PRICE_HA_CLOSE) ? + (ENUM_APPLIED_PRICE)(-(int)InpSourcePrice) : + (ENUM_APPLIED_PRICE)InpSourcePrice; + + g_calculator.Calculate(rates_total, prev_calculated, open, high, low, close, price_type, + BufferMiddle, BufferUpper, BufferLower); + + return(rates_total); + } +//+------------------------------------------------------------------+