ENGINE BLUEPRINT — VERSION 2.0 (WORD-SAFE CODE FORMAT) (Copy/paste directly into Word — formatting preserved) ENGINE BLUEPRINT — WORDSAFE CODE FORMAT VERSION: 2.0 AUTHOR: Anthony DATE: May 2026 TITLE: MULTI-ENGINE TREND SYSTEM — ENGINE BLUEPRINT FORMAT: WORD-SAFE (NO MARKDOWN, NO CODE FENCES) SECTION 1 — OVERVIEW This document defines the code-level blueprint for the TrendEngine (per-symbol engine) and PortfolioController (central risk brain). It is designed for direct implementation in MQL5 (MT5), but the logic is platform-agnostic. Includes: • Class structures • Method responsibilities • Pseudocode for all major functions • Volatility-regime logic • Dual-timeframe confirmation • Micropyramiding • Risk-weighted satellites • Portfolio-level controls • Monitoring hooks • Error-handling patterns SECTION 2 — FILE STRUCTURE EngineBase.mqh TrendEngine.mqh PortfolioController.mqh Config.mqh Monitoring.mqh MainEA.mq5 SECTION 3 — TRENDENGINE CLASS (PER SYMBOL) Class Name: TrendEngine Engine Instances: Core: GER40 or US500 or NAS100, XAUUSD Satellites: XAGUSD, COPPER, OIL, PLATINUM, NATGAS, BTCUSD 3.1 CLASS PROPERTIES symbol tf_exec tf_conf trendFilterLen atrPeriod atrEntryMult atrStopMult volLowThr volMedThr volHighThr volExtremeThr maxRiskPerTrade riskWeight maxPyramidAdds pyramidAddR atr trendFilter volRegime inPosition positionDir entryPrice stopPrice currentR pyramidCount portfolio (pointer) monitor (pointer) activationDelayPassed SECTION 4 — ENGINE EVENT FLOW OnBar(): UpdateIndicators() If SessionAllowed() == false → return ClassifyVolatility() If volRegime == CHAOTIC → return If activationDelayPassed == false → return If inPosition: UpdateStops() HandlePyramiding() return TryEnter() SECTION 5 — INDICATOR UPDATES UpdateIndicators(): atr = ATR(symbol, tf_exec, atrPeriod) trendFilter = MA(symbol, tf_conf, trendFilterLen) SECTION 6 — VOLATILITY CLASSIFICATION ClassifyVolatility(): atrPct = atr / Close(symbol) * 100 If atrPct > volExtremeThr → volRegime = CHAOTIC Else if atrPct > volHighThr → volRegime = HIGH Else if atrPct > volMedThr → volRegime = MEDIUM Else → volRegime = LOW SECTION 7 — ENTRY LOGIC TryEnter(): recentHigh = HighestHigh(N) recentLow = LowestLow(N) closeExec = Close(tf_exec) closeConf = Close(tf_conf) upTrend = closeConf > trendFilter downTrend = closeConf < trendFilter longBreakout = closeExec > recentHigh + atr * atrEntryMult shortBreakout = closeExec < recentLow - atr * atrEntryMult If longBreakout AND upTrend: If portfolio.CanOpenTrade(this, +1): OpenTrade(+1) return If shortBreakout AND downTrend: If portfolio.CanOpenTrade(this, -1): OpenTrade(-1) return SECTION 8 — POSITION SIZING AND TRADE EXECUTION OpenTrade(direction): equity = AccountEquity() riskAmount = equity * maxRiskPerTrade * riskWeight stopDist = atr * atrStopMult lotSize = riskAmount / (stopDist * TickValue(symbol)) lotSize = NormalizeLotSize(lotSize) price = Ask or Bid depending on direction If CheckSpreadAndSlippage() == false → return If SendOrder(symbol, direction, lotSize, price, stopDist) == false → return inPosition = true positionDir = direction entryPrice = price stopPrice = price - stopDist (long) or price + stopDist (short) pyramidCount = 0 currentR = 1.0 SECTION 9 — STOP MANAGEMENT UpdateStops(): If positionDir == long: trailBase = Close(tf_exec) - atr * atrStopMult newStop = max(stopPrice, trailBase) Else: trailBase = Close(tf_exec) + atr * atrStopMult newStop = min(stopPrice, trailBase) If newStop != stopPrice: ModifyStop(symbol, newStop) stopPrice = newStop SECTION 10 — MICROPYRAMIDING HandlePyramiding(): If pyramidCount >= maxPyramidAdds → return currentPrice = Close(tf_exec) // For long; mirrored for short in implementation openR = (currentPrice - entryPrice) / (entryPrice - stopPrice) If openR < 1.0 → return If volRegime == HIGH or CHAOTIC → return trendStrength = CalcTrendStrength() If trendStrength < threshold → return If portfolio.CanPyramid(this) == false → return AddPyramidPosition() AddPyramidPosition(): equity = AccountEquity() riskAmount = equity * maxRiskPerTrade * riskWeight * pyramidAddR stopDist = abs(Close(tf_exec) - stopPrice) lotSize = riskAmount / (stopDist * TickValue(symbol)) lotSize = NormalizeLotSize(lotSize) price = Ask or Bid If CheckSpreadAndSlippage() == false → return If SendOrder(...) == false → return pyramidCount++ SECTION 11 — PORTFOLIO CONTROLLER Class Name: PortfolioController Responsibilities: • Enforce 60/40 core/satellite risk split • Enforce max portfolio risk • Enforce exposure caps • Correlation management • Volatility-regime management • Risk-off mode • Capital scaling • Satellite activation delay • One-trade-per-instrument rule 11.1 CANOPENTRADE() CanOpenTrade(engine, direction): If riskOffState == ON AND engine is satellite → return false If engine.activationDelayPassed == false → return false If ExposureLimitReached(engine) → return false If OneTradePerInstrumentViolated(engine) → return false currentR = CalcTotalRAtRisk() newR = engine.EstimateRForNewTrade() If currentR + newR > maxPortfolioRisk * globalRiskMult → return false If Check60_40Split(engine, newR) == false → return false return true 11.2 60/40 ENFORCEMENT Check60_40Split(engine, newR): coreR = CalcCoreRAtRisk() satR = CalcSatelliteRAtRisk() If engine is core: return (coreR + newR) <= maxPortfolioRisk * 0.60 * globalRiskMult Else: return (satR + newR) <= maxPortfolioRisk * 0.40 * globalRiskMult 11.3 RISK-OFF MODE UpdateRiskState(): dd = CalcPortfolioDrawdown() If dd > threshold AND riskOffState == OFF: riskOffState = ON PauseSatellites() ReduceCoreRisk() If dd < recoveryThreshold AND riskOffState == ON: riskOffState = OFF ResumeSatellites() RestoreCoreRisk() 11.4 CAPITAL SCALING UpdateRiskScaling(): equity = AccountEquity() If equity > highWatermark * 1.20: globalRiskMult *= 1.10 highWatermark = equity dd = CalcPortfolioDrawdown() If dd > 0.10: globalRiskMult *= 0.90 SECTION 12 — MONITORING HOOKS Engine exposes: symbol inPosition positionDir currentR atr volRegime pyramidCount engineDrawdown activationDelayPassed lastError lastSignal Portfolio exposes: totalRAtRisk totalExposure portfolioDrawdown riskOffState globalRiskMult correlationMatrix volatilityRegime Execution exposes: slippage spread orderRejectRate latency SECTION 13 — ERROR HANDLING PATTERN SafeSendOrder(): For i from 1 to MAX_RETRIES: If TrySendOrder() == true → return true Sleep(RETRY_DELAY) LogError("Order failed after retries") PauseEngine() return false END OF ENGINE BLUEPRINT — VERSION 2.0