0bps

Strategy vault / Breakout

Consecutive Bar Breakout Trading Strategy

This strategy trades consecutive upside or downside bar breakouts, judging if recent price action exhibits persistence in one direction. It aims to capture short-term trend opportunities. Strategy Logic: 1. Check if…

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

This strategy trades consecutive upside or downside bar breakouts, judging if recent price action exhibits persistence in one direction. It aims to capture short-term trend opportunities.

Strategy Logic:

  1. Check if current bar is up/down versus bars from fixed lookback, e.g. 5 bars ago.

  2. Enter long after multiple bars close higher than open.

  3. Enter short after multiple bars close lower than open.

  4. Use stops to limit loss.

  5. Customizable backtest period for optimizing parameters.

Advantages:

  1. Consecutive up/down bars determine short-term trends.

  2. Real-time alerts possible for monitoring.

  3. Simple backtest optimization enables live trading.

Risks:

  1. No overall mid/long-term bias, risks whipsaws.

  2. Tight stops may prematurely exit.

  3. Beware reversals, prudent to actively take profits.

In summary, this short-term tactical strategy has potential based on backtests, but requires caution on reversals and disciplined loss cutting when live trading.

Parameters

NameDefaultWhat it controls
v_input_1trueBarsUp
v_input_2trueBarsDown
v_input_3timestamp(2021-01-01T00:00:00)startDate
v_input_4timestamp(2021-12-31T00:00:00)finishDate
v_input_5{{strategy.order.alert_message}}Buy message
v_input_6{{strategy.order.alert_message}}Sell message

Source Pine Script

/*backtest
start: 2023-08-13 00:00:00
end: 2023-09-12 00:00:00
period: 3h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
// strategy("BarUpDn Strategy", overlay=true, initial_capital = 10000, default_qty_value = 10000, default_qty_type = strategy.cash)

BarsUp = input(1)
BarsDown = input(1)

// Strategy Backesting
startDate  = input(timestamp("2021-01-01T00:00:00"), type = input.time)
finishDate = input(timestamp("2021-12-31T00:00:00"), type = input.time)

time_cond  = true

// Messages for buy and sell
message_buy  = input("{{strategy.order.alert_message}}", title="Buy message")
message_sell = input("{{strategy.order.alert_message}}", title="Sell message")

if (close > open and open > close[BarsUp]) and time_cond
	strategy.entry("BarUp", strategy.long, stop = high + syminfo.mintick, alert_message = message_buy)
if (close < open and open < close[BarsDown]) and time_cond
	strategy.entry("BarDn", strategy.short, stop = low + syminfo.mintick, alert_message = message_sell)
//plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr)

Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-13. 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/Consecutive-Bar-Breakout-Trading-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