GFast_%R+stoch+rsi
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © gfastjamwork

//@version=4
//udy("GFast")
study("GFast_%R+stoch", shorttitle="%G", overlay=0)

//============================================================================//
//                            stoch                                           //
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)
plot(k, "K", color=#0094FF)
plot(d, "D", color=#FF6A00)
h0 = hline(80, "Upper Band", color=#606060)
h1 = hline(20, "Lower Band", color=#606060)
//fill(h0, h1, color.rgb(153, 21, 255,80),  title="Background")
//==========================================================================//
//                                %R                                        //
length = input(title="Length", type=input.integer, defval=14)
src2 = input(close, "Source", type = input.source)
_pr(length) =>
	max = highest(length)
	min = lowest(length)
	-100 * (src2 - min) / (min - max)
percentR = _pr(length)

plot(percentR, title="%R", color=#FF9800 ,linewidth=2)
//==========================================================================//

///****************************************************************************//
//Bull = _pr(length) < d
//Bear = d > _pr(length)
///=== Display %G lines =====

//GG = plot(percentR, title="%R", color=#7E57C2,linewidth=2)
//StochG = plot(d, "D", color=#FF6A00)
//fillcolor = Bull ? color.rgb(50,205,50,80) : Bear ? color.red : color.rgb(255,3,3,80)
//fill(GG,StochG,fillcolor)

//@version=4
//study(title="Relative Strength Index", shorttitle="RSI", format=format.price, precision=2, resolution="")
len = input(14, minval=1, title="Length")
src3 = input(close, "Source", type = input.source)
up = rma(max(change(src3), 0), len)
down = rma(-min(change(src3), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
plot(rsi, "RSI", color.white , linewidth=2)
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")

