mirror of
https://github.com/softwaredevelop/mql5.git
synced 2026-08-22 00:38:07 +00:00
refactor: Optimized for incremental calculation
This commit is contained in:
@@ -1,10 +1,9 @@
|
|||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
//| Bollinger_Bands_Pro.mq5 |
|
//| Bollinger_Bands_Pro.mq5 |
|
||||||
//| Copyright 2025, xxxxxxxx|
|
//| Copyright 2025, xxxxxxxx|
|
||||||
//| |
|
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
#property copyright "Copyright 2025, xxxxxxxx"
|
#property copyright "Copyright 2025, xxxxxxxx"
|
||||||
#property version "1.00"
|
#property version "1.10" // Optimized for incremental calculation
|
||||||
#property description "A professional, unified Bollinger Bands indicator with a selectable"
|
#property description "A professional, unified Bollinger Bands indicator with a selectable"
|
||||||
#property description "price source, including a full range of Heikin Ashi prices."
|
#property description "price source, including a full range of Heikin Ashi prices."
|
||||||
|
|
||||||
@@ -96,20 +95,29 @@ void OnDeinit(const int reason)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
//| Custom indicator iteration function. |
|
//| Custom indicator calculation function |
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
int OnCalculate(const int rates_total, const int, const datetime&[], const double &open[], const double &high[], const double &low[], const double &close[], const long&[], const long&[], const int&[])
|
int OnCalculate(const int rates_total,
|
||||||
|
const int prev_calculated, // <--- Now used!
|
||||||
|
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(CheckPointer(g_calculator) != POINTER_INVALID)
|
if(CheckPointer(g_calculator) != POINTER_INVALID)
|
||||||
{
|
{
|
||||||
//--- Convert our custom enum back to a standard ENUM_APPLIED_PRICE for the calculator
|
|
||||||
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); // Convert -1 to 1 (CLOSE), -2 to 2 (OPEN) etc.
|
price_type = (ENUM_APPLIED_PRICE)(-(int)InpSourcePrice);
|
||||||
else
|
else
|
||||||
price_type = (ENUM_APPLIED_PRICE)InpSourcePrice;
|
price_type = (ENUM_APPLIED_PRICE)InpSourcePrice;
|
||||||
|
|
||||||
g_calculator.Calculate(rates_total, price_type, open, high, low, close,
|
//--- Delegate calculation with prev_calculated optimization
|
||||||
|
g_calculator.Calculate(rates_total, prev_calculated, price_type, open, high, low, close,
|
||||||
BufferCenterLine, BufferUpperBand, BufferLowerBand);
|
BufferCenterLine, BufferUpperBand, BufferLowerBand);
|
||||||
}
|
}
|
||||||
return(rates_total);
|
return(rates_total);
|
||||||
|
|||||||
Reference in New Issue
Block a user