mirror of
https://github.com/softwaredevelop/mql5.git
synced 2026-08-21 16:28:06 +00:00
refactor(indicators): Optimized for incremental calculation
This commit is contained in:
@@ -1,11 +1,9 @@
|
|||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
//| Vortex_Pro.mq5 |
|
//| Vortex_Pro.mq5 |
|
||||||
//| Copyright 2025, xxxxxxxx|
|
//| Copyright 2025, xxxxxxxx|
|
||||||
//| |
|
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
#property copyright "Copyright 2025, xxxxxxxx"
|
#property copyright "Copyright 2025, xxxxxxxx"
|
||||||
#property link ""
|
#property version "2.00" // Optimized for incremental calculation
|
||||||
#property version "1.00"
|
|
||||||
#property description "Vortex Indicator (VI) with selectable"
|
#property description "Vortex Indicator (VI) with selectable"
|
||||||
#property description "candle source (Standard or Heikin Ashi)."
|
#property description "candle source (Standard or Heikin Ashi)."
|
||||||
|
|
||||||
@@ -48,11 +46,9 @@ input ENUM_CANDLE_SOURCE InpCandleSource = CANDLE_STANDARD;
|
|||||||
double BufferVI_Plus[];
|
double BufferVI_Plus[];
|
||||||
double BufferVI_Minus[];
|
double BufferVI_Minus[];
|
||||||
|
|
||||||
//--- Global calculator object (as a base class pointer) ---
|
//--- Global calculator object ---
|
||||||
CVortexCalculator *g_calculator;
|
CVortexCalculator *g_calculator;
|
||||||
|
|
||||||
//+------------------------------------------------------------------+
|
|
||||||
//| Custom indicator initialization function. |
|
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
int OnInit()
|
int OnInit()
|
||||||
{
|
{
|
||||||
@@ -67,7 +63,7 @@ int OnInit()
|
|||||||
g_calculator = new CVortexCalculator_HA();
|
g_calculator = new CVortexCalculator_HA();
|
||||||
IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("Vortex HA(%d)", InpPeriod));
|
IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("Vortex HA(%d)", InpPeriod));
|
||||||
break;
|
break;
|
||||||
default: // CANDLE_STANDARD
|
default:
|
||||||
g_calculator = new CVortexCalculator();
|
g_calculator = new CVortexCalculator();
|
||||||
IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("Vortex(%d)", InpPeriod));
|
IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("Vortex(%d)", InpPeriod));
|
||||||
break;
|
break;
|
||||||
@@ -86,8 +82,6 @@ int OnInit()
|
|||||||
return(INIT_SUCCEEDED);
|
return(INIT_SUCCEEDED);
|
||||||
}
|
}
|
||||||
|
|
||||||
//+------------------------------------------------------------------+
|
|
||||||
//| Custom indicator deinitialization function. |
|
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
void OnDeinit(const int reason)
|
void OnDeinit(const int reason)
|
||||||
{
|
{
|
||||||
@@ -96,13 +90,14 @@ void OnDeinit(const int reason)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
//| Custom indicator calculation function. |
|
int OnCalculate(const int rates_total, const int prev_calculated, 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, const datetime&[], const double &open[], const double &high[], const double &low[], const double &close[], const long&[], const long&[], const int&[])
|
|
||||||
{
|
{
|
||||||
if(CheckPointer(g_calculator) == POINTER_INVALID)
|
if(CheckPointer(g_calculator) == POINTER_INVALID)
|
||||||
return 0;
|
return 0;
|
||||||
g_calculator.Calculate(rates_total, open, high, low, close, BufferVI_Plus, BufferVI_Minus);
|
|
||||||
|
// Delegate calculation with incremental optimization
|
||||||
|
g_calculator.Calculate(rates_total, prev_calculated, open, high, low, close, BufferVI_Plus, BufferVI_Minus);
|
||||||
|
|
||||||
return(rates_total);
|
return(rates_total);
|
||||||
}
|
}
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
|
|||||||
Reference in New Issue
Block a user