Adding time variable to the plot command

21 Views Asked by At

Sorry, for my coding is hella rusty, and I'm trying to figure out pinescript.

Simple script to which I'm trying to add time variable. The goal it to have the plot only during RTH (NY trading hours).

I've gotten as far as "IF statement must be inside the plot command, and not the other way around", but I can't seem to make my way any further than that. Please, help.

study("Pivot High Low Points", overlay =true)

t = time(timeframe.period, "0930-1600")
time_cond = not na(t)

lb = input(defval = 5, title="Left Bars")
rb = input(defval = 5, title="Right Bars")

mb = lb + rb + 1

plotshape(iff(not na(high[mb]), iff(highestbars(mb) == -lb, high[lb], na), na), style = shape.triangledown, location = location.abovebar, color = color.red, size = size.tiny, offset = -lb)  
plotshape(iff(not na(low[mb]), iff(lowestbars(mb) == -lb, low[lb], na), na), style = shape.triangleup, location = location.belowbar, color = color.lime, size = size.tiny, offset = -lb)

The question is, how do I insert the "if and time_cond" into the plotshape command? Thank you!

couldn't figure it out. Will not compile

1

There are 1 best solutions below

0
vitruvius On

Assign your if condition to a variable and then and it with your time_cond.

high_cond = iff(not na(high[mb]), iff(highestbars(mb) == -lb, high[lb], na), na)
low_cond = iff(not na(low[mb]), iff(lowestbars(mb) == -lb, low[lb], na), na)

high_plot = high_cond and time_cond
low_plot = low_cond and time_cond

plotshape(high_plot, style = shape.triangledown, location = location.abovebar, color = color.red, size = size.tiny, offset = -lb)  
plotshape(low_plot, style = shape.triangleup, location = location.belowbar, color = color.lime, size = size.tiny, offset = -lb)

Note: Since you are using offset in your plotshape(), you might need to adjust your time condition depending on your needs.