refactor: Optimized for incremental calculation + Fixed display mode bug

This commit is contained in:
Toh4iem9
2025-11-30 13:29:06 +01:00
parent a7d9f8d2be
commit a5ad9f1c95
+28 -18
View File
@@ -1,10 +1,9 @@
//+------------------------------------------------------------------+
//| RSI_Pro.mq5 |
//| Copyright 2025, xxxxxxxx|
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, xxxxxxxx"
#property version "3.10"
#property version "3.21" // Fixed display mode bug
#property description "A professional, unified RSI with selectable price source (incl. Heikin Ashi),"
#property description "a flexible MA signal line, and optional Bollinger Bands."
@@ -119,9 +118,18 @@ 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,
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)
{
@@ -131,24 +139,26 @@ int OnCalculate(const int rates_total, const int, const datetime&[], const doubl
else
price_type = (ENUM_APPLIED_PRICE)InpSourcePrice;
g_calculator.Calculate(rates_total, price_type, open, high, low, close,
//--- Delegate calculation (Calculates ALL buffers)
g_calculator.Calculate(rates_total, prev_calculated, price_type, open, high, low, close,
BufferRSI, BufferSignalMA, BufferUpperBand, BufferLowerBand);
for(int i = 0; i < rates_total; i++)
//--- FIX: Force hide unused buffers for the ENTIRE history
//--- Since the calculator fills them all, we must clear what we don't want to see.
//--- Clearing a double array is very fast, so we do it from 0.
if(InpDisplayMode == DISPLAY_RSI_ONLY)
{
if(InpDisplayMode == DISPLAY_RSI_ONLY)
{
BufferSignalMA[i] = EMPTY_VALUE;
BufferUpperBand[i] = EMPTY_VALUE;
BufferLowerBand[i] = EMPTY_VALUE;
}
else
if(InpDisplayMode == DISPLAY_RSI_AND_MA)
{
BufferUpperBand[i] = EMPTY_VALUE;
BufferLowerBand[i] = EMPTY_VALUE;
}
ArrayInitialize(BufferSignalMA, EMPTY_VALUE);
ArrayInitialize(BufferUpperBand, EMPTY_VALUE);
ArrayInitialize(BufferLowerBand, EMPTY_VALUE);
}
else
if(InpDisplayMode == DISPLAY_RSI_AND_MA)
{
ArrayInitialize(BufferUpperBand, EMPTY_VALUE);
ArrayInitialize(BufferLowerBand, EMPTY_VALUE);
}
}
return(rates_total);
}