0bps

Strategy vault / Breakout

Narrow Range Inside Day Breakout Strategy

The narrow range inside day breakout strategy identifies narrow range oscillations and inside day close breakouts for long-only trend following. It generates long signals when price narrowing, inside day, and SMA…

Author
ChaoZhang
Complexity
Starter · 74 lines
Parameters
5
Backtest bar
10m · intraday
Tested on
BTC/USDT · futures

Strategy Overview

The narrow range inside day breakout strategy identifies narrow range oscillations and inside day close breakouts for long-only trend following. It generates long signals when price narrowing, inside day, and SMA slope up all emerge to capture post-breakout trends.

Strategy Logic

  1. Use NR7 to identify the narrowest range day among the past 7 days.

  2. Use inside day to determine previous day's high is lower than current day's high, and previous day's low is higher than current day's low.

  3. When NR7 and inside day occur together, with closing price higher than opening price, go long.

  4. Exit when next day's close is higher than open.

The strategy utilizes both price narrowing and inside day signals to identify accumulation stages. With SMA slope up, price is likely to breakout. Such multi-condition filtering improves accuracy.

Also, the long-only approach avoids consolidation traps and unnecessary trades.

Advantages of the Strategy

  • Considers both narrowing and inside day signals

  • SMA direction determines trend existence

  • Multi-condition filtering improves signal accuracy

  • Long-only avoids consolidation traps

  • Optimizable backtest parameters, flexible

Risk Warnings

  • SMA tuning needed to optimize signals

  • Long entry may lag, focus on breakout timing

  • Unable to profit from downtrends

  • Prevent re-expansion of ranges

Conclusion

The narrow range inside day breakout strategy thoroughly examines market structure and generates high-probability signals. With parameter tuning, it is highly adaptive. The strategy is worth backtesting, live optimization, and integration into overall quant systems.

Parameters

NameDefaultWhat it controls
v_input_1trueShow Narrow Range 7 (NR7) ?
v_input_2trueShow Inside Day (I) ?
v_input_3trueShow NR7ID (NR7 + Inside Day) colors ?
v_input_4trueShow SMA ?
v_input_514SMA Length

Source Pine Script

/*backtest
start: 2023-09-11 00:00:00
end: 2023-09-14 00:00:00
period: 10m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=2
strategy("NR7ID: Narrow Range + Inside Day, Long Only Strategy (by ChartArt)", shorttitle="CA_-_NR7ID_Strat", overlay=true) // max_bars_back=5000

// ChartArt's Narrow Range + Inside Day Strategy (Long Only)
//
// Version 1.0
// Idea by ChartArt on Oktober 16, 2016.
//
// This long only strategy determines when there is both
// a NR7 (narrow range 7, a trading day in which the range
// is narrower than any of the previous six days), plus a
// inside day (high of the current day is lower than the high
// of the previous day and the low of the current day is higher
// than the low of the previous day) both on the same trading day
// and enters a long trade when the close is larger than the
// open and the slope of the simple moving average is upwards, too.
//
// The strategy exits the long trade next time the close is
// larger than the open in any of the next trading days.
//
// In addition the NR7ID can be colored (if close large open
// colored in green, else in red) and the SMA can be drawn
// with a color based on the direction of the SMA slope.
//
// List of my work: 
// https://www.tradingview.com/u/ChartArt/
// 
//  __             __  ___       __  ___ 
// /  ` |__|  /\  |__)  |   /\  |__)  |  
// \__, |  | /~~\ |  \  |  /~~\ |  \  |  
// 
// 


// NR7 Identifier
show_NR7=input(true, type=bool,title="Show Narrow Range 7 (NR7) ?")
range=(high-low)
nr7=(range < range[1]) and (range < range[2]) and (range < range[3]) and (range < range[4]) and (range < range[5]) and (range < range[6])
plotchar(show_NR7?nr7:na, char="7", location=location.abovebar, color=blue)

// Inside Day Identifier
show_insidebar = input(true, type=bool,title="Show Inside Day (I) ?")
insidebar =  (high < high[1] and low > low[1])
plotchar(show_insidebar?insidebar:na, char="i", location=location.abovebar, color=blue)

// NR7 + Inside Day Identifier
show_NR7ID = input(true, type=bool,title="Show NR7ID (NR7 + Inside Day) colors ?")
NR7ID = nr7 and insidebar
NR7ID_color = NR7ID and open < close ? green : NR7ID and open > close ? red : gray
barcolor(show_NR7ID?NR7ID_color:na)

// Simple Moving Average
show_ma = input(true, type=bool,title="Show SMA ?")
ma_length = input(14,title="SMA Length")
ma = sma(close,ma_length)
ma_change = change(ma) > 0
ma_change_color = change(ma) > 0 ? green : change(ma) < 0 ? red : blue
plot(show_ma?ma:na,color=ma_change_color,linewidth=3)

// (not enabled) Short Strategy: NR7 + Inside Day + close is smaller than open + change of SMA is downwards
//strategy.entry("sell", strategy.short, when = NR7ID and open > close and ma_change == false, comment="Short")
//strategy.close("sell", when = open > close )

// Long Strategy: NR7 + Inside Day + close is larger than open + change of SMA is upwards
strategy.entry("long", strategy.long, when = NR7ID and open < close and ma_change == true, comment="Long")
strategy.close("long", when = open < close )

Published by ChaoZhang on the FMZ strategy square · last modified 2023-12-01. 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/Narrow-Range-Inside-Day-Breakout-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