Reputation: 33
how to use this synax input(title="enable",type=input.bool) to enable or disable the indicator in one click
'''// @version=4 study(title="Dynamic Support & Resistance", shorttitle="DSR", overlay=true)
// Get user input
emaMainLength = input(title="Longterm EMA Length", type=input.integer, defval=200, minval=1)
emaDSR1Length = input(title="DSR 1 EMA Length", type=input.integer, defval=50, minval=1)
emaDSR2Length = input(title="DSR 2 EMA Length", type=input.integer, defval=20, minval=1)
// Get EMAs
ema200 = ema(close, emaMainLength)
ema50 = ema(close, emaDSR1Length)
ema20 = ema(close, emaDSR2Length)
bearTrend = ema200 > ema50 and ema50 > ema20 // Bearish trend
bullTrend = ema200 < ema50 and ema50 < ema20 // Bullish trend
// Draw invisible plot lines required for zone color fill
z1 = plot(ema20, color=na, transp=100)
z2 = plot(ema50, color=na, transp=100)
// Fill zone
fill(z1, z2, color=bearTrend ? color.red : na, transp=75)
fill(z1, z2, color=bullTrend ? color.lime : na, transp=75)
// Draw long-term EMA
plot(ema200, color=bearTrend ? color.red : na, linewidth=2, transp=0)
plot(ema200, color=bullTrend ? color.green : na, linewidth=2, transp=0)
'''
Upvotes: 1
Views: 1384
Reputation: 980
You can use a ternary with na
when choosing what to plot. Such as:
display = input(title="enable",type=input.bool, defval=true)
plot(display ? ema200 : na, color=bearTrend ? color.red : na, linewidth=2, transp=0)
Upvotes: 1