1

I have an indicator that has an 8 sma ribbon and 4 other MAs. Is it possible to divide these into two groups with check boxes in the settings dialog box so I can hide the ribbon so my charts don't look cluttered? I'm new to coding, any help is appreciated.

showRibbon = input.bool(true, 'Ribbon') 
showEmas = input.bool(true, 'EMAs') 
Ribbon = ta.sma(ohlc4,len1, len2, len3, len4, len5, len6, len7, len8) 
EMAs = ta.ema(ohlc4,len9, len10, len11, len12)
smashapalooza
  • 932
  • 2
  • 2
  • 12

1 Answers1

0

Yes this is doable. You can turn each on or off in the indicator settings. See example.

//@version=5
indicator("My script", overlay = true)
showRibbon = input.bool(true, 'Show Ribbon')
showEmas = input.bool(true, 'Show Emas')

fakeRibbon = ta.sma(close,50)
EMA1 = ta.ema(close,21)

plot(showRibbon ? fakeRibbon : na, color= color.blue)
plot(showEmas ? EMA1 : na, color = color.green)
smashapalooza
  • 932
  • 2
  • 2
  • 12
  • how would i plot this: – CrypticSins May 13 '23 at 03:49
  • There’s a plot in my example. Copy that into the pine editor and add it to your chart so you can see how it works. Otherwise Post your code if you want myself or someone to look directly at it – smashapalooza May 13 '23 at 03:54
  • showRibbon = input.bool(true, 'Ribbon') showEmas = input.bool(true, 'EMAs') Ribbon = ta.sma(ohlc4,len1, len2, len3, len4, len5, len6, len7, len8) EMAs = ta.ema(ohlc4,len9, len10, len11, len12) – CrypticSins May 13 '23 at 04:02
  • how can i assign the emas to the either the ribbon or ema group? – CrypticSins May 13 '23 at 04:07
  • You're can't get your ma's like that, you can only put in one length at a time. You need a new variable for each moving average. You put them in a group just like the plot lines in the example. In none code they would read like this if 'showEmas' is checked then plot the ema otherwise plot nothing, then the color assigned for the ema – smashapalooza May 13 '23 at 04:11
  • You should read up on the ternary operator https://www.tradingview.com/pine-script-docs/en/v5/language/Operators.html#ternary-operator – smashapalooza May 13 '23 at 04:13