//@version=5 indicator(title='Snap Back Indicator', shorttitle='Snap Back Indicator', overlay=true) //Session Rules bartimeSess = time('D') newbarSess = bartimeSess != bartimeSess[1] high_range = ta.valuewhen(newbarSess, high, 0) low_range = ta.valuewhen(newbarSess, low, 0) //User inputs orbRange = input.string(title="Opening Range Period (minutes)", defval='3') inputMax = str.tonumber(orbRange) EnableAlerts = input(title='Enable Alerts', defval=false) rangeExtention = input(0.65, title="Trigger Extention Value") show = input(false, title="Display Opening Lines BEFORE Opening Range Candle") show_Trigger = input(true, title="Display Trigger Lines") hide = not show and timeframe.isintraday and timeframe.multiplier <= inputMax showEMA = input(false, title="Display EMA") risk = input(title='Risk Dollar Value', defval = 500.00) showshares= input(true, title="Show Shares") //EMA Calculation len = input.int(10, minval=1, title="EMA Length") src = input(close, title="EMA Source") offset = input.int(title="EMA Offset", defval=0, minval=-500, maxval=500) out = ta.ema(src, len) //plot(out, title="EMA", color=color.yellow, linewidth=4, offset=offset) plot(showEMA ? out : na, title='EMA', color=color.new(color.yellow, 20), linewidth=4) //Calcul For Opening Range locHigh = request.security(syminfo.tickerid, orbRange, high_range) locLow = request.security(syminfo.tickerid, orbRange, low_range) range_1 = locHigh - locLow //Plot Statements For ORB plot(hide and time(timeframe.period) > 0 ? locHigh : na, style=plot.style_line, color=locHigh[1] != locHigh ? na : color.red, title='ORB High', linewidth=4) plot(not hide and time(timeframe.period) > 0 ? locHigh : na, title='ORB High', color=color.new(color.red, 20), linewidth=4) plot(hide and time(timeframe.period) > 0 ? locLow : na, style=plot.style_line, color=locLow[1] != locLow ? na : color.green, title='ORB High', linewidth=4) plot(not hide and time(timeframe.period) > 0 ? locLow : na, title='ORB High', color=color.new(color.green, 20), linewidth=4) //plot(time(timeframe.period) > 0 ? locHigh : na, title='ORB High', color=color.new(color.red, 20), linewidth=4) //plot(time(timeframe.period) > 0 ? locLow : na, title='ORB Low', color=color.new(color.green, 20), linewidth=4) //Plot Statements For Trigger Points plot(hide and show_Trigger ? locHigh + rangeExtention : na, style=plot.style_line, color=locHigh[1] + rangeExtention != locHigh + rangeExtention ? na : color.orange, title='Short Trigger', linewidth=2) plot(not hide and show_Trigger ? locHigh + rangeExtention : na, title='Trigger Short', color=color.new(color.orange, 20), linewidth=2) plot(hide and show_Trigger ? locLow - rangeExtention : na, style=plot.style_line, color=locLow[1] - rangeExtention != locLow - rangeExtention ? na : color.orange, title='Long Trigger', linewidth=2) plot(not hide and show_Trigger ? locLow - rangeExtention : na, title='Trigger Long', color=color.new(color.orange, 20), linewidth=2) //Plot Statements For Short Stop plot(hide ? locHigh + range_1 : na, style=plot.style_line, color=locHigh[1] + range_1 != locHigh + range_1 ? na : color.red, title='Short Stop', linewidth=2) plot(not hide ? locHigh + range_1 : na, title='Short Stop', color=color.new(color.red, 20), linewidth=2) //Plot Statements For Long Stop plot(hide ? locLow - range_1 : na, style=plot.style_line, color=locLow[1] - range_1 != locLow - range_1 ? na : color.red, title='Long Stop', linewidth=2) plot(not hide ? locLow - range_1 : na, title='Long Stop', color=color.new(color.red, 20), linewidth=2) //Breakout Strategy Rules //user inputs Target1 = input(true, "Target is 1R", tooltip="Choose only one target") Target2 = input(false, "Target is Trigger", tooltip="Choose only one target") Target3 = input(false, "Target is 2R", tooltip="Choose only one target") //variable var start_Long = false var start_Short = false var end_Long = false var end_Short = false target_Long = float(na) target_Short = float(na) trigger_Short = locHigh + rangeExtention trigger_Long = locLow - rangeExtention targetLongHit = false targetShortHit = false long_Stop = locLow - range_1 short_Stop = locHigh + range_1 //Set Targets if Target1 and not Target2 and not Target3 target_Long := locHigh target_Short := locLow if not Target1 and Target2 and not Target3 target_Long := locHigh + rangeExtention target_Short := locLow - rangeExtention if not Target1 and not Target2 and Target3 target_Long := short_Stop target_Short := long_Stop //reset variables at beginning of new session if newbarSess start_Long := false start_Short := false end_Long := false end_Short := false targetLongHit := false targetShortHit:= false //ORB trade trigger calculations if high >= trigger_Short and not start_Long and not end_Short start_Short := true if low <= trigger_Long and not start_Short and not end_Long start_Long := true //plot ORB Triggers plotshape(series=start_Long and not nz(start_Long[1]), title="Long Trigger", style=shape.triangleup, location=location.belowbar, color=color.green, text="Buy", size=size.tiny) plotshape(series=start_Short and not nz(start_Short[1]), title="Short Trigger", style=shape.triangledown, location=location.abovebar, color=color.red, text="Sell", size=size.tiny) //End trade when stop is hit if low <= long_Stop and start_Long end_Long := true start_Long := false if high >= short_Stop and start_Short end_Short := true start_Short := false //plot stop hits plotshape(series=end_Long and not nz(end_Long[1]), title="Stop Hit", style=shape.xcross, location=location.belowbar, color=color.red, size=size.tiny) plotshape(series=end_Short and not nz(end_Short[1]), title="Stop Hit", style=shape.xcross, location=location.abovebar, color=color.red, size=size.tiny) //End trade when target is hit if high >= target_Long and start_Long end_Long := true start_Long := false targetLongHit := true if low <= target_Short and start_Short end_Short := true start_Short := false targetShortHit := true //plot target hits plotshape(series=targetLongHit and not nz(targetLongHit[1]), title="Stop Hit", style=shape.xcross, location=location.abovebar, color=color.purple, size=size.tiny) plotshape(series=targetShortHit and not nz(targetShortHit[1]), title="Stop Hit", style=shape.xcross, location=location.belowbar, color=color.purple, size=size.tiny) //Share Calculations shares = risk / range_1 if showshares labelText = str.tostring(math.ceil(shares)) ourLabel = label.new(x=bar_index, y=na, text=labelText, xloc=xloc.bar_index, yloc=yloc.belowbar, color=color.green, textcolor=color.white, style=label.style_label_lower_left, size=size.normal) label.delete(ourLabel[1]) //Alerts if start_Long and EnableAlerts == true alert('Long Trigger Hit OK to set Trade', freq=alert.freq_all) if start_Short and EnableAlerts == true alert('Short Trigger Hit OK to set Trade', freq=alert.freq_all)