refactor: Simplified Price Source Selection

This commit is contained in:
Toh4iem9
2025-12-21 16:50:43 +01:00
parent ae4b0c81e3
commit 7784991066
@@ -3,7 +3,7 @@
//| Copyright 2025, xxxxxxxx| //| Copyright 2025, xxxxxxxx|
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
#property copyright "Copyright 2025, xxxxxxxx" #property copyright "Copyright 2025, xxxxxxxx"
#property version "1.10" // Optimized for incremental calculation #property version "1.20" // Simplified Price Source Selection
#property description "Ehlers' Smoother (Super/Ultimate) applied to Momentum (Close-Open)." #property description "Ehlers' Smoother (Super/Ultimate) applied to Momentum (Close-Open)."
#property indicator_separate_window #property indicator_separate_window
@@ -16,22 +16,22 @@
#property indicator_width1 1 #property indicator_width1 1
#property indicator_level1 0.0 #property indicator_level1 0.0
#property indicator_levelstyle STYLE_SOLID #property indicator_levelstyle STYLE_DOT
#property indicator_levelcolor clrGray
#include <MyIncludes\Ehlers_Smoother_Calculator.mqh> #include <MyIncludes\Ehlers_Smoother_Calculator.mqh>
//--- Restored Enum for clarity --- //--- Enum for selecting the candle source for calculation ---
enum ENUM_CANDLE_SOURCE enum ENUM_CANDLE_SOURCE
{ {
SOURCE_STD, // Standard Candles CANDLE_STANDARD, // Use standard OHLC data
SOURCE_HA // Heikin Ashi Candles CANDLE_HEIKIN_ASHI // Use Heikin Ashi smoothed data
}; };
//--- Input Parameters --- //--- Input Parameters ---
input ENUM_SMOOTHER_TYPE InpSmootherType = SUPERSMOOTHER; input ENUM_SMOOTHER_TYPE InpSmootherType = SUPERSMOOTHER;
input int InpPeriod = 20; input int InpPeriod = 20;
input ENUM_CANDLE_SOURCE InpCandleSource = SOURCE_STD; // UPDATED: Use simplified candle source selection
input ENUM_CANDLE_SOURCE InpCandleSource = CANDLE_STANDARD;
//--- Indicator Buffers --- //--- Indicator Buffers ---
double BufferMomentum[]; double BufferMomentum[];
@@ -47,7 +47,8 @@ int OnInit()
string name = (InpSmootherType == SUPERSMOOTHER) ? "SS-Mom" : "US-Mom"; string name = (InpSmootherType == SUPERSMOOTHER) ? "SS-Mom" : "US-Mom";
if(InpCandleSource == SOURCE_HA) // Determine HA usage based on simplified enum
if(InpCandleSource == CANDLE_HEIKIN_ASHI)
{ {
g_calculator = new CEhlersSmootherCalculator_HA(); g_calculator = new CEhlersSmootherCalculator_HA();
IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("%s HA(%d)", name, InpPeriod)); IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("%s HA(%d)", name, InpPeriod));
@@ -80,7 +81,7 @@ void OnDeinit(const int reason)
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
int OnCalculate(const int rates_total, int OnCalculate(const int rates_total,
const int prev_calculated, // <--- Now used! const int prev_calculated,
const datetime &time[], const datetime &time[],
const double &open[], const double &open[],
const double &high[], const double &high[],
@@ -93,11 +94,12 @@ int OnCalculate(const int rates_total,
if(CheckPointer(g_calculator) == POINTER_INVALID) if(CheckPointer(g_calculator) == POINTER_INVALID)
return 0; return 0;
//--- Delegate calculation with prev_calculated optimization // We pass PRICE_CLOSE as a dummy because in SOURCE_MOMENTUM mode,
//--- We pass PRICE_CLOSE as a dummy value because in SOURCE_MOMENTUM mode, // the calculator ignores price_type and calculates (Close - Open) internally.
//--- the calculator ignores price_type and calculates (Close - Open) internally. // The HA switching is handled by the object type (CEhlersSmootherCalculator_HA).
g_calculator.Calculate(rates_total, prev_calculated, PRICE_CLOSE, open, high, low, close, BufferMomentum); g_calculator.Calculate(rates_total, prev_calculated, PRICE_CLOSE, open, high, low, close, BufferMomentum);
return(rates_total); return(rates_total);
} }
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
//+------------------------------------------------------------------+