Re: 🔺 MT5 XARD - Simple Trend Following Trading System

1662
jp303 wrote: Thu Feb 19, 2026 6:36 am Hi guys, first post on here so not sure if images will load but is my MT5 playing up? Or is this normal? My m5 doesnt make any sense - The m1,m3,m4, all have the HLEMA miles away as well as 15,30m etc but on the 5m its following price much more closely.
It's because for some reason M5 is not included in period multiplication function, it starts from M4 to M1
You need to edit the mq5 file and change period.
Search for this line of code

Code: Select all

   else if(_Period <= PERIOD_M4)
   {
      EMA16Period = 336;
      Print("M4 timeframe: EMA period = ", EMA16Period);
   }
and change PERIOD_M4 to PERIOD_M5 also change "M4 timeframe..." to "M5 timeframe..."

Re: 🔺 MT5 XARD - Simple Trend Following Trading System

1664
I have made many changes, so please treat this code as untested. Xard needs to check if everything works as he would like it to.

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.

Re: 🔺 MT5 XARD - Simple Trend Following Trading System

1665
budhi1976 wrote: Thu Feb 19, 2026 4:32 pm It's because for some reason M5 is not included in period multiplication function, it starts from M4 to M1
You need to edit the mq5 file and change period.
Search for this line of code

Code: Select all

   else if(_Period <= PERIOD_M4)
   {
      EMA16Period = 336;
      Print("M4 timeframe: EMA period = ", EMA16Period);
   }
and change PERIOD_M4 to PERIOD_M5 also change "M4 timeframe..." to "M5 timeframe..."
Thats great, thanks. I must have missed this if it was previously mentioned. This is a huge help!


Re: 🔺 MT5 XARD - Simple Trend Following Trading System

1669
Lenovo wrote: Thu Feb 19, 2026 8:28 pm Hello tech-savvy friends, could you add a
countdown where I have circled in red? It would be useful, because due to the size of my monitor, I can't keep the right-hand panel visible.
To be honest, I have no idea what your problem is, but I added an auto-scaling option that should work if you have a 4K monitor. This will upscale HUD (auto works only above 3000 pixels)and if you have a small monitor, reduce the scaling to 0.8 or less.
OK, that's enough changes for today. Xard needs to review and evaluate them, adjust the ATR for Forex, and integrate all the options if he wants to, of course.