diff --git a/Indicators/MyIndicators/Vortex_Pro.mq5 b/Indicators/MyIndicators/Vortex_Pro.mq5 index 50cd7de..5e05c60 100644 --- a/Indicators/MyIndicators/Vortex_Pro.mq5 +++ b/Indicators/MyIndicators/Vortex_Pro.mq5 @@ -1,11 +1,9 @@ //+------------------------------------------------------------------+ //| Vortex_Pro.mq5 | //| Copyright 2025, xxxxxxxx| -//| | //+------------------------------------------------------------------+ #property copyright "Copyright 2025, xxxxxxxx" -#property link "" -#property version "1.00" +#property version "2.00" // Optimized for incremental calculation #property description "Vortex Indicator (VI) with selectable" #property description "candle source (Standard or Heikin Ashi)." @@ -48,11 +46,9 @@ input ENUM_CANDLE_SOURCE InpCandleSource = CANDLE_STANDARD; double BufferVI_Plus[]; double BufferVI_Minus[]; -//--- Global calculator object (as a base class pointer) --- +//--- Global calculator object --- CVortexCalculator *g_calculator; -//+------------------------------------------------------------------+ -//| Custom indicator initialization function. | //+------------------------------------------------------------------+ int OnInit() { @@ -67,7 +63,7 @@ int OnInit() g_calculator = new CVortexCalculator_HA(); IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("Vortex HA(%d)", InpPeriod)); break; - default: // CANDLE_STANDARD + default: g_calculator = new CVortexCalculator(); IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("Vortex(%d)", InpPeriod)); break; @@ -86,8 +82,6 @@ int OnInit() return(INIT_SUCCEEDED); } -//+------------------------------------------------------------------+ -//| Custom indicator deinitialization function. | //+------------------------------------------------------------------+ 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, 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, 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) 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); } //+------------------------------------------------------------------+