3

sorry for being such a newb and asking this silly question but does anyone know how to turn an EMA into a toggle switch (checkbox) input in TradingView?

Example - having an EMA 200 line drawn unto the chart and having the option to open the settings and toggling it On/OFF with a checkbox.

Bjorn Mistiaen
  • 6,459
  • 3
  • 18
  • 42
Kris
  • 33
  • 4

1 Answers1

2

Generally you can click the style tab in the settings menu and turn it off there.

Alternatively you could do the following:

showMA = input(title='Show EMA', type=input.bool, defval=true)

myEMA = ema(close, 200)

plot(showMA ? myEMA : na)
bajaco
  • 830
  • 1
  • 4
  • 11
  • Is there a way to also make it stop doing its function when you uncheck it from the Inputs panel? I have the Ema plotted to a 'plotshape' that gives a signal on the chart when price is above the Ema or below it – Kris Mar 26 '21 at 00:55
  • Pinescript will give you a warning if you were to put it in an if statement, generally I don't think it's good practice to do so. You make your condition: `over = close > myEMA` and then do `plotshape(showMA ? over : na, ...)` – bajaco Mar 26 '21 at 01:39