1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.
Source Code
30 lines of Pine Script v4 from BTCBreakoutShortHedge.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.
BTCBreakoutShortHedge.pine
//@version=4
strategy("BTC Breakout Short Selling with Hedge", shorttitle="BTC_BSSH", overlay=true)
// Input parameters
atr_length = input(14, title="ATR Length", minval=1)
breakout_length = input(50, title="Breakout Lookback Length", minval=1)
hedge_ratio = input(0.5, title="Hedge Ratio", type=input.float)
stop_loss_atr = input(2, title="Stop Loss Multiplier (ATR)", type=input.float)
take_profit_atr = input(3, title="Take Profit Multiplier (ATR)", type=input.float)
// Calculate Average True Range (ATR)
atr = atr(atr_length)
// Identify breakout
lowest_low = lowest(low, breakout_length)
breakout = close < lowest_low
// Entry conditions
enter_short = breakout
// Stop Loss and Take Profit levels
stop_loss_level = close + atr * stop_loss_atr
take_profit_level = close - atr * take_profit_atr
// Execute strategy
strategy.entry("Short", strategy.short, when=enter_short)
strategy.exit("SL/TP", "Short", stop=stop_loss_level, limit=take_profit_level)
// Hedge position
strategy.entry("Hedge", strategy.long, qty_percent=hedge_ratio * 100, when=enter_short)
Overview
BTC Breakout Short Selling with Hedge identifies market lows over a specified lookback period to trigger short entries. Upon entry, it calculates dynamic stop loss and take profit levels based on Average True Range multipliers. Simultaneously, the strategy opens a long hedge position scaled by a percentage hedge ratio. The strategy overlays directly on the main price chart. Note that while the short entry includes defined risk exits, the secondary hedge position does not feature built-in stop loss or take profit rules.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
ATR Length
int
14
atr_length
Breakout Lookback Length
int
50
breakout_length
Hedge Ratio
float
0.5
hedge_ratio
Stop Loss Multiplier (ATR)
float
2
stop_loss_atr
Take Profit Multiplier (ATR)
float
3
take_profit_atr
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.
Calculates standard Bollinger Bands and identifies band expansion breakouts where upper and lower bands move in opposite directions. It enters long positions when price breaks above the upper band with a high candle body percentage, and enters short positions
This strategy plots VWMA-based Bollinger bands on the 1-minute ES futures price chart for volatility analysis and potential breakout identification. It calculates dynamic long and short stop loss and take profit levels using percentage inputs relative to entry
This strategy detects price breakouts above rolling highest highs or below lowest lows over a customizable lookback period. It includes optional volume spike and ATR volatility threshold filters, along with bar confirmation rules. Positions are taken upon conf
This price-chart strategy plots a simple moving average and upper and lower bands built from the standard deviation of close, scaled by separate offset inputs. It enters a fixed quantity long when close crosses above the upper band and a fixed quantity short w
2 Candles Inside ATR is an overlay script that measures volatility compression across two consecutive candles. It calculates a smoothed Average True Range (ATR) and compares it against the combined high and low range of the current and previous bars. When the
This strategy trades long breakouts of a fast and a slow moving average on the price chart. It opens a long position when price crosses above either average, using a percentage of equity as size. It reduces the position by a set share when the high reaches the