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…
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:
Check if current bar is up/down versus bars from fixed lookback, e.g. 5 bars ago.
Enter long after multiple bars close higher than open.
Enter short after multiple bars close lower than open.
Use stops to limit loss.
Customizable backtest period for optimizing parameters.
Advantages:
Consecutive up/down bars determine short-term trends.
Real-time alerts possible for monitoring.
Simple backtest optimization enables live trading.
Risks:
No overall mid/long-term bias, risks whipsaws.
Tight stops may prematurely exit.
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
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | true | BarsUp |
| v_input_2 | true | BarsDown |
| v_input_3 | timestamp(2021-01-01T00:00:00) | startDate |
| v_input_4 | timestamp(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.
/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- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- 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
- 5 Day Moving Average Channel Breakout Strategy Combined With Mileage ConceptPine Script · Breakout · 1d
- ATR Trailing Stops StrategyPine Script · Breakout · 1h
- ATR Trend Breakout StrategyPine Script · Breakout · 1d
- Adaptive Bollinger Breakout with Moving Average Quantitative Strategy SystemPine Script · Breakout · 1h
- Adaptive Channel Breakout StrategyPine Script · Breakout · 1d
- Adaptive Multi Period Trading Strategy Based on Wave Trend Momentum BreakoutPine Script · Breakout · 2h