FVG-Delta_Forex_Engine / STRATEGY_DETAILED_SPEC.txt
abyXsmart's picture
Upload 15 files
acaeaf3 verified
Raw History Blame Contribute Delete
7.78 kB
FVG-Delta Forex Signal Engine β€” Strategy Detailed Spec (v6.0)
=============================================================
Overview
--------
A lock-forward staged Smart-Money state machine driven by a strict sequence on
15m candles. The strategy is IDENTICAL to the FVG-Delta crypto engine; this file
documents it plus the forex-specific refinements.
0) FVG + impulse context detected (zone acquired)
1) First retracement liquidity locked + BoS CLOSE through the impulse wick extreme
2) Price returns and BREAKS+CLOSES past the first liquidity (sweep)
3) Price interacts with the FVG zone
4) Opposite-direction confirmation -> verified entry (dynamic SL/TP)
"Lock-forward" means each stage transition is searched ONCE and its bar index is
stored in state. Subsequent cycles only search for the NEXT transition. A stage is
never lost to a transient empty per-cycle search window β€” only to hard
invalidation (a CLOSE through the FVG against the setup) or, for EARLY stages
only, TTL/age expiry.
Universe & timeframe
--------------------
- Market: global forex β€” FX majors/minors, metals (XAU/XAG), energy (oil,
natgas), indices (NAS100/SPX500/US30/DAX/FTSE/Nikkei/DXY). Curated in
instruments.py; illiquid exotics and single stocks are excluded.
- Data: Yahoo Finance via yfinance, 15m OHLC, no API key. The whole universe is
batch-downloaded once per scan cycle into an in-memory cache.
- Timeframe: 15m. Structural stages (0,1,2) decide on the last CLOSED candle
(bars[-2]). Stage-3 interaction and SL/TP/Break-even may use the still-forming
candle (bars[-1]) β€” see "Forex execution speed" below.
Stage detail
------------
STAGE 0 β€” FVG + impulse
A real impulse is a tight one-way burst of 3+ consecutive displacement candles
that CREATES the FVG and does not re-enter it. Staggered/cluttered legs with too
many opposing bars or alternations are rejected.
STAGE 1 β€” first liquidity + BoS
The first-retracement liquidity line is locked and an immutable BoS level is
stored. A BoS must CLOSE beyond the impulse wick extreme AFTER the liquidity,
with the FVG unmitigated and the liquidity untapped before that close. A hard
gap is enforced between the liquidity line and the FVG (so price can later sweep
the liquidity into the gap before tapping the FVG). For longs the BoS sits ABOVE
the liquidity; for shorts BELOW. A setup that inverts this never reaches Stage 1.
STAGE 2 β€” liquidity sweep
A candle BREAKS and CLOSES past the first liquidity. While at Stage 1/2 the FVG
must stay CLEAN β€” if price taps the FVG before the sweep, the sequence is broken
and the setup invalidates.
STAGE 3 β€” FVG interaction
Price touches the FVG zone. FOREX CHANGE: this is registered INTRABAR (on the
forming candle) when INTRABAR_STAGE3=true, because in fast markets price can tap
an FVG and reject within one candle β€” waiting for the close would miss it. The
Stage-3 alert fires on this touch.
Stage-3 invalidation: a CLOSE through the FVG (against the setup) before a clean
confirmation kills the setup. A wick THROUGH the FVG that CLOSES back inside
remains valid and can still produce a Stage-4 entry.
STAGE 4 β€” verified entry
An opposite-direction confirmation (strong body OR strong rejection wick with an
opposite-direction close) out of the FVG promotes to Stage 4 with dynamic
SL/TP. A confirmation whose SL/TP already played out in history is discarded as
stale (freshness gate) β€” only genuinely live setups stay in Stage 4.
Forex execution speed (the v6.0 forex edge)
-------------------------------------------
- INTRABAR_STAGE3 (default on): Stage-3 touch is detected on the forming candle.
- INTRABAR_EXITS (default on): SL / TP1 / TP2 / Break-even are detected intrabar
(using the forming candle's high/low), so invalidation and targets fire the
moment price reaches them β€” not only on candle close.
- Structural stages (1/2) remain CLOSE-based to avoid repaint of BoS/sweep.
No TTL on Stage 3/4
-------------------
Once a setup reaches Stage 3 (interaction) or Stage 4 (entry) it carries NO TTL.
It resolves naturally:
Stage 3 -> dies only on a CLOSE through the FVG (or promotes to Stage 4).
Stage 4 -> dies only on SL / TP2 / Break-even.
Early stages (0/1/2) still expire by ZONE_TTL_SECONDS / MAX_ZONE_AGE_CANDLES so
stale structure is recycled. Controlled by NO_TTL_FROM_STAGE (default 3).
SL / TP construction
--------------------
- SL anchors BEYOND the FVG-interaction wick (+ SL_WICK_BUFFER_ATR) rather than
the exact FVG edge, so price has breathing room. A minimum risk floor (ATR- and
%-based) prevents stops so tight a single candle invalidates them.
- TP2 = max(TP2_RR x risk, nearest resting liquidity / opposing swing beyond
entry). TP1 = half of the entry->TP2 distance. On TP1: close 50% and move SL to
break-even; the remainder runs to TP2.
Forex risk model (risk_forex.py)
--------------------------------
P/L in forex is pips x pip-value x lots β€” NOT a % of margin. Leverage only sets
the required margin. For each Stage-4 setup the engine reports:
- pip distances (SL, TP1, TP2)
- lot size (LOT_SIZE, default 0.01 micro)
- leverage (LEVERAGE, default 500) and required margin = notional / leverage
- $ risk and $ reward (spread-aware), and net RR
- spread (typical per-instrument, factored into the effective entry)
Worked example (EUR/USD, LONG, lot 0.01, leverage 500):
entry 1.15800, SL 1.15600, TP2 1.16400, spread 0.6p, pip-value $0.10/0.01-lot
SL distance ~20.6 pips -> risk ~ $2.12
TP2 distance ~59.4 pips -> reward ~ $5.88 -> RR ~ 2.77
notional ~ $1,158 -> margin @500x ~ $2.32
Worked example (XAU/USD, SHORT, lot 0.01, leverage 500):
entry 4243.0, SL 4253.0, TP2 4213.0, spread 2.5p, pip-value $0.10/0.01-lot
SL ~102.5 pips -> risk ~ $10.50 ; TP2 ~297.5 pips -> reward ~ $29.50 ; RR ~2.8
notional ~ $4,243 -> margin @500x ~ $8.49
(Pip values are broker-approximate defaults; override per pair via FVG_PIPVAL_*.)
Market clock (market_clock.py)
------------------------------
The forex week opens Sunday 17:00 and closes Friday 17:00 America/New_York
(DST-aware), so it is closed all weekend and on configured holidays
(New Year, Good Friday, Christmas, Boxing Day, plus FVG_FX_HOLIDAYS). Index
instruments use their cash sessions. The clock returns epoch timestamps for the
next open/close; the dashboard renders the countdown in the viewer's browser
timezone so it always matches the user's wall clock.
Economic news radar (economic_calendar.py)
------------------------------------------
The free ForexFactory weekly JSON feed is fetched and graded per instrument:
RED (No-Trade) : inside a HIGH-impact blackout (default 15m before to 15m after)
AMBER (Caution) : a HIGH event approaching (<=60m) or a MEDIUM event imminent
GREEN (Safe) : nothing significant near this instrument
Each event reduces to a short label (News: FOMC, News: CPI, News: NFP, ...) with a
live countdown. This safety context is shown on the dashboard AND attached to
every Telegram alert so the user can decide whether to trade (at their own risk).
Monitoring & lifecycle
----------------------
Stage 3 and 4 are re-checked every cycle. Stage 4 emits a per-trade alert chain:
Entry -> TP1 (close 50% + SL to break-even) -> terminal SL Hit / TP2 Hit /
Break-Even Close. Only terminal Stage-4 outcomes are written to Trade History;
all Stage 1-3 invalidations are removed beforehand.
Telegram alerts
---------------
Stage 3 and Stage 4 only (screenshot first, message second), plus the lifecycle
chain. Each alert carries the forex risk block (entry/SL/TP in price + pips, $
risk/reward, lot, leverage, margin, spread) and the market + news context. A
startup ping confirms connectivity.