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…

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:
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.
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:
Inside and outside bar patterns are quite reliable for determining trend direction.
Breakout entry increases certainty and avoids some false breakouts.
Fully automated without manual intervention. Reduces operational risks.
Risk Analysis
Some risks also exist with this strategy:
Candlestick pattern identification not always accurate. Potential for wrong signals.
Breakout entry prone to getting trapped. Stop loss may need adjustment.
Improper parameter settings can lead to amplified losses. Requires robust optimization.
Improvement Areas
Some ways to improve the strategy include:
Adding filters to reduce false signals, e.g. volume filter.
Optimizing dynamic take profit and stop loss algorithms.
Incorporating anti-reverse stop loss.
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
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 3 | target profit% |
| v_input_2 | true | stop loss % |
| v_input_3 | 2021 | yearfrom |
| v_input_4 | 2022 | yearuntil |
| v_input_5 | true | monthfrom |
| v_input_6 | 12 | monthuntil |
| v_input_7 | true | dayfrom |
| v_input_8 | 31 | dayuntil |
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.
/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- 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
- Adaptive Multi Period Trading Strategy Based on Wave Trend Momentum BreakoutPine Script · Breakout · 2h
- Advanced Multi Pattern Breakout Trading StrategyPine Script · Breakout · 1d
- Dual Thrust StrategyPine Script · Breakout · 10m
- Dynamic Bollinger Bands Breakout Quantitative Trading StrategyPine Script · Breakout · 2d
- Dynamic Dual Moving Average Breakthrough Trading System Dynamic Dual Moving Average Breakthrough Trading SystemPine Script · Breakout · 1d
- Flexible Long Short Trading Strategy Based on Keltner ChannelsPine Script · Breakout · 1d