//@version=6 // This Pine Scriptâ„¢ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // Records the high and low of a clock window, then alerts when a later bar the same day closes outside it. // Each side alerts once per day. The window is a session in the timezone you set, not "the first bars on the chart". indicator("Opening Range Breakout", "ORB", overlay=true) string window = input.session("0930-1000", "Opening range", group="Window", tooltip="Exchange-style session, for example 0930-1000. Use a chart timeframe shorter than this window.") string tz = input.string("America/New_York", "Timezone", group="Window", tooltip="IANA timezone of the window, for example America/New_York, Europe/London, or Asia/Tokyo.") if timeframe.isdwm runtime.error("Opening Range Breakout needs an intraday chart. A daily bar cannot describe a clock window.") escapeJson(string source) => string out = str.replace_all(source, "\\", "\\\\") out := str.replace_all(out, "\"", "\\\"") out := str.replace_all(out, "\n", " ") out webhookMessage(string side, string detail) => "{\"strategy\":{\"order_action\":\"" + side + "\"},\"ticker\":\"" + escapeJson(syminfo.ticker) + "\",\"action\":\"" + escapeJson(detail) + "\"}" bool inWindow = not na(time(timeframe.period, window, tz)) var float rangeHigh = na var float rangeLow = na var bool upSent = false var bool downSent = false if timeframe.change("D") rangeHigh := na rangeLow := na upSent := false downSent := false if inWindow rangeHigh := na(rangeHigh) ? high : math.max(rangeHigh, high) rangeLow := na(rangeLow) ? low : math.min(rangeLow, low) bool ready = not inWindow and not na(rangeHigh) and not na(rangeLow) bool upBreak = ready and close > rangeHigh and not upSent bool downBreak = ready and close < rangeLow and not downSent string priceText = str.tostring(close, format.mintick) if barstate.isconfirmed and upBreak upSent := true if barstate.isrealtime alert(webhookMessage("buy", "Closed above the opening range high at " + priceText + "."), alert.freq_once_per_bar_close) if barstate.isconfirmed and downBreak downSent := true if barstate.isrealtime alert(webhookMessage("sell", "Closed below the opening range low at " + priceText + "."), alert.freq_once_per_bar_close) pHigh = plot(rangeHigh, "Opening range high", color=color.teal, linewidth=1, style=plot.style_linebr) pLow = plot(rangeLow, "Opening range low", color=color.orange, linewidth=1, style=plot.style_linebr) fill(pHigh, pLow, color=color.new(color.teal, 88), title="Opening range") plotshape(upBreak and barstate.isconfirmed, "Close above opening range", shape.triangleup, location.belowbar, color.teal, size=size.tiny) plotshape(downBreak and barstate.isconfirmed, "Close below opening range", shape.triangledown, location.abovebar, color.orange, size=size.tiny)