Strategies — Detailed Algorithm Descriptions

3. Strategies — Detailed Algorithm Descriptions

3.1 Smart DI (Directional Index)

Concept: Measures the dominance of one market direction using the ADX indicator, analysing the difference between the DI+ and DI- lines.

Algorithm — step by step:

  1. Fetches DI+ and DI- values from ADX (buffer 1 — the previous closed bar, to avoid repainting)
  2. Calculates diff = |DI+ - DI-|
  3. Fetches data for the last closed candle on Inp_Strat_TF
  4. Calculates candle body size: body = |close - open| / _Point
  5. If Impulse/Muzzle Mode is active: the minimum candle body requirement rises from Inp_Strat_Min_Candle_Body to Inp_Muzzle_Min_Candle_Body (default 150 pts instead of 2 pts) — the strategy’s characteristics change during an impulse
  6. BUY signal: DI+ > DI- AND diff > Min_DI_Diff AND DI- < Max_Opposite_DI
  7. SELL signal: DI- > DI+ AND diff > Min_DI_Diff AND DI+ < Max_Opposite_DI

Log: "Smart DI BUY" / "Smart DI SELL"

Key property: The Inp_Strat_Max_Opposite_DI parameter limits opposition strength — even when DI+ dominates, an overly strong DI- blocks the signal. It acts as a built-in trend quality filter.

3.2 MTF Point System (Multi-TimeFrame)

Concept: Scores trend alignment across 4 independent timeframes using EMA5/EMA7 crossovers. Each timeframe earns one point; a minimum score threshold is required.

Algorithm — step by step:

  1. On each of the 4 timeframes (TF1, TF2, TF3, TF4), fetches EMA5 and EMA7
  2. BUY point: EMA5 > EMA7 on that TF → score++
  3. SELL point: EMA5 < EMA7 on that TF → score++
  4. If score >= Inp_MTF_Min_Score (default 3 out of 4) → signal is active

Check condition: On every new bar of Inp_MTF_TF1 (the fastest TF)

Log: "MTF BUY" / "MTF SELL"

Philosophy: The system does not require perfect alignment — even 3 out of 4 timeframes is sufficient. This provides flexibility in fluid markets where all timeframes rarely agree simultaneously.

3.3 Three Consecutive Candles

Concept: Detects a mini-trend: 3 consecutive closed candles in the same direction with a minimum body size.

Algorithm — step by step:

  1. Fetches the last 3 closed candles on Inp_Filter_3Candles_TF
  2. For each candle: body = |close - open| / _Point
  3. If any candle’s body < Inp_Filter_3Candles_MinBody → signal is invalid
  4. BUY: all 3 candles are bullish (close > open)
  5. SELL: all 3 candles are bearish (close < open)

Log: "3 Candles BUY" / "3 Candles SELL"

Strength: Simple, visually intuitive, and highly effective as a validator — it confirms momentum before Smart DI or MTF fire their signals.

Multi-Core Strategy Engine — „First Come, First Served”

2. Multi-Core Strategy Engine — „First Come, First Served”

This is the system’s most important architectural innovation. Despite the name suggesting a single strategy, AHS is a strategy engine with interchangeable cores, where each strategy can simultaneously fulfil two roles:

RoleParameterDescription
Trigger_As_Strategy = trueThe strategy GENERATES the trade signal
Validator_As_Filter = trueThe strategy CONFIRMS signals from other strategies

The „First Come, First Served” Rule

Strategies are evaluated sequentially in a fixed order:

EvaluateStrategies()
  1. Smart DI (if As_Strategy=true)       → signal? → filters → order → RETURN
  2. MTF Point System (if As_Strategy=true) → signal? → filters → order → RETURN
  3. 3 Consecutive Candles (if As_Strategy=true) → signal? → filters → order → RETURN

Critical implication: When strategy #1 (Smart DI) generates a valid signal and passes all filters, the system immediately opens an order and exits the function (return). Strategies 2 and 3 are never evaluated on that tick. There is no voting, averaging or consensus — the first valid signal wins.

Each strategy is checked only once per new bar (on its own timeframe), which eliminates multiple signals within the same candle.

Configuration Possibilities

  • SmartDI as trigger, MTF + 3Candles as filters — SmartDI fires the signal, but it must be confirmed by both other systems
  • All three as triggers — three independent strategies compete to open a trade
  • MTF as trigger, SmartDI as filter — MTF generates, SmartDI confirms
  • Any combination — each strategy can be independently enabled/disabled in either role

A Validator Does Not Validate Itself

Smart logic: strategy X acting as a filter does NOT validate its own signals. Example: if SmartDI is the trigger, the SmartDI filter is skipped (it does not check itself) — only MTF and 3Candles filters are checked.

// Validator skips its own source
if (Inp_SmartDI_As_Filter && trigger_source != "SmartDI") {
    if (!CheckSmartDI_Condition(is_buy)) return false;
}

Architecture & Module Connections

1. Architecture & Module Connections

The system is composed of five header files included into the compiled main file _AHS_Main.ex5:

_AHS_Main.ex5
  ├── AHS_Inputs.mqh      → All input parameters, enumerations, global state variables
  ├── AHS_Filters.mqh     → Market filters (The Shield): Macro Matrix, Impulse, Channel, ADX/MA, SmartDI, MTF, 3Candles
  ├── AHS_Strategy.mqh    → Multi-Core Engine: position sizing, order execution
  ├── AHS_Management.mqh  → Position management: TSL BB, Hard BE, Neg BE, Dynamic TP, EOD Terminator
  └── AHS_Panel.mqh       → Graphical information panel: status, MTF dashboard, positions list

OnTick() Flow — Step by Step

Every incoming tick passes through a strictly defined sequence in the main loop:

OnTick()
  1.  License check (CLicenseManager.IsExpired)
  2.  Session schedule check (IsScheduleAllowed)
  3.  EOD Terminator (CheckForEODClose) → emergency close all positions
  4.  Daily P/L update and daily reset
  5.  Account Protection checks:
        → DailyLossReached?    → block new orders
        → DrawdownFreeze?      → block new orders
        → DailyTargetReached?  → block new orders
  6.  Equity Trailing Lock (master equity trailing SL)
  7.  Institutional Impulse Detection (CheckInstitutionalImpulse)
  8.  Dynamic Channel Update (UpdateDynamicChannel) every X hours
  9.  News Filter → freeze before/after news events
 10.  ManageAllPositions() → manage all open positions
 11.  Cooldown check + position count limit check
 12.  EvaluateStrategies() → Multi-Core Engine searches for a signal
 13.  Information panel update

All stages are independent — position management (step 10) runs regardless of whether new signals are being sought (step 12). Even when new orders are blocked, open positions are always managed.

Architektura i powiązania modułów

1. Architektura i powiązania modułów

System składa się z pięciu plików nagłówkowych dołączanych do skompilowanego pliku głównego _AHS_Main.ex5:

_AHS_Main.ex5
  ├── AHS_Inputs.mqh      → Wszystkie parametry wejściowe, enumeracje, zmienne globalne stanu
  ├── AHS_Filters.mqh     → Filtry rynkowe (The Shield): Macro Matrix, Impulse, Channel, ADX/MA, Smart DI, MTF, 3Candles
  ├── AHS_Strategy.mqh    → Multi-Core Engine: kalkulacja wielkości pozycji, wykonanie zlecenia
  ├── AHS_Management.mqh  → Zarządzanie pozycjami: TSL BB, Hard BE, Neg BE, Dynamic TP, EOD Terminator
  └── AHS_Panel.mqh       → Graficzny panel informacyjny: status, MTF dashboard, lista pozycji

Przepływ OnTick() — krok po kroku

Każdy napływający tick przez główną pętlę EA przechodzi przez ściśle określoną sekwencję:

OnTick()
  1. Sprawdzenie licencji (CLicenseManager.IsExpired)
  2. Sprawdzenie harmonogramu sesji (IsScheduleAllowed)
  3. EOD Terminator (CheckForEODClose) → awaryjne zamknięcie wszystkich pozycji
  4. Aktualizacja dziennego P/L i reset dzienny
  5. Sprawdzenie Account Protection:
       → DailyLossReached? → blokada nowych zleceń
       → DrawdownFreeze?   → blokada nowych zleceń
       → DailyTargetReached? → blokada nowych zleceń
  6. Equity Trailing Lock (master equity trailing SL)
  7. Institutional Impulse Detection (CheckInstitutionalImpulse)
  8. Dynamic Channel Update (UpdateDynamicChannel) co X godzin
  9. News Filter → blokada przed/po newsach
 10. ManageAllPositions() → zarządzanie wszystkimi otwartymi pozycjami
 11. Sprawdzenie warunku cooldown + limitu pozycji
 12. EvaluateStrategies() → Multi-Core Engine szuka sygnału
 13. Aktualizacja panelu informacyjnego

Wszystkie etapy są niezależne — zarządzanie pozycjami (krok 10) działa niezależnie od wyszukiwania sygnałów (krok 12). Oznacza to, że nawet jeśli nowe zlecenia są zablokowane, otwarte pozycje są zawsze zarządzane.

Pełna Dokumentacja Techniczna

AHS — Adaptive Hybrid System v78.00

Multi-Core Strategy Engine dla MetaTrader 5 (MQL5)

Projekt realizowany od 10 lipca, ponad 12 godzin dziennie, często przez cały tydzień — do 21 kwietnia.



SPIS TREŚCI

  1. Architektura i powiązania modułów
  2. Multi-Core Strategy Engine — koncepcja “kto pierwszy ten lepszy”
  3. Strategie — szczegółowy opis algorytmów
  4. Macro Risk Matrix — dynamiczny scoring instytucjonalny
  5. Institutional Impulse + Muzzle Mode — zmiana charakterystyki podczas impulsu
  6. Dynamic Channel (Box Trading) — tunel ceny
  7. Zarządzanie pozycjami — warstwy ochrony
  8. Ochrona konta — poziom systemowy
  9. Obsługa manualna (Click & Forget)
  10. Harmonogram i EOD Terminator
  11. News Filter
  12. Filtr Tygodniowy i Fibonacci
  13. Zarządzanie kapitałem i wielkością pozycji
  14. Pyramiding (skalowanie)
  15. Panel informacyjny
  16. Licencja i aktualizacje
  17. Pełna lista parametrów wejściowych (Inputs)




1:500

Adaptive Hybrid System - Multi-Core Strategy Engine -US100
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.