Problem
GetMarketTrend() is called inside isAllGood() for W1, D1, and H4 timeframes.
Since isAllGood() evaluates ~50 OBs per bar, this results in 150 CopyRates() system calls per bar
(3 timeframes × 50 OBs). Each CopyRates() allocates memory and copies rate arrays.
Solution
- Added
RefreshTrendCache() in helpers.mqh — called once per CTOB bar in ExecuteTimer
- Cache variables in
globals.mqh: g_cachedMacroTrend, g_cachedD1Trend, g_cachedH4Trend
isAllGood() in cOrderBlock.mqh now reads cached values instead of calling GetMarketTrend()
Impact
- 50× reduction in CopyRates() calls (150 → 3 per bar)
- Estimated 20-30% CPU savings in the OB evaluation loop
- Zero behavioral change — trend values don't change within the same candle
Files Changed
OBInclude/globals.mqh — added cache variables
OBInclude/helpers.mqh — added RefreshTrendCache(), call site in ExecuteTimer
OBInclude/cOrderBlock.mqh — replaced 3 GetMarketTrend() calls with cached reads
Verification
Needs a compile test + before/after backtest to confirm identical PF/trades/DD.
Problem
GetMarketTrend()is called insideisAllGood()for W1, D1, and H4 timeframes.Since
isAllGood()evaluates ~50 OBs per bar, this results in 150 CopyRates() system calls per bar(3 timeframes × 50 OBs). Each CopyRates() allocates memory and copies rate arrays.
Solution
RefreshTrendCache()inhelpers.mqh— called once per CTOB bar inExecuteTimerglobals.mqh:g_cachedMacroTrend,g_cachedD1Trend,g_cachedH4TrendisAllGood()incOrderBlock.mqhnow reads cached values instead of callingGetMarketTrend()Impact
Files Changed
OBInclude/globals.mqh— added cache variablesOBInclude/helpers.mqh— addedRefreshTrendCache(), call site inExecuteTimerOBInclude/cOrderBlock.mqh— replaced 3GetMarketTrend()calls with cached readsVerification
Needs a compile test + before/after backtest to confirm identical PF/trades/DD.