0

I'm trying to plot all key levels on the chart.

The Previous day Open, High, Low, Close (OHLC) is plotted correctly colored in Green, Light Green, Orange, Red, respectively. (I have no problem with them)

My challenge is the way my Premarket Highs and Lows (blue lines) are plotted on the chart. unlike my OHLC lines they start plotting only from the last candle during market open. They're supposed to start being plotted during the premarket period of the current day and allow it to extend to the right..HERE'S THE CHART

I'm guessing the problem is with the tickerid but I can't figure out how.

//@version=5
indicator("Key Levels", overlay=true)

f_newLine(_color) => line.new(na, na, na, na, xloc.bar_time, extend.right, _color)

f_moveLine(_line, _x, _y) =>
    line.set_xy1(_line, _x,   _y)
    line.set_xy2(_line, _x+1, _y)

Time = 0
BarCount = 0

if(Time < 9.30)
    Hour = hour
    Minute = minute/100
    Time := Hour + Minute
    StartCount = (Time[0] < Time[1]) //boolean
    PMend = Time == 9.30             //boolean
    PMstart = StartCount             //boolean
    BarCount := ta.barssince(PMstart) +1

isGreen = close > open
isRed = close < open
isDoji = close == open

var PMhigh = 0.0
var PMlow = 0.0
var PMdb50 = 0.0


session_start = BarCount[1] > BarCount
in_session = BarCount > BarCount[1] and Time < 9.30

//Determine Premarket High
if session_start
    if isGreen
        PMhigh := high
    if isRed
        PMhigh := high
    else
        PMhigh := high
    

if in_session
    if isGreen and PMhigh < close
        PMhigh := high
    if isRed and PMhigh < open
        PMhigh := high
    if isDoji and PMhigh < close
        PMhigh := high
    

//Determine Premarket Low 
if session_start
    if isGreen
        PMlow := low
    if isRed
        PMlow := low
    else
        PMlow := low
    
    
if in_session
    if isGreen and PMlow > open
        PMlow := low
    if isRed and PMlow > close
        PMlow := low
    if isDoji and PMlow > close
        PMlow := low
    

var line    line_open = f_newLine(color.green)
var line    line_high = f_newLine(color.rgb(0, 255, 8))
var line    line_low  = f_newLine(color.rgb(255, 196, 0))
var line    line_close = f_newLine(color.red)
var line    line_PMhigh = f_newLine(color.blue)
var line    line_PMlow = f_newLine(color.blue)


[pdo,pdh,pdl,pdc,pdt1] = request.security(syminfo.tickerid,"D", [open[1],high[1],low[1],close[1],time[1]])
[pmh,pml,pdt] = request.security(syminfo.tickerid,"", [PMhigh, PMlow,time])

if barstate.islast
    f_moveLine(line_open, pdt1, pdo)
    f_moveLine(line_high, pdt1, pdh)
    f_moveLine(line_low, pdt1, pdl)
    f_moveLine(line_close, pdt1, pdc)
    f_moveLine(line_PMhigh, pdt, pmh)
    f_moveLine(line_PMlow, pdt, pml)
Arcee
  • 149
  • 8

0 Answers0