// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © JoltEffect
// XLM Network me : GAHK7EEG2WWHVKDNT4CEQFZGKF2LGDSW2IVM4S5DP42RBW3K6BTODB4A
// XLM memo : 103760958
// XLM Binance SmartChain me : 0x703a8daa5e53d2229cd94bf5df46b9ba83e3ce28
//@version=4
//Now includes 1min for Suki
//Now includes combinded Alarm indicator 3m/5m/15m/1hr
//Now includes combined indicator plotted to chart
study(title="Jolt MTF Superduper Stochastic", shorttitle="Jolt MTF Superduper Srsi")
//Plotter Inputs
p1 = hline(95, title='Overbuy', color=#FF0000, linestyle=hline.style_dotted, linewidth=2)
p2 = hline(5, title='Oversell', color=#00FF00, linestyle=hline.style_dotted, linewidth=2)
//RSI inputs
rsiSource = input(title="RSI Source", type=input.source, defval=close)
lengthRSI = input(14, "RSI Lenght", minval=1)
//Stochastic RSI Inputs
lengthStoch = input(14, "Stochastic Length", minval=1)
smoothK = input(3, minval=1, title="Stoch K")
smoothD = input(3, minval=1, title="Stoch D")
//Alarm threshholds
shortThreshold = input(285, "Short Risk Threshold 240-285", minval = 240, maxval=285)
longThreshold = input(15, "Long Risk Threshold 15-60", minval=15, maxval=60)
rsi1 = rsi(rsiSource, lengthRSI)
f_secureSecurity(_symbol, _res, _src) => security(_symbol, _res, _src[1], lookahead = barmerge.lookahead_on)
f_resInMinutes() =>
_resInMinutes = timeframe.multiplier * (
timeframe.isseconds ? 1. / 60 :
timeframe.isminutes ? 1. :
timeframe.isdaily ? 60. * 24 :
timeframe.isweekly ? 60. * 24 * 7 :
timeframe.ismonthly ? 60. * 24 * 30.4375 : na)
f_tfResInMinutes(_res) =>
security(syminfo.tickerid, _res, f_resInMinutes())
currentTfInMinutes = f_resInMinutes()
k = sma(stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
//Timeframes
outK0 = f_secureSecurity(syminfo.tickerid, tostring(1), k)
outK1 = f_secureSecurity(syminfo.tickerid, tostring(3), k)
outK2 = f_secureSecurity(syminfo.tickerid, tostring(5), k)
outK3 = f_secureSecurity(syminfo.tickerid, tostring(15), k)
outK4 = f_secureSecurity(syminfo.tickerid, tostring(30), k)
outK5 = f_secureSecurity(syminfo.tickerid, tostring(60), k)
outK6 = f_secureSecurity(syminfo.tickerid, tostring(240), k)
outK7 = f_secureSecurity(syminfo.tickerid, tostring(1440), k)
outTotal = outK1 + outK2 + outK3
megaOutTotal = outK5 + outK6 + outK7
// Ploter
plot(currentTfInMinutes<1? outK0 : currentTfInMinutes==1? k : na, title="Stoch K 1 Minutes", style=plot.style_line, linewidth=2, color=color.maroon, transp=0)
plot(currentTfInMinutes<3? outK1 : currentTfInMinutes==3? k : na, title="Stoch K 3 Minutes", style=plot.style_line, linewidth=2, color=color.purple, transp=0)
plot(currentTfInMinutes<5? outK2 : currentTfInMinutes==5? k : na, title="Stoch K 5 Minutes", style=plot.style_line, linewidth=2, color=color.aqua, transp=0)
plot(currentTfInMinutes<15? outK3 : currentTfInMinutes==15? k : na, title="Stoch K 15 Minutes", style=plot.style_line, linewidth=2, color=color.lime, transp=0)
plot(currentTfInMinutes<30? outK4 : currentTfInMinutes==30? k : na, title="Stoch K 30 Minutes", style=plot.style_line, linewidth=2, color=color.yellow, transp=0)
plot(currentTfInMinutes<60? outK5 : currentTfInMinutes==60? k : na, title="Stoch K 60 Minutes", style=plot.style_line, linewidth=2, color=color.orange, transp=0)
plot(currentTfInMinutes<240? outK6 : currentTfInMinutes==240? k : na, title="Stoch K 240 Minutes", style=plot.style_line, linewidth=2, color=color.red, transp=0)
plot(currentTfInMinutes<1440? outK7 : currentTfInMinutes==1440? k : na, title="Stoch K 1440 Minutes", style=plot.style_line, linewidth=2, color=color.white, transp=0)
plot(series = outTotal, title="Lower timeframe Alarm", color=color.olive)
plot(series = megaOutTotal, title="Higher timeframe Alarm", color=color.blue)
// Plot the tresholds
fill(p1, p2, color=color.black, transp=100, title='Background')
buyLong = outTotal <= longThreshold
buyShort = outTotal >= shortThreshold
buyMegaLong = megaOutTotal <= longThreshold
buyMegaShort = megaOutTotal >= shortThreshold
plot(buyLong ? outTotal : na, title = 'Buy Long', color = color.green, style = plot.style_circles, linewidth = 10, transp = 15)
plot(buyShort ? outTotal : na, title = 'Buy Short', color = color.red, style = plot.style_circles, linewidth = 10, transp = 15)
plot(buyMegaLong ? megaOutTotal : na, title = 'Buy Mega Long', color = color.green, style = plot.style_cross, linewidth = 6, transp = 15)
plot(buyMegaShort ? megaOutTotal : na, title = 'Buy Mega Long', color = color.red, style = plot.style_cross, linewidth = 10, transp = 15)
//if (megaOutTotal <= lowThreshold and outTotal <=lowThreshold)
//if (megaOutTotal >= upThreshold and outTotal >=upThreshold)
// end