// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © Dynamictradingstrategies //@version=5 indicator('SUSHANT ATR BREAKOUT INTRADAY SCRIPT', overlay = true) tradetime = input.session(title='tradetime', defval='0915-1530') timeframe = input.timeframe(title='tradetime', defval='1') sqoff = input.session(title='sqoff', defval='1518-1519') EOD = input.session(title='EOD', defval='1529-1530') ////////////// Timing function declaration/////////////////////// barsinsession(tradetime) => time(timeframe, tradetime) != 0 insession = barsinsession(tradetime) ? 1 : 0 sqoffsession = barsinsession(sqoff) ? 1 : 0 squareoffpos = sqoffsession == 1 and sqoffsession[1] == 0 endofday = barsinsession(EOD) ? 1 : 0 RSI_25 = input(title='RSI_25', defval=25) length_100 = input(title='RSI_100', defval=100) RSI = ta.rsi(close,RSI_25) RSI2 = ta.rsi(close,length_100) [diplus, diminus, adx] = ta.dmi(14, 14) length = input(title='ATR Period', defval=22) mult = input.float(title='ATR Multiplier', step=0.1, defval=3.0) showLabels = input(title='Show Buy/Sell Labels ?', defval=true) useClose = input(title='Use Close Price for Extremums ?', defval=true) highlightState = input(title='Highlight State ?', defval=true) atr = mult * ta.atr(length) longStop = (useClose ? ta.highest(close, length) : ta.highest(length)) - atr longStopPrev = nz(longStop[1], longStop) longStop := close[1] > longStopPrev ? math.max(longStop, longStopPrev) : longStop shortStop = (useClose ? ta.lowest(close, length) : ta.lowest(length)) + atr shortStopPrev = nz(shortStop[1], shortStop) shortStop := close[1] < shortStopPrev ? math.min(shortStop, shortStopPrev) : shortStop var int dir = 1 dir := close > shortStopPrev ? 1 : close < longStopPrev ? -1 : dir buySignal = dir == 1 sellSignal = dir == -1 buy = (buySignal and RSI > RSI2 and adx > 25) and insession short = (sellSignal and RSI < RSI2 and adx > 14) and insession sell = sellSignal or squareoffpos cover = buySignal or squareoffpos var islong = false var issell = false var isshort = false var iscover = false buy := not islong and buy sell := not issell and sell short := not isshort and short cover := not iscover and cover if buy islong := true issell := false if sell islong := false issell := true if short isshort := true iscover := false if cover isshort := false iscover := true if endofday islong := false isshort := false var color longColor = color.green var color shortColor = color.red longStopPlot = plot(dir == 1 ? longStop : na, title='Long Stop', style=plot.style_linebr, linewidth=2, color=color.new(longColor, 0)) shortStopPlot = plot(dir == 1 ? na : shortStop, title='Short Stop', style=plot.style_linebr, linewidth=2, color=color.new(shortColor, 0)) midPricePlot = plot(ohlc4, title='', style=plot.style_circles, linewidth=0, display=display.none, editable=false) longFillColor = highlightState ? dir == 1 ? longColor : na : na shortFillColor = highlightState ? dir == -1 ? shortColor : na : na fill(midPricePlot, longStopPlot, title='Long State Filling', color=longFillColor, transp=90) fill(midPricePlot, shortStopPlot, title='Short State Filling', color=shortFillColor, transp=90) alertcondition(buy, title='Alert: CE Buy', message=' Buy!') alertcondition(short, title='Alert: CE Short', message=' Short!') alertcondition(sell, title='Alert: CE Sell', message=' Sell!') alertcondition(cover, title='Alert: CE Cover', message=' Cover!') // ******************************************************************** plotshape(buy , title = "BUY", style = shape.triangleup, text = "BUY", color = color.green, textcolor = color.black, location = location.belowbar, size = size.small) plotshape(sell, title = "SELL", style = shape.triangledown, text = "SELL", color = color.red, textcolor = color.black, location = location.abovebar,size = size.small) plotshape(short , title = "SHORT", style = shape.triangledown, text = "SHORT", color = color.red, textcolor = color.black, location = location.abovebar, size = size.small) plotshape(cover, title = "COVER", style = shape.triangleup, text = "COVER", color = color.green, textcolor = color.black, location = location.belowbar,size = size.small)