//@version=2 strategy("King Buy Sell - Radheyrock", overlay=true) tim = input('375') // Skip buying near the upper band and selling near the lower band out1 = security(tickerid, tim, open) out2 = security(tickerid, tim, close) // 81, 1 & 81, 2 as channel length = input(81, minval=1) src = input(close, title="Source") Band1 = input(1.0, minval=0.001, maxval=10, step=0.1) basis = sma(src, length) dev = Band1 * stdev(src, length) upper = basis + dev lower = basis - dev Band2 = input(2.0, minval=0.001, maxval=10, step=0.1) dev2 = Band2 * stdev(src, length) upper2 = basis + dev2 lower2 = basis - dev2 plot(basis, color=black, linewidth=3) p1a = plot(upper, color=green, linewidth=2) p1b = plot(lower, color=green, linewidth=2) p2a = plot(upper2, color=blue, linewidth=3) p2b = plot(lower2, color=blue, linewidth=3) // EMA settings ema1_length = input(20, minval=1, title="EMA 1 Length") ema2_length = input(50, minval=1, title="EMA 2 Length") ema3_length = input(100, minval=1, title="EMA 3 Length") ema1 = ema(close, ema1_length) ema2 = ema(close, ema2_length) ema3 = ema(close, ema3_length) plot(ema1, color=red, linewidth=2, title="EMA 1") plot(ema2, color=orange, linewidth=2, title="EMA 2") plot(ema3, color=purple, linewidth=2, title="EMA 3") // Signal conditions longCondition = crossover(security(tickerid, tim, close), security(tickerid, tim, open)) and close < upper shortCondition = crossunder(security(tickerid, tim, close), security(tickerid, tim, open)) and close > lower // Previous signal conditions longConditionPrev = longCondition[1] shortConditionPrev = shortCondition[1] // Plot signals only when they change // plotshape(series=(longCondition and not longConditionPrev), location=location.belowbar, color=green, style=shape.labelup, text="LONG") // plotshape(series=(shortCondition and not shortConditionPrev), location=location.abovebar, color=red, style=shape.labeldown, text="SHORT") // ATR Calculation atrLength = input(14, minval=1, title="ATR Length") atrMultiplier = input(1.5, title="ATR Multiplier") atrValue = atr(atrLength) // Plot ATR as an overlay on the price chart atrUpper = close + atrMultiplier * atrValue atrLower = close - atrMultiplier * atrValue plot(atrUpper, color=orange, linewidth=1, title="ATR Upper Bound") plot(atrLower, color=orange, linewidth=1, title="ATR Lower Bound") // Stop-loss based on ATR longStopLoss = close - atrMultiplier * atrValue shortStopLoss = close + atrMultiplier * atrValue // Strategy entries with ATR-based stop-loss if (longCondition and not longConditionPrev) strategy.entry("long", strategy.long, stop=longStopLoss) if (shortCondition and not shortConditionPrev) strategy.entry("short", strategy.short, stop=shortStopLoss)