//@version=4
study(title="Scalping Arrows", shorttitle="SA 1.0", overlay=true)
frequency = input("Low", "Frequency", options=["High", "Standard", "Low"])
showScreener = false
periodK = 14
smoothK = frequency == "High" ? 1 : frequency == "Standard" ? 3 : 8
periodD = 3
length = 20
mult = 2
exp = true
BandsStyle = "Average True Range"
atrlength = 10
getK(c, h, l) => sma(stoch(c, h, l, periodK), smoothK)
getD(K) => sma(K, periodD)
getMA(s) => ema(s, length)
getATR(h,l,c) => rma(max(h-l, abs(h-c[1]), abs(l-c[1])), atrlength)
getCondBuy(c, h, l) =>
_k = getK(c, h, l)
_d = getD(_k)
_ma = getMA(c)
_rangema = getATR(h, l, c)
_lower = _ma - _rangema * mult
crossover(_k, _d) and _d < 20 and _lower > c
getCondSell(c, h, l) =>
_k = getK(c, h, l)
_d = getD(_k)
_ma = getMA(c)
_rangema = getATR(h, l, c)
_upper = _ma + _rangema * mult
crossunder(_k, _d) and _upper[1] < c[1] and _d > 80
condBuy = getCondBuy(close[1], high[1], low[1])
condSell = getCondSell(close[1], high[1], low[1])
plotshape(condBuy, "Long/Buy", shape.triangleup, location.belowbar, color.aqua, text="Long", size=size.small)
plotshape(condSell, "Short/Sell", shape.triangledown, location.abovebar, color.orange, text="Short", size=size.small)
alertcondition(condBuy, "Scalping Arrows Long", "Long")
alertcondition(condSell, "Scalping Arrows Short", "Short")