Code: Select all
Changelog: XU_EFFECT_v3.11 Optimization & Refactoring
🚀 Performance Optimizations
Bulk Data Access
Moved CopyBuffer logic for SEMA (Fast/Slow) and RSI out of the main OnCalculate loop.
Implemented bulk copying of data only for the necessary range (limit to rates_total), significantly reducing API overhead.
Fast Time Computations
Optimized IsTradingGap to check for simple "period-sized" gaps first (t2 - t1 == PeriodSeconds()). This bypasses slow TimeToStruct calls for 90%+ of candles.
Variable Caching
Replaced repetitive GetSymbolEpsilon() calls with a single global variable g_FloatEpsilon calculated once in OnInit.
Optimized Array Access
Replaced safe but slow SafeArrayGet with direct array access (buffer[i]) in inner loops where index validity is already guaranteed.
Lazy Initialization
Removed massive ArrayInitialize calls in OnInit that were zeroing out entire buffers unnecessarily.
UI Throttling
Implemented a throttle mechanism in UpdateSovereignDisplay to limit UI redraws (default: 10 FPS), preventing chart lag during high-frequency ticks.
🐛 Bug Fixes & Logic Corrections
Ternary HUD Confidence Logic
Issue: Original code (v3.08) capped confidence at 1 using MathMin because VWAP/RSI inputs were binary.
Fix: Rewrote logic to sum the agreements. Now the HUD correctly displays confidence as "1/3", "2/3", or "3/3".
"Disappearing HUD" Race Condition
Issue: HUD elements sometimes vanished when switching timeframes.
Fix: Added explicit ObjectsDeleteAll and ChartRedraw in OnInit to ensure a clean slate, plus a forced redraw in EnsureUIExists.
Invalid Historical Calculations
Issue: Original code used iClose(Symbol, Period, shift) inside the loop, which uses 0=newest indexing, while OnCalculate uses 0=oldest. This caused calculations to use future data or incorrect bars.
Fix: Refactored CalculateSEMABias and GetHybridTernaryBias to accept price as an argument, passed directly from close[i]. This is both faster and correct.
🧹 Code Structure & Cleanup
Modular Organization
Grouped related functions into labeled sections:
CORE SYSTEM
CALCULATION ENGINES
UI & DISPLAY SYSTEM
DATA MANAGEMENT
UTILITIES
Consolidated Definitions
Moved all #define macros, constants, and global variables to the top of the file for better readability.
Standardized Headers
Added consistent ASCII art headers to all function blocks for easy navigation.
Syntax Corrections
Fixed minor syntax errors (like missing function signatures) that were introduced during manual editing.