0

I only know that I can use overlay = true when I'm first plotting but what if I want to add another indicator in the same script that needs overlay to be false. Is there a way I can do that?

I added 26 SMA with 9 EMA perfectly fine and I'm trying to see whether I can also add a stochastic oscillator in the script but unlike the SMA and EMA, I don't need the overlay for the oscillator

This is the code that I currently have:

study(title="Indicator", overlay = true)

lenSMA = input(26, minval = 1, title = "SMA Length")
lenEMA = input(9, minval = 1, title = "EMA Length")

plot(sma(close, lenSMA), color = color.black, linewidth = 3, title = "Plot SMA")
plot(ema(close, lenEMA), color = color.purple, linewidth = 2, title = "Plot EMA")


periodk = input(14, title = "K", minval = 1)
periodD = input(3, title = "D", minval = 1)
smoothK = input(3, title = "Smoooth", minval = 1)
k = sma(stoch(close, high, low, periodK), smoothK)
d = sma(k, period)

h0 = hline(80)
h1 = hline(20)
fill(h0, h1, color = color.purple, tranps = 75)

But as expected, the stochastic oscillator plots on the actual graph and not on the bottom portion. I want the SMA and EMA to have overlay but not the oscillator.

WaddyBox
  • 63
  • 2
  • 8
  • I think some more explanation of what you are trying to achieve would help the community understand further. Can you detail what indicators you are trying to display as false and true? As what you asked can't be achieved and you would have to use two separate indicators (one true and one false). But with more understanding of what indicator type it is there might be a way of changing the parameters so that it aligns with the chart y axis. – frien_dd Apr 28 '21 at 20:14
  • Yep sorry about that. I just edited it – WaddyBox Apr 28 '21 at 20:19
  • What symbol are you using? – frien_dd Apr 28 '21 at 21:31
  • Like the ticker ?? – WaddyBox Apr 28 '21 at 23:33
  • Yeah Stocks or Crypto "Bybit:BTCUSD". – frien_dd Apr 29 '21 at 08:09
  • Could you also add the code that you have been working on that you want to combine. This way I can play with the correct code and within the correct symbol ticker. – frien_dd Apr 29 '21 at 08:37
  • Yes I'll do that right now – WaddyBox Apr 29 '21 at 15:40
  • For the ticker, I'll use SPY – WaddyBox Apr 29 '21 at 15:46
  • Does this answer your question? [pine script with two indicators one overlaid on the chart and another on its own?](https://stackoverflow.com/questions/59956130/pine-script-with-two-indicators-one-overlaid-on-the-chart-and-another-on-its-own) – jim collins Dec 24 '22 at 19:29

2 Answers2

0

This cannot be done in Pine Script for the moment.
You'll have to create 2 scripts in order to achieve that.
One with overlay=true, and one with overlay=false.

Bjorn Mistiaen
  • 6,459
  • 3
  • 18
  • 42
0

This was the idea I was visualising but it didn't turn out the way I expected, but thought I would share.

//@version=4
study(title="Stochastic RSI", shorttitle="Stoch RSI", format=format.price, precision=2, resolution="", overlay=true)

lenSMA = input(26, minval = 1, title = "SMA Length")
lenEMA = input(9, minval = 1, title = "EMA Length")

plot(sma(close, lenSMA), color = color.black, linewidth = 3, title = "Plot SMA")
plot(ema(close, lenEMA), color = color.purple, linewidth = 2, title = "Plot EMA")

//Daily Open
dOpen = security(syminfo.tickerid, "D", open, lookahead = barmerge.lookahead_on)


smoothK = input(3, "K", minval=1)
smoothD = input(3, "D", minval=1)
lengthRSI = input(14, "RSI Length", minval=1)
lengthStoch = input(14, "Stochastic Length", minval=1)
src = input(close, title="RSI Source")
rsi1 = rsi(src, lengthRSI)
k = sma(stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = sma(k, smoothD)
k1 = k+dOpen
d1 = d+dOpen
plot(k1, "K", color=#0094FF)
plot(d1, "D", color=#FF6A00)
h00 = dOpen+80
h11 = dOpen+20
h0 = plot(h00, "Upper Band", color=#606060)
h1 = plot(h11, "Lower Band", color=#606060)
frien_dd
  • 154
  • 2
  • 12