Strategy · Pine Script v4 · On the chart

BarUpDn Long Strategy

by hasnocool

BarUpDn Long Strategy executes long trades based on price bar directional movements and previous bar closes.

View on GitHub

GitHub stars106on the repository
Pine versionv4older, still runs
Lines of code19
Settings6inputs
LicenceGPL-3.0
Last update2 years ago18 Sep 2024

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 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.

Details

Published by

hasnocool on GitHub

Type

Strategy, Pine Script v4

Draws

On the price chart

Category

Candlestick patterns, Breakout

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Topics

analysisbtcusdtcryptocurrencydatapandaspythonsimulationtradingtradingview

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
BarsUpint1BarsUp
BarsDownint1BarsDown
startDatetimetimestamp("2021-01-01T00:00:00")startDate
finishDatetimetimestamp("2021-12-31T00:00:00")finishDate
Buy messagestring{{strategy.order.alert_message}}message_buy
Sell messagestring{{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.

Similar Pine Scripts

OutSide Bar Strategy

by TWODS-CAPITAL
37 stars

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.

Strategy v5 Candlestick patternsBreakout
Updated 3 years ago · MIT GitHub repository of OutSide Bar Strategy
3 stars

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

Strategy v5 Volatility & bandsBreakout
Updated yesterday · None stated GitHub repository of H4 布林ATR型態多單策略
3 stars

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

Strategy v5 BreakoutSupport & resistance
Updated 5 months ago · None stated GitHub repository of ORB Hooplah Strategy

Traffic Light Strategy

by Pa1-Tiwari
3 stars

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

Strategy v6 BreakoutCandlestick patterns
Updated 10 months ago · MIT GitHub repository of Traffic Light Strategy

Inside Bar Breakout

by Basant1Saini
1 stars

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

Strategy v5 Candlestick patternsBreakout
Updated 7 months ago · None stated GitHub repository of Inside Bar Breakout

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers