mirror of
https://github.com/softwaredevelop/mql5.git
synced 2026-07-27 20:47:44 +00:00
refactor: Optimized for incremental calculation
This commit is contained in:
@@ -1,11 +1,9 @@
|
|||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
//| LinearRegression_Pro.mq5 |
|
//| LinearRegression_Pro.mq5 |
|
||||||
//| Copyright 2025, xxxxxxxx|
|
//| Copyright 2025, xxxxxxxx|
|
||||||
//| |
|
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
#property copyright "Copyright 2025, xxxxxxxx"
|
#property copyright "Copyright 2025, xxxxxxxx"
|
||||||
#property link ""
|
#property version "2.10" // Optimized for incremental calculation
|
||||||
#property version "2.00"
|
|
||||||
#property description "Professional, manually calculated Linear Regression Channel with"
|
#property description "Professional, manually calculated Linear Regression Channel with"
|
||||||
#property description "selectable price source (Standard and Heikin Ashi)."
|
#property description "selectable price source (Standard and Heikin Ashi)."
|
||||||
|
|
||||||
@@ -98,7 +96,7 @@ void OnDeinit(const int reason)
|
|||||||
//| Linear Regression Channel calculation function. |
|
//| Linear Regression Channel 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[],
|
||||||
@@ -108,25 +106,17 @@ int OnCalculate(const int rates_total,
|
|||||||
const long &volume[],
|
const long &volume[],
|
||||||
const int &spread[])
|
const int &spread[])
|
||||||
{
|
{
|
||||||
if(rates_total < InpRegressionPeriod || CheckPointer(g_calculator) == POINTER_INVALID)
|
if(CheckPointer(g_calculator) == POINTER_INVALID)
|
||||||
return(0);
|
return 0;
|
||||||
|
|
||||||
if(time[rates_total - 1] > g_last_update_time)
|
ENUM_APPLIED_PRICE price_type;
|
||||||
{
|
if(InpSourcePrice <= PRICE_HA_CLOSE)
|
||||||
ArrayInitialize(BufferUpper, EMPTY_VALUE);
|
price_type = (ENUM_APPLIED_PRICE)(-(int)InpSourcePrice);
|
||||||
ArrayInitialize(BufferLower, EMPTY_VALUE);
|
else
|
||||||
ArrayInitialize(BufferMiddle, EMPTY_VALUE);
|
price_type = (ENUM_APPLIED_PRICE)InpSourcePrice;
|
||||||
|
|
||||||
ENUM_APPLIED_PRICE price_type;
|
//--- Delegate calculation with prev_calculated optimization
|
||||||
if(InpSourcePrice <= PRICE_HA_CLOSE)
|
g_calculator.Calculate(rates_total, prev_calculated, open, high, low, close, price_type, BufferMiddle, BufferUpper, BufferLower);
|
||||||
price_type = (ENUM_APPLIED_PRICE)(-(int)InpSourcePrice);
|
|
||||||
else
|
|
||||||
price_type = (ENUM_APPLIED_PRICE)InpSourcePrice;
|
|
||||||
|
|
||||||
g_calculator.Calculate(rates_total, open, high, low, close, price_type, BufferMiddle, BufferUpper, BufferLower);
|
|
||||||
|
|
||||||
g_last_update_time = time[rates_total - 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
return(rates_total);
|
return(rates_total);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user