0bps

Strategy vault / Breakout

Gap Opening Strategy

1. Use 20-period simple moving average to determine overall market trend 2. Use 3-period high-low price difference to judge recent price fluctuation 3. Go long when price is above MA and difference is greater than…

Author
ChaoZhang
Complexity
Starter · 44 lines
Parameters
3
Backtest bar
1d · swing
Tested on
BTC/USDT · futures

IMG

This strategy judges market trend direction by calculating moving average and price difference to determine long entry, avoiding frequent opening during shocks.

Strategy Overview

  1. Use 20-period simple moving average to determine overall market trend
  2. Use 3-period high-low price difference to judge recent price fluctuation
  3. Go long when price is above MA and difference is greater than 20-period average
  4. Exit when price drops below 98% of entry price

Strategy Principle

This strategy combines MA and price fluctuation to capture upside opportunities during trends.

When price breaks above MA, it indicates an upward trend. If recent 3-period HL difference is larger than 20-period average, it suggests increased fluctuation and potential for a big rise for entry.

After opening, set a fixed percentage stop loss price. Exit when price drops below to control downside risk.

Advantages

  1. Avoid frequent opening during shocks by judging both trend and volatility
  2. More solid breakout signal using price difference
  3. Stop loss helps control risk

Risks

  1. Improper parameter tuning leads to missing trades
  2. Too wide stop loss brings large loss
  3. Breakout could be false, needs more factors

Risk Solutions:

  1. Optimize parameters for best combination
  2. Use multiple stops or adaptive stops per market volatility
  3. Add indicators like volume to confirm signal reliability

Improvement Direction

  1. Add volatility indicators like BB for better entry
  2. Analyze volume to confirm entry signals
  3. Judge overall market using stock index to avoid bad trades
  4. Use moving/trailing stop to lock in more profit

Conclusion

This strategy effectively filters out shocks and volatility before entering in trending markets with simple but useful indicators, avoiding unnecessary trades. Also, risk is well controlled to limit losses. Further optimizations can lead to even better results.

Parameters

NameDefaultWhat it controls
v_input_120Longitud MA
v_input_23Longitud HL
v_input_30.98Salir por debajo de precio

Source Pine Script

/*backtest
start: 2023-02-21 00:00:00
end: 2024-02-27 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Estrategia de Diferencia HL y MA para Criptomonedas", shorttitle="HL MA Crypto Strategy-Ortiz", overlay=true)

// Definir longitud de MA y HL
ma_length = input(20, title="Longitud MA")
hl_length = input(3, title="Longitud HL")
exit_below_price = input(0.98, title="Salir por debajo de precio")

// Calcular MA
ma = ta.sma(close, ma_length)

// Calcular HL
hh = ta.highest(high, hl_length)
ll = ta.lowest(low, hl_length)
hl = hh - ll

// Condiciones de tendencia alcista
bullish_trend = close > ma

// Condiciones de entrada y salida
long_condition = close > ma and close > ma[1] and hl > ta.sma(hl, ma_length)
short_condition = false // No operar en tendencia bajista
exit_condition = low < close * exit_below_price

// Entrada y salida de la estrategia
if (long_condition)
    strategy.entry("Buy", strategy.long)
if (short_condition)
    strategy.entry("Sell", strategy.short)
if (exit_condition)
    strategy.close("Buy")

// Plot de señales en el gráfico
plotshape(long_condition, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, title="Buy Signal")
plotshape(short_condition, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, title="Sell Signal")

Published by ChaoZhang on the FMZ strategy square · last modified 2024-02-28. 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/Gap-Opening-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