0bps

Strategy vault / Trend following

Inside Bar Failure Strategy

This strategy trades based on inside bar breakdowns. If the high/low of the bar following an inside bar penetrates the prior inside bar's range, trade signals are generated. The logic is: 1. Check if the prior 2 bars…

Pine ScriptTrend following
Author
ChaoZhang
Complexity
Starter · 27 lines
Parameters
1
Backtest bar
4d · position
Tested on
BTC/USDT · futures

Strategy Logic

This strategy trades based on inside bar breakdowns. If the high/low of the bar following an inside bar penetrates the prior inside bar's range, trade signals are generated.

The logic is:

  1. Check if the prior 2 bars formed an inside bar i.e. bar 2's high/low within bar 1's range

  2. If bar 3 high exceeds bar 2 high, and closes above bar 2 low, go long

  3. If bar 3 low breaks bar 2 low, and closes below bar 2 high, go short

  4. Optionally close orders X bars later (e.g. 3 bars)

It aims to capture trends emerging from inside bar consolidations. Inside bars represent short-term balances, and breakdowns can kickstart new trends.

Advantages

  • Inside bars easy to identify, breakdowns give clear signals

  • Closing orders early avoids whipsaws

  • Simple and intuitive rules

Risks

  • Need to further validate signal effectiveness

  • Inside bar formation and breakdowns less common

  • Could trade against major trend

Summary

This strategy attempts to capitalize on trends from inside bar breakdowns. But the lower frequency of trading needs evaluation of risk-reward. Combining with other factors could improve performance.

Parameters

NameDefaultWhat it controls
v_input_13Look Forward

Source Pine Script

/*backtest
start: 2022-09-07 00:00:00
end: 2022-10-31 00:00:00
period: 4d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=3
strategy("Inside Bar Failure", overlay=true)

forward = input(defval=3, title="Look Forward")

longCondition = if (high[2] > high[1] and low[2] < low[1] and low < low[1] and high < high[1] and close > low[1])
    x = true
if (longCondition)
    strategy.entry("Long", strategy.long)

shortCondition = if (high[2] > high[1] and low[2] < low[1] and high > high[1] and low > low[1] and close < high[1])
    y = true
if (shortCondition)
    strategy.entry("Short", strategy.short)
    
if (longCondition[forward])
    strategy.close("Long")
if (shortCondition[forward])
    strategy.close("Short")

Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-14. 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/Inside-Bar-Failure-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