// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// Assembled by [USER=2840]@FateOwnzYou[/USER] on UseThinkScript.com
// Link: https://usethinkscript.com/threads/savage-oscillator-for-thinkorswim.4214/
// Modified for TradingView by Ozia
//@version=4
study(title="Savage Oscillator", shorttitle="SVG", format=format.price, precision=2, resolution="")
//Input Paramater
RSI_length = input(2)
Reversal_Warning_Candle = input(title = "Reversal_Warning Candle", type=input.bool, defval=false)
Reversal_Warning = input(8)
Sensitivity = input(1)
HighVolume = input(title = "HighVolume", type=input.bool, defval=true)
VolumeAveragingLength = input(20)
VolumePercentThreshold = input(60)
//RSI
up = rma(max(change(close), 0), RSI_length)
down = rma(-min(change(close), 0), RSI_length)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
_High1 = hline(10.0)
_High2 = hline(8.0)
_Low1 = hline(-8)
_Low2 = hline(-10)
zero = hline(0)
//Upper and Lower Zone
fill(_High1, _High2, color=color.yellow)
fill(_Low1, _Low2, color=color.yellow)
//Stochastics
k1 = ema(stoch(close, high, low, 8), 5)
k2 = ema(stoch(close, high, low, 17), 5)
mins1 = (k1 < 100 ? k1 : 100) -50
mins2 = (k2 < 100 ? k2 : 100) -50
mins3 = (rsi < 100 ? rsi : 100) -50
maxs1 = mins1 > -100 ? mins1 : -100
maxs2 = mins2 > -100 ? mins2 : -100
maxs3 = mins3 > -100 ? mins3 : -100
s1 = maxs1 / 50.01
s2 = maxs2 / 50.01
s3 = maxs3 /50.01
bull = (ema((s1 + s2 + s3)/3, Sensitivity)) * 10
wa20 = wma(bull, 20)
wa10 = wma(bull, 10)
SpdChng = bull < 1.5 ? wa20 - 1.5 : wa10 - 1.5
bear = SpdChng - bull
middle = ((bull - bear)/2)+ bear
//High Volume
aVol = rma(volume,VolumeAveragingLength)
pVol = 100 * ((volume - aVol[1])/ aVol[1])
pDot() => pVol >= VolumePercentThreshold
plot(bull, style=plot.style_linebr, linewidth=2, color=color.green)
plot(bear, style=plot.style_linebr, linewidth=2, color=color.red)
plot(middle, style=plot.style_linebr, linewidth=1, color=color.gray)
//Reversals
DReversal_Warning() => bull > Reversal_Warning
UReversal_Warning() => bull < Reversal_Warning * -1
barcolor(Reversal_Warning_Candle and DReversal_Warning() ? color.blue : UReversal_Warning() ? color.orange : na)
barcolor(Reversal_Warning_Candle and UReversal_Warning() ? color.blue : UReversal_Warning() ? color.orange : na)
plotshape(pDot() and HighVolume ? true : na, style=shape.circle, color=color.aqua, location=location.absolute, transp = 0, size = size.tiny)
plotshape(DReversal_Warning(), style=shape.circle, color=color.orange, location=location.top, textcolor=color.black, transp = 0, size = size.tiny)
plotshape(UReversal_Warning() , style=shape.circle, color=color.red, location=location.bottom, textcolor=color.black, transp = 0, size = size.tiny)