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
19 lines of Pine Script v4 from BarUpDn Long Strategy.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.
BarUpDn Long Strategy.pine
//@version=4
strategy("BarUpDn Long Strategy", overlay=true, initial_capital = 10000, default_qty_value = 10000, default_qty_type = strategy.cash)
// There will be no short entries, only exits from long.
strategy.risk.allow_entry_in(strategy.direction.long)
BarsUp = input(1)
BarsDown = input(1)
// Strategy Backesting
startDate = input(timestamp("2021-01-01T00:00:00"), type = input.time)
finishDate = input(timestamp("2021-12-31T00:00:00"), type = input.time)
time_cond = time >= startDate and time <= finishDate
// Messages for buy and sell
message_buy = input("{{strategy.order.alert_message}}", title="Buy message")
message_sell = input("{{strategy.order.alert_message}}", title="Sell message")
if (close > open and open > close[BarsUp]) and time_cond
strategy.entry("BarUp", strategy.long, stop = high + syminfo.mintick, alert_message = message_buy)
if (close < open and open < close[BarsDown]) and time_cond
strategy.entry("BarDn", strategy.short, stop = low + syminfo.mintick, alert_message = message_sell)
//plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr)
Expand (24 lines)
Overview
BarUpDn Long Strategy places a long stop order above the current high when a bullish candle opens above a prior close. Because short entries are restricted to exiting long positions, a bearish candle opening below a prior close triggers an exit stop order near the bar low. Main inputs configure the bar lookback offsets and backtest date range. The strategy draws on the price chart and operates without stop loss or take profit orders.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
BarsUp
int
1
BarsUp
BarsDown
int
1
BarsDown
startDate
time
timestamp("2021-01-01T00:00:00")
startDate
finishDate
time
timestamp("2021-12-31T00:00:00")
finishDate
Buy message
string
{{strategy.order.alert_message}}
message_buy
Sell message
string
{{strategy.order.alert_message}}
message_sell
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.
The OutSide Bar Strategy identifies outside bar candlestick patterns directly on the main price chart. It triggers a long entry when a bar's high exceeds the previous high and its low drops below the previous low, provided the bar closes higher than its open.
This strategy plots Bollinger Bands on the price chart and enters long only when flat. It buys on a strong bullish close above the middle band or on a small-body pullback that tags the middle band with a long lower wick. The stop sits below the signal bar by a
This strategy detects Opening Range Breakouts in a specified session. It calculates the high and low of the opening range bar then plots these levels on the price chart and fills the area between them. Candles are colored based on their relation to the ORB hig
The Traffic Light Strategy is a breakout trading system overlaid on the main price chart. It detects momentum transitions whenever two consecutive candles have opposing colors (bullish followed by bearish, or vice versa). Upon detection, it marks the combined
This strategy enters long when the chart high breaks the previous higher-timeframe high during a detected higher-timeframe inside bar, and enters short on a break of the previous higher-timeframe low. It sizes positions at 10 percent of equity and has no stop
Inside Bar Breakout identifies standard and double inside bar candlestick patterns to trade breakout momentum. It sets trigger levels using reference bar extremes plus an adjustable percentage buffer. Once a pattern forms, the strategy waits up to five bars fo