A complete enum, input, and switch example
Paste this v6 indicator into Pine Editor. The default Exponential choice plots a 20-bar EMA; Simple plots the SMA; Hidden removes the line. Both averages are calculated on every bar before the switch selects the output. The table shows the selected title through str.tostring(). The title is useful for display, while dispatch uses AverageMode members.
//@version=6
indicator("Enum average modes", overlay=true)
enum AverageMode
sma = "Simple"
ema = "Exponential"
hidden = "Hidden"
AverageMode mode = input.enum(AverageMode.ema, "Average mode")
int length = input.int(20, "Length", minval=1)
float smaValue = ta.sma(close, length)
float emaValue = ta.ema(close, length)
float selected = switch mode
AverageMode.sma => smaValue
AverageMode.ema => emaValue
AverageMode.hidden => float(na)
=> float(na)
plot(selected, "Selected average", color=color.blue, linewidth=2)
var table status = table.new(position.top_right, 1, 1)
if barstate.islast
table.cell(status, 0, 0, str.tostring(mode), text_color=color.white, bgcolor=color.blue)