Joe
Joe

Reputation: 7919

PineScript - How to plot a line in upper graph (MA) or lower graph (RSI)

Is there a different way to plot a line in upper graph (like MA indicator) or in lower graph (like RSI indicator) because I can not see any difference in the code.

Will it be possible to have an indicator with plotting both graphs (up and down)?

Upper graph like MA

enter image description here

//@version=4
study(title="Moving Average", shorttitle="MA", overlay=true, resolution="")
len = input(9, minval=1, title="Length")
src = input(close, title="Source")
offset = input(title="Offset", type=input.integer, defval=0, minval=-500, maxval=500)
out = sma(src, len)
plot(out, color=color.blue, title="MA", offset=offset)

Lower graph like RSI

enter image description here

//@version=4
study(title="Relative Strength Index", shorttitle="RSI", format=format.price, precision=2, resolution="")
len = input(14, minval=1, title="Length")
src = input(close, "Source", type = input.source)
up = rma(max(change(src), 0), len)
down = rma(-min(change(src), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
plot(rsi, "RSI", color=#7E57C2)
band1 = hline(70, "Upper Band", color=#787B86)
bandm = hline(50, "Middle Band", color=color.new(#787B86, 50))
band0 = hline(30, "Lower Band", color=#787B86)
fill(band1, band0, color=color.rgb(126, 87, 194, 90), title="Background")

Upvotes: 2

Views: 2954

Answers (2)

SafetyHammer
SafetyHammer

Reputation: 411

you can use hline function to draw horizontal lines also line.new. If you want to plot on both top and bottom screens then you need to add code in both top and bottom.

Upvotes: 0

rumpypumpydumpy
rumpypumpydumpy

Reputation: 3803

In study() there is the overlay parameter. Using overlay = true places the indicator in the main pane and overlay = false into a sub pane like RSI.

You can only assign the indicator/script to a single pane, so no, you can't plot on both.

Upvotes: 3

Related Questions