Brandon G
Brandon G

Reputation: 59

Pinescript - Syminfo.type undeclared identifier

I dont understand why pinescript wont let me use the syminfo.type variable. Documentation for version 4 says it should support it.

I am trying to just do a check on the type of the security and only plot if it is a security of type futures. I am just trying to mark the real trading hours session.

//version 4
study("RTH Vertical Lines", overlay=true, scale=scale.none)
type = syminfo.type
condOpen = (syminfo.timezone == 'America/Chicago') and (hour == 8 and minute == 30) and type == "futures"
condClose = (syminfo.timezone == 'America/Chicago') and (hour == 15 and minute == 0) and type == "futures"

plot(condOpen ? 10e20 : na, style = histogram, color=#FFFF00, transp=60)
plot(condClose ? 10e20 : na, style = histogram, color=#FFFF00, transp=60)

enter image description here

Upvotes: 0

Views: 649

Answers (1)

Bjorn Mistiaen
Bjorn Mistiaen

Reputation: 6875

You can use syminfo.type, but you forgot the @ character for the version number, so the compiler didn't use version 4, and doesn't recognize it.

//@version=4
study("RTH Vertical Lines", overlay=true, scale=scale.none)

var bool    typeOk      = syminfo.type     == "futures"
var bool    timezoneOk  = syminfo.timezone == "America/Chicago"

condOpen  = timezoneOk and (hour ==  8 and minute == 30) and typeOk
condClose = timezoneOk and (hour == 15 and minute ==  0) and typeOk

plot(condOpen  ? 10e20 : na, style = plot.style_histogram, color=color.yellow, transp=60)
plot(condClose ? 10e20 : na, style = plot.style_histogram, color=color.yellow, transp=60)

You could also use bgcolor() to mark your open/close bars, instead of plot().
This way, you don't need the scale.none in study()

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

var bool    typeOk      = syminfo.type     == "futures"
var bool    timezoneOk  = syminfo.timezone == "America/Chicago"

condOpen  = timezoneOk and (hour ==  8 and minute == 30) and typeOk
condClose = timezoneOk and (hour == 15 and minute ==  0) and typeOk

bgcolor(condOpen  ? color.blue : na, transp=60)
bgcolor(condClose ? color.blue : na, transp=60)

Upvotes: 1

Related Questions