OPEN-SOURCE SCRIPT
Updated maXXit EMA[V6 5.2.8]

# maXXit EMA Trading Strategy — V6.5.2.8 FXP
****
*© 2025–2026 maXXit consulting — All Rights Reserved*
---
## Overview
Fully automated EMA-based trading strategy for TradingView (Pine Script v6) with live broker execution via Python Webhook Server. Covers **20+ instruments** across Futures, CFDs, ETFs, Crypto and Forex with direct integration for **IBKR · OANDA · IG Markets**.
**What makes this system unique:**
- Three EMAs working in concert define trend direction, entry timing and signal quality
- Self-learning **Adaptive Intelligence Engine** re-weights scoring factors after every completed trade
- **FIX PARAM mode** auto-loads optimised parameters per instrument and timeframe — no manual tuning needed
- **Long Only / Short Only** modes to align with directional bias
- Full automation: TradingView alert → JSON → Python server → broker order in real time
---
## How the Signal Works
The strategy uses three EMAs:
- **FastEMA (TriggerLine)** — default 19 — generates crossover signals against EMA 55
- **EMA 55** — internal crossover partner
- **TrendLine (slow EMA)** — default 178 — defines whether Long or Short trades are allowed
- **LookBack** — default 3 bars — controls how fast the system reacts to trend changes
**Long entry fires when all of the following are true simultaneously:**
- TrendLine is rising over LookBack bars
- FastEMA crosses EMA 55 upward
- SetBack condition satisfied (if enabled)
- Bar is confirmed · pyramiding limit not yet reached
**Short entry** is the exact mirror.
### Re-Entry Mode
Instead of primary crossovers, targets **rebounds to the FastEMA** after a correction. Requires trend not overextended (not EXPAND or EXCESS), FastEMA above TrendLine for ≥ 4 bars, and a confirmed rebound candle.
### SetBack Mode
Waits for price to physically **return to the FastEMA** before entering. Eliminates overextended entries. Fewer trades, higher quality.
### Trend States
- **NOTR** (0–0.5 ATR) — No trend, no entries
- **WEAK** (0.5–2.0 ATR) — Caution, Re-Entry disabled
- **TREND** (2.0–5.0 ATR) — Optimal conditions
- **EXPAND** (5.0–7.0 ATR) — Elevated risk, Re-Entry disabled
- **EXCESS** (>7.0 ATR) — Overextended, no Re-Entries
---
## Key Parameters
**EMA Trigger Signals**
- `Use predefined Parameter` — Enables FIX PARAM. Recommended ON for live trading
- `Re Entry` — Switch to Re-Entry signal mode
- `Use SetBack` — Require pullback to FastEMA before entry *(changes EMA settings completely)*
- `EMA TriggerLine` — Default 19, options: 3/5/8/13/15/17/19/21/25/29/34/42
- `EMA TrendLine` — Default 178, options: 55/77/89/120/144/178/200/233
- `EMA LookBack` — Default 3, options: 1/2/3/4
**Trade Settings**
- `Long Only` / `Short Only` — Restrict to one direction *(both ON = resets to bidirectional)*
- `Signal Generation` — FUT (for mirror trading) · INSTRUMENT (direct) · None
- `Mirror Trade` — YES trades CFD or ETF instead of the futures contract
- `Allow direct switch` — Doubles quantity on reversal to close + open in one order
- `Maximum trades (Pyramiding)` — 1 to 10 positions per direction
**Risk, Stop & Take Profit**
- `Auto Trail` — ATR-based adaptive trailing stop
- `Configure Stop` — Manual trail via Risk %
- `Configure TP` — Take-profit target in %
- `Risk Per Trade %` — Default 1%
- `Take Profit %` — Default 5%
**Account Settings**
- `Webhook secret` — Must match Python server exactly, case-sensitive
- `Account ID` — DU... = IBKR paper · U... = IBKR live · OANDA · IG_MARKETS
- `Account Size` — USD balance for position sizing, default $10,000
- `Weekly Profit Target` — System stops at 150% of target · also sets CFD/ETF lot size
- `Max Daily Loss` — Default $150, no further trades after limit hit
**Session**
- `Session Start / End` — Trading hours in 24h exchange time
- `Allow Weekend Trading` — For Crypto only
- `Session Timezone` — Default Europe/Berlin
---
## FIX PARAM — Pre-Defined Parameter Sets
When `Use predefined Parameter` is ON, all settings load automatically. Loading an instrument on an unsupported timeframe blocks trading automatically.
**US Index Futures**
- MNQ 5m — FastEMA 13, Trend 55, LB 4, TP 4.5%
- MNQ 60m — FastEMA 5, Trend 77, LB 1, SetBack, Auto-Trail
- MYM 15m — FastEMA 8, Trend 55, LB 3, SetBack, TP 5.5%
- MYM 60m — FastEMA 15, Trend 77, LB 4, TP 10%, Pyramid 3
- MES 5m — FastEMA 34, Trend 89, LB 3, TP 3.5%
- MES 60m — FastEMA 5, Trend 55, LB 4, TP 10%, Pyramid 3
- MES 240m — FastEMA 29, Trend 178, LB 4, Re-Entry, TP 8%, Pyramid 4
**European Futures**
- FXXP 15m — FastEMA 17, Trend 77, LB 4, TP 12.5%, Pyramid 2
- FXXP 60m — FastEMA 5, Trend 89, LB 4, TP 5.5%
- FSXE 15m — FastEMA 17, Trend 77, LB 4, TP 12.5%
- FSXE 60m — FastEMA 5, Trend 120, LB 3, TP 12.5%
- CN1 240m — FastEMA 13, Trend 89, LB 4, TP 7.5%
**Commodities**
- MGC 5m — FastEMA 5, Trend 233, LB 3, FIX Stop 4%
- MGC 15m — FastEMA 17, Trend 233, LB 1, Auto-Trail, TP 10%
- MGC 60m — FastEMA 19, Trend 120, LB 2, Re-Entry, FIX Stop, TP 9.5%, **Pyramid 3**
- MGC 240m — FastEMA 17, Trend 233, LB 1, FIX Stop 2%
- MCL 15m — FastEMA 15, Trend 89, LB 2, SetBack, Re-Entry, Risk 9.2%
- MCL 60m — FastEMA 19, Trend 120, LB 2, SetBack, **Pyramid 5**
- MCL 240m — FastEMA 5, Trend 55, LB 4, FIX Stop, Pyramid 2
- MNG 60m — FastEMA 42, Trend 200, LB 4, Risk 15%, TP 17%
- ZN 60m — FastEMA 8, Trend 55, LB 3, Risk 6%
- ZW 240m — FastEMA 21, Trend 77, LB 4
**Crypto**
- BTCUSD 60m — FastEMA 29, Trend 233, LB 3, FIX Stop, TP 7.5%
- BTCUSD 240m — FastEMA 19, Trend 144, LB 1
- ETHUSD 15m — FastEMA 34, Trend 233, LB 4, Re-Entry, **Pyramid 3**
- ETHUSD 60m — FastEMA 34, Trend 144, LB 4, **Pyramid 5**
- ETHUSD 240m — FastEMA 21, Trend 200, LB 2
**Forex**
- EURUSD 60m — FastEMA 8, Trend 55, LB 3, Risk 6%
---
## Pyramiding
Adds positions to an already open and profitable direction. Volume-weighted average entry is calculated automatically and shown in the dashboard.
- **Pyramid 1** — Classic single-entry, ideal for volatile/choppy markets
- **Pyramid 3–5** — Trending markets like Gold (MGC) or Crude Oil (MCL)
- **Pyramid 5** — MCL 60m with SetBack (highly selective, pre-configured)
- **Pyramid 10** — Only for very smooth, confirmed trends
---
## Automated Execution via Webhook
Every signal generates a JSON alert sent via HTTPS POST to the Python Webhook Server (Docker container). The server validates the secret and routes to the correct broker.
**Broker routing by Account ID:**
- `DU...` / `U...` — Interactive Brokers via IB Gateway (Futures: MKT, ETF: LMT)
- `OANDA` — OANDA REST API v20, automatic symbol mapping (e.g. XAUUSD → XAU_USD)
- `IG_MARKETS` — IG Markets REST API with epic codes and auto session renewal
**Special order type `CLC`** — sends cancel-all-open-orders to IBKR.
---
## Dashboard
Real-time overlay on the chart showing:
- Market State (UPTREND / DOWNTREND / NEUTRAL / WEAK) · ADX · trend score
- Momentum · Volatility regime · Volume profile
- Current position (LONG / SHORT / FLAT) with open count
- Entry price · Profit in points · Stop & TP levels
- P/L in USD · Dollar per point · Ask / Bid
Four color themes: **Cyber** · **Quantum** · **Matrix** · **Aurora**
---
## Risk Management
- **Daily Loss Limit** — Trading stops for the day once limit is hit
- **Weekly Profit Target** — Stops at 150% of weekly target to lock in gains
- **Session Filter** — No orders outside defined hours or on weekends (unless Crypto)
- **Bar Confirmation** — Only confirmed bars trigger entries, no repainting
- **Timeframe Guard** — FIX PARAM blocks trading on unsupported timeframes
---
## Supported Instruments
MNQ · MYM · MES · MGC · MCL · MNG · ZN · ZW · FXXP · FSXE · CN1 · BTCUSD · ETHUSD · EURUSD · MHG · 10Y
---
## Important Notes
> **Automated execution requires the maXXit Python Webhook Server** running as a Docker container. The server receives TradingView alerts via HTTPS, authenticates the webhook secret, and places orders at the broker in real time.
> **Always test on a demo/paper account first.** Use Account ID `DU...` for IBKR paper, `practice` for OANDA, `DEMO` for IG Markets.
---
## Disclaimer
Trading futures, CFDs, and leveraged products involves substantial risk of loss. Past performance is not a guarantee of future results. Always test on a demo account before using real capital. maXXit consulting accepts no liability for trading losses.
****
*© 2025–2026 maXXit consulting — All Rights Reserved*
---
## Overview
Fully automated EMA-based trading strategy for TradingView (Pine Script v6) with live broker execution via Python Webhook Server. Covers **20+ instruments** across Futures, CFDs, ETFs, Crypto and Forex with direct integration for **IBKR · OANDA · IG Markets**.
**What makes this system unique:**
- Three EMAs working in concert define trend direction, entry timing and signal quality
- Self-learning **Adaptive Intelligence Engine** re-weights scoring factors after every completed trade
- **FIX PARAM mode** auto-loads optimised parameters per instrument and timeframe — no manual tuning needed
- **Long Only / Short Only** modes to align with directional bias
- Full automation: TradingView alert → JSON → Python server → broker order in real time
---
## How the Signal Works
The strategy uses three EMAs:
- **FastEMA (TriggerLine)** — default 19 — generates crossover signals against EMA 55
- **EMA 55** — internal crossover partner
- **TrendLine (slow EMA)** — default 178 — defines whether Long or Short trades are allowed
- **LookBack** — default 3 bars — controls how fast the system reacts to trend changes
**Long entry fires when all of the following are true simultaneously:**
- TrendLine is rising over LookBack bars
- FastEMA crosses EMA 55 upward
- SetBack condition satisfied (if enabled)
- Bar is confirmed · pyramiding limit not yet reached
**Short entry** is the exact mirror.
### Re-Entry Mode
Instead of primary crossovers, targets **rebounds to the FastEMA** after a correction. Requires trend not overextended (not EXPAND or EXCESS), FastEMA above TrendLine for ≥ 4 bars, and a confirmed rebound candle.
### SetBack Mode
Waits for price to physically **return to the FastEMA** before entering. Eliminates overextended entries. Fewer trades, higher quality.
### Trend States
- **NOTR** (0–0.5 ATR) — No trend, no entries
- **WEAK** (0.5–2.0 ATR) — Caution, Re-Entry disabled
- **TREND** (2.0–5.0 ATR) — Optimal conditions
- **EXPAND** (5.0–7.0 ATR) — Elevated risk, Re-Entry disabled
- **EXCESS** (>7.0 ATR) — Overextended, no Re-Entries
---
## Key Parameters
**EMA Trigger Signals**
- `Use predefined Parameter` — Enables FIX PARAM. Recommended ON for live trading
- `Re Entry` — Switch to Re-Entry signal mode
- `Use SetBack` — Require pullback to FastEMA before entry *(changes EMA settings completely)*
- `EMA TriggerLine` — Default 19, options: 3/5/8/13/15/17/19/21/25/29/34/42
- `EMA TrendLine` — Default 178, options: 55/77/89/120/144/178/200/233
- `EMA LookBack` — Default 3, options: 1/2/3/4
**Trade Settings**
- `Long Only` / `Short Only` — Restrict to one direction *(both ON = resets to bidirectional)*
- `Signal Generation` — FUT (for mirror trading) · INSTRUMENT (direct) · None
- `Mirror Trade` — YES trades CFD or ETF instead of the futures contract
- `Allow direct switch` — Doubles quantity on reversal to close + open in one order
- `Maximum trades (Pyramiding)` — 1 to 10 positions per direction
**Risk, Stop & Take Profit**
- `Auto Trail` — ATR-based adaptive trailing stop
- `Configure Stop` — Manual trail via Risk %
- `Configure TP` — Take-profit target in %
- `Risk Per Trade %` — Default 1%
- `Take Profit %` — Default 5%
**Account Settings**
- `Webhook secret` — Must match Python server exactly, case-sensitive
- `Account ID` — DU... = IBKR paper · U... = IBKR live · OANDA · IG_MARKETS
- `Account Size` — USD balance for position sizing, default $10,000
- `Weekly Profit Target` — System stops at 150% of target · also sets CFD/ETF lot size
- `Max Daily Loss` — Default $150, no further trades after limit hit
**Session**
- `Session Start / End` — Trading hours in 24h exchange time
- `Allow Weekend Trading` — For Crypto only
- `Session Timezone` — Default Europe/Berlin
---
## FIX PARAM — Pre-Defined Parameter Sets
When `Use predefined Parameter` is ON, all settings load automatically. Loading an instrument on an unsupported timeframe blocks trading automatically.
**US Index Futures**
- MNQ 5m — FastEMA 13, Trend 55, LB 4, TP 4.5%
- MNQ 60m — FastEMA 5, Trend 77, LB 1, SetBack, Auto-Trail
- MYM 15m — FastEMA 8, Trend 55, LB 3, SetBack, TP 5.5%
- MYM 60m — FastEMA 15, Trend 77, LB 4, TP 10%, Pyramid 3
- MES 5m — FastEMA 34, Trend 89, LB 3, TP 3.5%
- MES 60m — FastEMA 5, Trend 55, LB 4, TP 10%, Pyramid 3
- MES 240m — FastEMA 29, Trend 178, LB 4, Re-Entry, TP 8%, Pyramid 4
**European Futures**
- FXXP 15m — FastEMA 17, Trend 77, LB 4, TP 12.5%, Pyramid 2
- FXXP 60m — FastEMA 5, Trend 89, LB 4, TP 5.5%
- FSXE 15m — FastEMA 17, Trend 77, LB 4, TP 12.5%
- FSXE 60m — FastEMA 5, Trend 120, LB 3, TP 12.5%
- CN1 240m — FastEMA 13, Trend 89, LB 4, TP 7.5%
**Commodities**
- MGC 5m — FastEMA 5, Trend 233, LB 3, FIX Stop 4%
- MGC 15m — FastEMA 17, Trend 233, LB 1, Auto-Trail, TP 10%
- MGC 60m — FastEMA 19, Trend 120, LB 2, Re-Entry, FIX Stop, TP 9.5%, **Pyramid 3**
- MGC 240m — FastEMA 17, Trend 233, LB 1, FIX Stop 2%
- MCL 15m — FastEMA 15, Trend 89, LB 2, SetBack, Re-Entry, Risk 9.2%
- MCL 60m — FastEMA 19, Trend 120, LB 2, SetBack, **Pyramid 5**
- MCL 240m — FastEMA 5, Trend 55, LB 4, FIX Stop, Pyramid 2
- MNG 60m — FastEMA 42, Trend 200, LB 4, Risk 15%, TP 17%
- ZN 60m — FastEMA 8, Trend 55, LB 3, Risk 6%
- ZW 240m — FastEMA 21, Trend 77, LB 4
**Crypto**
- BTCUSD 60m — FastEMA 29, Trend 233, LB 3, FIX Stop, TP 7.5%
- BTCUSD 240m — FastEMA 19, Trend 144, LB 1
- ETHUSD 15m — FastEMA 34, Trend 233, LB 4, Re-Entry, **Pyramid 3**
- ETHUSD 60m — FastEMA 34, Trend 144, LB 4, **Pyramid 5**
- ETHUSD 240m — FastEMA 21, Trend 200, LB 2
**Forex**
- EURUSD 60m — FastEMA 8, Trend 55, LB 3, Risk 6%
---
## Pyramiding
Adds positions to an already open and profitable direction. Volume-weighted average entry is calculated automatically and shown in the dashboard.
- **Pyramid 1** — Classic single-entry, ideal for volatile/choppy markets
- **Pyramid 3–5** — Trending markets like Gold (MGC) or Crude Oil (MCL)
- **Pyramid 5** — MCL 60m with SetBack (highly selective, pre-configured)
- **Pyramid 10** — Only for very smooth, confirmed trends
---
## Automated Execution via Webhook
Every signal generates a JSON alert sent via HTTPS POST to the Python Webhook Server (Docker container). The server validates the secret and routes to the correct broker.
**Broker routing by Account ID:**
- `DU...` / `U...` — Interactive Brokers via IB Gateway (Futures: MKT, ETF: LMT)
- `OANDA` — OANDA REST API v20, automatic symbol mapping (e.g. XAUUSD → XAU_USD)
- `IG_MARKETS` — IG Markets REST API with epic codes and auto session renewal
**Special order type `CLC`** — sends cancel-all-open-orders to IBKR.
---
## Dashboard
Real-time overlay on the chart showing:
- Market State (UPTREND / DOWNTREND / NEUTRAL / WEAK) · ADX · trend score
- Momentum · Volatility regime · Volume profile
- Current position (LONG / SHORT / FLAT) with open count
- Entry price · Profit in points · Stop & TP levels
- P/L in USD · Dollar per point · Ask / Bid
Four color themes: **Cyber** · **Quantum** · **Matrix** · **Aurora**
---
## Risk Management
- **Daily Loss Limit** — Trading stops for the day once limit is hit
- **Weekly Profit Target** — Stops at 150% of weekly target to lock in gains
- **Session Filter** — No orders outside defined hours or on weekends (unless Crypto)
- **Bar Confirmation** — Only confirmed bars trigger entries, no repainting
- **Timeframe Guard** — FIX PARAM blocks trading on unsupported timeframes
---
## Supported Instruments
MNQ · MYM · MES · MGC · MCL · MNG · ZN · ZW · FXXP · FSXE · CN1 · BTCUSD · ETHUSD · EURUSD · MHG · 10Y
---
## Important Notes
> **Automated execution requires the maXXit Python Webhook Server** running as a Docker container. The server receives TradingView alerts via HTTPS, authenticates the webhook secret, and places orders at the broker in real time.
> **Always test on a demo/paper account first.** Use Account ID `DU...` for IBKR paper, `practice` for OANDA, `DEMO` for IG Markets.
---
## Disclaimer
Trading futures, CFDs, and leveraged products involves substantial risk of loss. Past performance is not a guarantee of future results. Always test on a demo account before using real capital. maXXit consulting accepts no liability for trading losses.
Release Notes
Bug fixes and fixed parameter updatesRelease Notes
fixes, enhancementsRelease Notes
adjustments to fixed parameters.Release Notes
performance improvementsOpen-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
maXXit consulting
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
maXXit consulting
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.