DarkWingDuck
DarkWingDuck

Reputation: 95

Pine Script to show a line 15% above market open price

I've managed to get this simple indicator working, how can I make it a straight horizontal line 15% above the market open price (i.e 9:30am EST for the USA Markets) for the day I'm currently viewing on my chart?

study("percent line", overlay=true)
percChange = (open/100) * 115
plot(percChange, style=line, color=orange)

EDIT: This code is closer to what I'm looking for but the indicator line starts at pre-market open at 04:00am EST instead of 09:30am EST, if anyone knows how to correct it for my needs I would be grateful.

study("percent line", overlay=true)

daily_open(x) => 
    trigger = na(time("D")) or change(time("D"))
    valuewhen(trigger, open, x)

percChange = (daily_open(0)/100) * 115
plot(percChange, style=line, color=orange)

Upvotes: 1

Views: 748

Answers (1)

Starr Lucky
Starr Lucky

Reputation: 1961

//@version=4
study("", overlay = true)

percChange = (open/100) * 115

var line1 = line.new(na,na,na,na, extend = extend.right)

period  = input("1", "Period", input.resolution)
session = input("0930-1800", "Session", input.session)
inSession = time(period, session, "UTC+00")

if not inSession[1] and inSession
    line.set_xy1(line1, bar_index, percChange)
    line.set_xy2(line1, bar_index+100, percChange)

Upvotes: 1

Related Questions