mirror of
https://github.com/softwaredevelop/mql5.git
synced 2026-08-16 22:08:07 +00:00
refactor: Upgraded with strict chronological sorting safeguards and pointer guards
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
//| Butterworth_Filter_Pro.mq5 |
|
//| Butterworth_Filter_Pro.mq5 |
|
||||||
//| Copyright 2025, xxxxxxxx|
|
//| Copyright 2026, xxxxxxxx|
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
#property copyright "Copyright 2025, xxxxxxxx"
|
#property copyright "Copyright 2026, xxxxxxxx"
|
||||||
#property version "2.00" // Optimized for incremental calculation
|
#property version "2.10" // Upgraded with strict chronological sorting safeguards and pointer guards
|
||||||
#property description "John Ehlers' Higher-Order Butterworth Filter."
|
#property description "John Ehlers' Higher-Order Butterworth Filter."
|
||||||
|
|
||||||
#property indicator_chart_window
|
#property indicator_chart_window
|
||||||
@@ -18,9 +18,10 @@
|
|||||||
#include <MyIncludes\Butterworth_Calculator.mqh>
|
#include <MyIncludes\Butterworth_Calculator.mqh>
|
||||||
|
|
||||||
//--- Input Parameters ---
|
//--- Input Parameters ---
|
||||||
input int InpPeriod = 20; // Critical Period for the filter
|
input group "Butterworth Settings"
|
||||||
input ENUM_BUTTERWORTH_POLES InpPoles = POLES_TWO; // Number of poles (2 or 3)
|
input int InpPeriod = 20; // Critical Period
|
||||||
input ENUM_APPLIED_PRICE_HA_ALL InpSourcePrice = PRICE_CLOSE_STD;
|
input ENUM_BUTTERWORTH_POLES InpPoles = POLES_TWO; // Number of poles (2 or 3)
|
||||||
|
input ENUM_APPLIED_PRICE_HA_ALL InpSourcePrice = PRICE_CLOSE_STD; // Price Source
|
||||||
|
|
||||||
//--- Indicator Buffers ---
|
//--- Indicator Buffers ---
|
||||||
double BufferFilter[];
|
double BufferFilter[];
|
||||||
@@ -64,6 +65,8 @@ void OnDeinit(const int reason)
|
|||||||
delete g_calculator;
|
delete g_calculator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
|
//| Custom indicator calculation function |
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
int OnCalculate(const int rates_total,
|
int OnCalculate(const int rates_total,
|
||||||
const int prev_calculated,
|
const int prev_calculated,
|
||||||
@@ -76,17 +79,28 @@ int OnCalculate(const int rates_total,
|
|||||||
const long &volume[],
|
const long &volume[],
|
||||||
const int &spread[])
|
const int &spread[])
|
||||||
{
|
{
|
||||||
|
if(rates_total < 4)
|
||||||
|
return 0;
|
||||||
|
|
||||||
if(CheckPointer(g_calculator) == POINTER_INVALID)
|
if(CheckPointer(g_calculator) == POINTER_INVALID)
|
||||||
return 0;
|
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;
|
ENUM_APPLIED_PRICE price_type;
|
||||||
if(InpSourcePrice <= PRICE_HA_CLOSE)
|
if(InpSourcePrice <= PRICE_HA_CLOSE)
|
||||||
price_type = (ENUM_APPLIED_PRICE)(-(int)InpSourcePrice);
|
price_type = (ENUM_APPLIED_PRICE)(-(int)InpSourcePrice);
|
||||||
else
|
else
|
||||||
price_type = (ENUM_APPLIED_PRICE)InpSourcePrice;
|
price_type = (ENUM_APPLIED_PRICE)InpSourcePrice;
|
||||||
|
|
||||||
|
//--- Delegate calculation with prev_calculated optimization
|
||||||
g_calculator.Calculate(rates_total, prev_calculated, price_type, open, high, low, close, BufferFilter);
|
g_calculator.Calculate(rates_total, prev_calculated, price_type, open, high, low, close, BufferFilter);
|
||||||
|
|
||||||
return(rates_total);
|
return(rates_total);
|
||||||
}
|
}
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
//+------------------------------------------------------------------+
|
|
||||||
|
|||||||
Reference in New Issue
Block a user