0
votes

DISPLAY VWAP ONLY IF CURRENT TIME FRAME IS LESS THAN 60MINS HOW DO I SOLVE IT?

code with error

//@version=4
study("VWAP/MVWAP", overlay = true)
vwaplength= input(title="VWAP Length", type=input.integer, defval=1)
emaSource1= input(title="EMA 1 Source", type=input.source, defval=close)

tf1 =  (timeframe.period < 60 ? 1 : 0)    //<---- this gives the error

cvwap = ema(vwap,vwaplength)
plotvwap = plot(tf1 and cvwap ? cvwap : na,color= color.navy, transp=0, title = "VWAP", linewidth=3, display =display.all)

//error: Add to Chart operation failed, reason: line 18: Cannot call 'operator <' with arguments (string, literal integer); available overloads: <(float, float) => bool; <(input float, input float) => input bool; <(const float, const float) => const bool; <(float, series[float]) => series[bool]; <(series[float], float) => series[bool]; <(series[float], series[float]) => series[bool]; line 25: Undeclared identifier 'tf1'

1

1 Answers

0
votes

timeframe.period is a string, you can't compare it with a number, you can try the following solution:

//@version=4
study("My Script",overlay=true)
a = time("60")
b = time(timeframe.period)
c = 0
c := a-b < 0 ? 1 : c[1]
plot(vwap/c)

The vwap will only be displayed if the time frame is inferior to 1 hour.