0bps

Strategy vault / Breakout

Breakthrough Fair Value Gap Strategy

This is a very simple trend following strategy. It will go long when a bullish FVG appears and close or go short when a bearish FVG appears. It does not perform well in range-bound markets, but can be very profitable…

Author
ChaoZhang
Complexity
Starter · 49 lines
Parameters
3
Backtest bar
1h · intraday
Tested on
BTC/USDT · futures

IMG

Overview

This is a very simple trend following strategy. It will go long when a bullish FVG appears and close or go short when a bearish FVG appears. It does not perform well in range-bound markets, but can be very profitable in trending markets.

Strategy Logic

The core logic of the strategy is to identify the fair value gap pattern. The so-called "fair value gap" refers to when the highest price today is lower than the lowest price the day before, or when the lowest price today is higher than the highest price the day before, a "breakthrough gap" will be formed. This usually signals a possible trend reversal ahead. Specifically, the rules of the strategy are:

  1. If today's highest price is lower than the lowest price 2 days ago, and the close is lower than the lowest price 2 days ago, a bearish fair value gap is considered to be formed, go short.

  2. If today's lowest price is higher than the highest price 2 days ago, and the close is higher than the highest price 2 days ago, a bullish fair value gap is considered to be formed, go long.

Here 2 lags are used, which is the highest and lowest price of the previous 2 bars to judge the fair value gap. This avoids being affected by false breakouts or short-term pullbacks and improves the reliability and quality of pattern recognition.

Advantages

  1. Identifying proper fair value gap patterns can well predict possible future trend reversals.
  2. The strategy logic and rules are simple, clear and easy to understand and implement.
  3. Can quickly capture new trend opportunities.

Risks

  1. Fair value gap pattern recognition is not completely accurate. False signals may also occur if there is a callback in the short term.
  2. The strategy will incur losses when the trend is reversed, so timely stop losses are needed to hedge risks.
  3. It performs poorly in range-bound markets, with more false signals and small losses.

Optimization Directions

  1. Optimize the stop loss mechanism. Dynamic ATR can be used to achieve dynamic risk control.
  2. Optimize filtering conditions. The reliability of fair value gap breaks can be judged based on factors like volume and moving averages.
  3. Incorporate multifactor models to predict future trend probabilities.

Conclusion

This strategy identifies the formation of fair value gaps to determine if trends may reverse. It belongs to the basic trend-following strategy. The advantage is that it can capture the timing of trend reversals more precisely. But there are also certain false signals. Risks can be controlled through stop losses and filtering. More factors can also be incorporated to improve judgment accuracy. Overall, this is a very simple and practical trend trading strategy that is worth expanding and optimizing.

Parameters

NameDefaultWhat it controls
v_input_bool_1falseTake only long trades?
v_input_bool_2false(?REMINDERS)Since this can generate a lot of trades, make sure to fill in the commission (if applicable) for a realistic ROI.
v_input_bool_3falseModify pyramiding orders to increase the amount of trades.

Source Pine Script

/*backtest
start: 2024-01-01 00:00:00
end: 2024-01-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Greg_007

//@version=5
strategy("Fair Value Gap Strategy", "FVG Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, pyramiding = 1)

var longOnly = input.bool(false, "Take only long trades?")
var pyramid = input.bool(false, "Since this can generate a lot of trades, make sure to fill in the commission (if applicable) for a realistic ROI.", group = "REMINDERS")
var pyramid2 = input.bool(false, "Modify pyramiding orders to increase the amount of trades.", group = "REMINDERS")
var bearFVG = false
var bullFVG = false
var plotBull = false
var plotBear = false
var bearTrend = false
var bullTrend = false

//BEARISH FVG
if high < low[2] and close[1] < low[2]
    bullFVG := false
    bearFVG := true
    plotBear := true
    if not longOnly
        strategy.entry("Short", strategy.short)
    else
        strategy.close_all()
else
    //BULLISH FVG 
    if low > high[2] and close[1] > high[2]
        bullFVG := true
        bearFVG := false
        plotBull := true
        strategy.entry("Long", strategy.long)
        
// plotshape(plotBull, style=shape.labeldown, location=location.abovebar, color=color.green, text="FVG",textcolor=color.white, size=size.tiny, title="Bull FVG", display=display.all - display.status_line)
// plotshape(plotBear, style=shape.labelup, location=location.belowbar, color=color.red, text="FVG",textcolor=color.white, size=size.tiny, title="Bear FVG", display=display.all - display.status_line)

// //reset the status
// plotBull := false
// plotBear := false

Published by ChaoZhang on the FMZ strategy square · last modified 2024-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/Breakthrough-Fair-Value-Gap-Strategy.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