0bps

Strategy vault / Momentum

High Frequency Fair Value Gap Momentum Trading Strategy with EMA and ATR Based Dynamic Exit

This strategy is a high-frequency trading system based on Fair Value Gaps (FVG). It combines 50-period and 200-period Exponential Moving Averages (EMA) for trend confirmation, while utilizing multiple filtering…

Author
ianzeng123
Complexity
Starter · 53 lines
Parameters
0
Backtest bar
1d · swing
Tested on
ETH/USDT · spot

IMG IMG

Overview

This strategy is a high-frequency trading system based on Fair Value Gaps (FVG). It combines 50-period and 200-period Exponential Moving Averages (EMA) for trend confirmation, while utilizing multiple filtering indicators such as volume and price volatility to enhance signal reliability. The strategy employs a dynamic take-profit and stop-loss mechanism based on Average True Range (ATR) to ensure profits while strictly controlling risks.

Strategy Principles

The core principle is to capture trading opportunities by identifying Fair Value Gaps in price movement. When price exhibits significant gaps that align with the main trend, the strategy considers this imbalance as an indication of continued price movement in that direction. Specifically:

  1. Overall trend determination using EMA50 and EMA200 relationship
  2. Identification of areas with significantly increased volume (1.5 times above 20-period average)
  3. Confirmation of price volatility exceeding normal levels, indicating strong market sentiment
  4. Trade execution when FVG appears in the trend direction with all conditions met
  5. Implementation of 2x ATR for take-profit and 1.2x ATR for stop-loss, achieving a risk-reward ratio of approximately 1.67

Strategy Advantages

  1. Multiple signal filtering mechanisms significantly improve trading accuracy
  2. Dynamic take-profit and stop-loss settings adapt to different market conditions
  3. Combines trend-following and reversal trading characteristics for profit in various market states
  4. Thoroughly considers market microstructure features like volume and price volatility
  5. Applicable to multiple major currency pairs and different timeframes

Strategy Risks

  1. Potentially inadequate stop-loss levels during extreme market volatility
  2. Some lag in identifying market turning points
  3. Possibility of frequent false signals during consolidation phases
  4. Requires real-time volume monitoring and high-quality data Risk control recommendations:
  • Adjust ATR multipliers to match different market volatility characteristics
  • Add trend filtering conditions to avoid trading in ranging markets
  • Monitor market liquidity changes in real-time

Strategy Optimization Directions

  1. Incorporate additional market microstructure indicators, such as order flow data
  2. Optimize volume filtering thresholds, considering adaptive thresholds
  3. Enhance the take-profit and stop-loss mechanism by introducing trailing stops
  4. Improve market state identification for different parameter settings
  5. Consider adding time filters to avoid trading during inactive periods

Summary

This strategy constructs a comprehensive trading system by combining technical analysis and market microstructure analysis methods. The core advantages lie in its multiple signal confirmation mechanism and dynamic risk control, though parameter optimization is still necessary for specific market conditions. Through continuous improvement and optimization, the strategy shows promise in maintaining stable performance across different market environments.

Source Pine Script

/*backtest
start: 2024-02-21 00:00:00
end: 2025-02-01 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Binance","currency":"ETH_USDT"}]
*/

//@version=5
strategy("Effective FVG Strategy - Forex", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)

// === Exponential Moving Averages for Faster Trend Detection ===
ema50 = ta.ema(close, 50)
ema200 = ta.ema(close, 200)
bullishTrend = ema50 > ema200
bearishTrend = ema50 < ema200

// === Volume & Imbalance Filters ===
highVolume = volume > ta.sma(volume, 20) * 1.5  // 1.5x higher than average volume
strongImbalance = math.abs(close - open) > ta.sma(math.abs(close - open), 20)  // Large price movement

// === Fair Value Gap (FVG) Detection ===
fvgUp = low[2] > high[0]  // Bullish FVG
fvgDown = high[2] < low[0]  // Bearish FVG

// Effective FVGs with trend confirmation
validBullFVG = fvgUp and highVolume and strongImbalance and bullishTrend
validBearFVG = fvgDown and highVolume and strongImbalance and bearishTrend

// === ATR-based Take Profit & Stop Loss (Optimized for Forex) ===
atr = ta.atr(14)
longTP = close + (2 * atr)  // TP = 2x ATR
longSL = close - (1.2 * atr)  // SL = 1.2x ATR
shortTP = close - (2 * atr)
shortSL = close + (1.2 * atr)

// === Execute Trades ===
if validBullFVG
    strategy.entry("Long", strategy.long)
    strategy.exit("Long Exit", from_entry="Long", limit=longTP, stop=longSL)

if validBearFVG
    strategy.entry("Short", strategy.short)
    strategy.exit("Short Exit", from_entry="Short", limit=shortTP, stop=shortSL)

// === Plot Buy/Sell Signals ===
plotshape(series=validBullFVG, location=location.belowbar, color=color.green, style=shape.labelup, text="BUY", title="BUY Signal")
plotshape(series=validBearFVG, location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL", title="SELL Signal")

// Highlight Significant FVGs
bgcolor(validBullFVG ? color.new(color.green, 85) : na)
bgcolor(validBearFVG ? color.new(color.red, 85) : na)

Published by ianzeng123 on the FMZ strategy square · last modified 2025-02-20. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.

Build this with AgenKit

A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/High-Frequency-Fair-Value-Gap-Momentum-Trading-Strategy-with-EMA-and-ATR-Based-Dynamic-Exit.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. Get tests, backtest, risk controls and a paper-trading switch

Understand it first

Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.

Related specs

esc

Try , , or .

↑↓ move↵ open