Don Krypto
Pine Script Rookie
Pine Script Rookie
Posts: 2
Joined: March 10th, 2023
Contact: TradingView Profile

Hide Old "Opening Range Breakout Lines"

Hi! I am using the indicator "Opening Range Breakout Lines" by RicardoSantos on Tradingview. Now I would like to hide the old price lines so that the indicator only shows the most recent open, buy and sell line. Is anyone able to help? Thanks in advance!

The code (v3) looks like this:

Code: Select all

//@version=3
study(title='Opening Range Breakout Lines', shorttitle='Opening Range Breakout Lines', overlay=true)

// Based on "[STRATEGY][RS]Open Session Breakout Trader" by RicardoSantos Published Jul 10, 2017
// All credit for the base coding of this script goes to Ricardo
// His script can be viewed at https://www.tradingview.com/script/mIvVYU42-STRATEGY-RS-Open-Session-Breakout-Trader/

use_trade_session = true
trade_session = input(title='Trade Session(xxxx-xxxx to define a interval):', type=session, defval='1801-1600', confirm=false)
isinsession = use_trade_session ? not na(time('1', trade_session)) : true

percent_range_multiplier = input(0.15)
r = security(tickerid, 'D', atr(100)[1])
open_price = open
open_price := change(use_trade_session and isinsession ? 1 : 0) > 0 ? open : open_price[1]
buy_line = open_price + r * percent_range_multiplier
sel_line = open_price - r * percent_range_multiplier
plot(series=not isinsession ? na : open_price, title='Session Open Price', color=black, linewidth=4, style=linebr, transp=0)
plot(series=not isinsession ? na : buy_line, title='Buy Line', color=green, linewidth=4, style=linebr, transp=0)
plot(series=not isinsession ? na : sel_line, title='Sell Line', color=maroon, linewidth=4, style=linebr, transp=0)

//  Conditions to buy/sell on the first bar, since cross's arent detected.
buy_on_1st_bar = change(open_price) != 0 and high > buy_line
sel_on_1st_bar = change(open_price) != 0 and low < sel_line

buy_trigger = crossover(close, buy_line) and isinsession
sel_trigger = crossunder(close, sel_line) and isinsession

plotshape(buy_trigger, style=shape.labelup, color=green, location=location.belowbar, textcolor=white, text="Buy", title="Buy")
plotshape(sel_trigger, style=shape.labeldown, color=red, location=location.abovebar, textcolor=white, text="Sell", title="Sell")

plotarrow(sel_trigger?-1:na, title="SELL Arrow", colordown=red, maxheight=100, minheight=50, transp=20)
plotarrow(buy_trigger?1:na, title="BUY Arrow", colordown=green, maxheight=100, minheight=50, transp=20)


alertcondition(buy_trigger, title="Buy Alert", message="Breakout Lines Possible Buy")
alertcondition(sel_trigger, title="Sell Alert", message="Breakout Lines Possible Sell") 

// Christmas Update Dec 27, 2019

Steve Burman
Moderator
Moderator
Posts: 109
Joined: January 13th, 2023

Re: Hide Old "Opening Range Breakout Lines"

Don,

You can add the following to the end of your buy_trigger and sel_trigger lines

and barstate.islast

however, this will only paint the lines on the last real-time bar if it's a buy or sell. So if the last buy_trigger or sel_trigger is 1 or more bars ago this won't display.

The only way I can think to do this would be to create an array of the bar_index and how many bars ago (bars_ago) of the last occurence of a buy_trigger or sel_trigger, overwriting the last entry with each new one. Then have a condition in the plotarrow statement that if the bars_ago is within a certain # of bars ago then display the line. I don't know how to do that exactly though.

Don Krypto
Pine Script Rookie
Pine Script Rookie
Posts: 2
Joined: March 10th, 2023
Contact: TradingView Profile

Re: Hide Old "Opening Range Breakout Lines"

Hey thanks for the reply! I will check this out in depth and will let you know about my progress.

Thanks!

Return to “Pine Script Q&A”