mirror of
https://github.com/softwaredevelop/mql5.git
synced 2026-08-22 16:58:07 +00:00
refactor: Optimized for incremental calculation + Modular architecture
This commit is contained in:
@@ -1,10 +1,9 @@
|
|||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
//| KeltnerChannel_Pro.mq5 |
|
//| KeltnerChannel_Pro.mq5 |
|
||||||
//| Copyright 2025, xxxxxxxx|
|
//| Copyright 2025, xxxxxxxx|
|
||||||
//| |
|
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
#property copyright "Copyright 2025, xxxxxxxx"
|
#property copyright "Copyright 2025, xxxxxxxx"
|
||||||
#property version "5.11" // Removed duplicate enum definition
|
#property version "5.30" // Modular architecture
|
||||||
#property description "Professional Keltner Channels with separate source selection"
|
#property description "Professional Keltner Channels with separate source selection"
|
||||||
#property description "for the Middle Line (MA) and the ATR calculation."
|
#property description "for the Middle Line (MA) and the ATR calculation."
|
||||||
|
|
||||||
@@ -109,10 +108,10 @@ void OnDeinit(const int reason)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
//| Custom indicator calculation function. |
|
//| Custom indicator calculation function |
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
int OnCalculate(const int rates_total,
|
int OnCalculate(const int rates_total,
|
||||||
const int prev_calculated,
|
const int prev_calculated, // <--- Now used!
|
||||||
const datetime &time[],
|
const datetime &time[],
|
||||||
const double &open[],
|
const double &open[],
|
||||||
const double &high[],
|
const double &high[],
|
||||||
@@ -122,21 +121,18 @@ int OnCalculate(const int rates_total,
|
|||||||
const long &volume[],
|
const long &volume[],
|
||||||
const int &spread[])
|
const int &spread[])
|
||||||
{
|
{
|
||||||
//--- Ensure the calculator object is valid
|
|
||||||
if(CheckPointer(g_calculator) == POINTER_INVALID)
|
if(CheckPointer(g_calculator) == POINTER_INVALID)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
//--- Convert our custom enum to the standard ENUM_APPLIED_PRICE
|
|
||||||
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 the entire calculation to our calculator object
|
//--- Delegate calculation with prev_calculated optimization
|
||||||
g_calculator.Calculate(rates_total, open, high, low, close, price_type, BufferMiddle, BufferUpper, BufferLower);
|
g_calculator.Calculate(rates_total, prev_calculated, open, high, low, close, price_type, BufferMiddle, BufferUpper, BufferLower);
|
||||||
|
|
||||||
//--- Return rates_total for a full recalculation, ensuring stability
|
|
||||||
return(rates_total);
|
return(rates_total);
|
||||||
}
|
}
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
|
|||||||
Reference in New Issue
Block a user