0bps

Strategy vault / Breakout

Inside Bar Breakout Strategy

The inside bar breakout strategy is a trend following strategy based on candlestick patterns. It uses the inside bar and outside bar candlestick patterns to determine the trend direction and enters positions on…

Author
ChaoZhang
Complexity
Intermediate · 61 lines
Parameters
8
Backtest bar
1d · swing
Tested on
BTC/USDT · futures

IMG

Overview

The inside bar breakout strategy is a trend following strategy based on candlestick patterns. It uses the inside bar and outside bar candlestick patterns to determine the trend direction and enters positions on breakouts.

Strategy Logic

The main logic behind this strategy is identifying two types of candlestick patterns:

  1. Inside bar: When the high of current bar is lower than the previous high and the low is higher than the previous low, it indicates a price contraction.

  2. Outside bar: When the high of current bar is higher than the previous high and the low is lower than the previous low, it indicates a price expansion.

When either pattern is identified, it signals a potential entry. On the next bar after the signal bar, if open price breaks above previous high, go long. If open price breaks below previous low, go short.

After entry, take profit and stop loss orders will be placed. The specific algorithms are:

Take Profit = (Current Close Price x Target Profit Percentage) / Minimum Price Tick Stop Loss = (Current Close Price x Stop Loss Percentage) / Minimum Price Tick

By doing this, it can secure profits after hitting take profit level and limit losses below maximum tolerable amount when hitting stop loss.

Advantage Analysis

The advantages of this strategy are:

  1. Inside and outside bar patterns are quite reliable for determining trend direction.

  2. Breakout entry increases certainty and avoids some false breakouts.

  3. Fully automated without manual intervention. Reduces operational risks.

Risk Analysis

Some risks also exist with this strategy:

  1. Candlestick pattern identification not always accurate. Potential for wrong signals.

  2. Breakout entry prone to getting trapped. Stop loss may need adjustment.

  3. Improper parameter settings can lead to amplified losses. Requires robust optimization.

Improvement Areas

Some ways to improve the strategy include:

  1. Adding filters to reduce false signals, e.g. volume filter.

  2. Optimizing dynamic take profit and stop loss algorithms.

  3. Incorporating anti-reverse stop loss.

  4. Utilizing machine learning to auto optimize parameters.

Conclusion

The inside bar breakout strategy is an overall reliable and easy-to-implement trend following method. It takes advantage of the predictive power of inside bar and outside patterns combined with the higher certainty of breakout entries. With simple straightforward logic, it is beginner friendly in algorithmic trading. Further enhancements in optimization and automation will lead to more stable and intelligent trading results.

Parameters

NameDefaultWhat it controls
v_input_13target profit%
v_input_2truestop loss %
v_input_32021yearfrom
v_input_42022yearuntil
v_input_5truemonthfrom
v_input_612monthuntil
v_input_7truedayfrom
v_input_831dayuntil

Source Pine Script

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

//@version=4
strategy("inside bar strategy  Wıth SL-TP ", overlay=true )



insides = high < high[1] and low > low[1]
outsides = high > high[1] and low < low[1]

candle_control=insides or outsides


target_profit_percent=input(3,"target profit%",step=0.1)
stop_loss_percent=input(1,"stop loss %",step=0.1)



yearfrom = input(2021)
yearuntil =input(2022)
monthfrom =input(1)
monthuntil =input(12)
dayfrom=input(1)
dayuntil=input(31)


long_cond=candle_control[1] and close>open and high>high[1]
short_cond=candle_control[1] and close<open and low<low[1]



if ( long_cond ) 
    strategy.entry("LONG", strategy.long, stop=close, oca_name="TREND",  comment="LONG")
    
else
    strategy.cancel(id="LONG")


if (  short_cond ) 

    strategy.entry("SHORT", strategy.short,stop=close, oca_name="TREND", comment="SHORT")
else
    strategy.cancel(id="SHORT")
    
    
    
    
profit_target=(close*(target_profit_percent/100))/syminfo.mintick
stop_target=(close*(stop_loss_percent/100))/syminfo.mintick


strategy.exit("LONG EXIT","LONG",profit=profit_target, loss=stop_target ) 
    
strategy.exit("LONG EXIT","SHORT",profit=profit_target, loss=stop_target ) 

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