Indicator · Pine Script v6 · On the chart

Intraday BUY/SELL & AUTO SL (5-min timeframe only) by chaitu50c

by Focal-QuantAI· code credited to chaitu50c

This indicator plots intraday reversal signals and automatic stop loss levels tailored for the 5-minute chart.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code127
Settings9inputs
LicenceNone statedfile: MPL-2.0
Last update6 months ago11 Apr 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

127 lines of Pine Script v6 from strategies/intraday_buy_sell_auto_sl_5_min_timeframe_only_by_chaitu50c/1XLAET958P9JG-sg0CX5_code.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

1XLAET958P9JG-sg0CX5_code.pine
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © chaitu50c

//@version=6
indicator('Intraday BUY/SELL & AUTO SL (5-min timeframe only) by chaitu50c)', overlay = true)

// === Inputs ===
showSignals = input.bool(true, 'Show Reversal Signals')
buyColor = input.color(color.green, 'Buy Signal Color')
sellColor = input.color(color.red, 'Sell Signal Color')
signalSize = input.string('large', 'Signal Size', options = ['tiny', 'small', 'normal', 'large', 'huge'])

// SL configuration
showSLLines = input.bool(true, 'Show SL Lines')
showSLLabels = input.bool(true, 'Show SL Labels')
slColor = input.color(color.black, 'SL Line & Label Color')
slLineWidth = input.int(1, 'SL Line Width', minval = 1, maxval = 5)
titleOffset = 10
slHitColor = input.color(color.gray, 'SL Hit Label Color')

// === Persistent storage ===
var array<line> slLines = array.new<line>()
var array<float> slLevels = array.new<float>()
var array<bool> slIsBuy = array.new<bool>()
var array<bool> slActive = array.new<bool>()
var array<int> slStartBars = array.new<int>()
var array<label> sigLabels = array.new<label>()
var array<label> slStopLbls = array.new<label>()
var array<label> slHitLbls = array.new<label>()

// === Reset on new session ===
if bool(ta.change(time('D')))
    for l in slLines
        line.delete(l)
    for lbl in sigLabels
        label.delete(lbl)
    for lbl in slStopLbls
        label.delete(lbl)
    for lbl in slHitLbls
        label.delete(lbl)
    array.clear(slLines)
    array.clear(slLevels)
    array.clear(slIsBuy)
    array.clear(slActive)
    array.clear(slStartBars)
    array.clear(sigLabels)
    array.clear(slStopLbls)
    array.clear(slHitLbls)

// === 3-Candle Reversal Logic (5-min only, body-close breakout) ===
tfMin = timeframe.multiplier
blockStartMs = math.floor(time / (15 * 60 * 1000)) * 15 * 60 * 1000
idxInBlk = math.round((time - blockStartMs) / (tfMin * 60 * 1000)) + 1
is5min = timeframe.period == '5'
blockComplete = is5min and idxInBlk % 3 == 0

c0g = close[2] > open[2]
c1r = close[1] < open[1]
c2r = close < open
c0r = close[2] < open[2]
c1g = close[1] > open[1]
c2g = close > open

buySignal = showSignals and blockComplete and c0r and c1g and c2g and close > high[2]
sellSignal = showSignals and blockComplete and c0g and c1r and c2r and close < low[2]

// block extremes
blkLow = math.min(math.min(low[2], low[1]), low)
blkHigh = math.max(math.max(high[2], high[1]), high)

// === Plot ▲/▼ reversal signals ===
if buySignal
    lbl = label.new(bar_index, low, '▲', xloc = xloc.bar_index, yloc = yloc.belowbar, textcolor = buyColor, style = label.style_none, size = signalSize)
    array.push(sigLabels, lbl)

if sellSignal
    lbl = label.new(bar_index, high, '▼', xloc = xloc.bar_index, yloc = yloc.abovebar, textcolor = sellColor, style = label.style_none, size = signalSize)
    array.push(sigLabels, lbl)

// === Draw SL lines ===
if buySignal and showSLLines
    l = line.new(bar_index, blkLow, bar_index + 1, blkLow, xloc = xloc.bar_index, extend = extend.right, color = slColor, style = line.style_dashed, width = slLineWidth)
    array.push(slLines, l)
    array.push(slLevels, blkLow)
    array.push(slIsBuy, true)
    array.push(slActive, true)
    array.push(slStartBars, bar_index)

if sellSignal and showSLLines
    l = line.new(bar_index, blkHigh, bar_index + 1, blkHigh, xloc = xloc.bar_index, extend = extend.right, color = slColor, style = line.style_dashed, width = slLineWidth)
    array.push(slLines, l)
    array.push(slLevels, blkHigh)
    array.push(slIsBuy, false)
    array.push(slActive, true)
    array.push(slStartBars, bar_index)

// === Draw SL labels ===
if buySignal and showSLLabels
    lblSL = label.new(bar_index + titleOffset, blkLow, 'STOPLOSS=' + str.tostring(blkLow, format.mintick), xloc = xloc.bar_index, yloc = yloc.price, color = slColor, textcolor = color.white, style = label.style_label_left)
    array.push(slStopLbls, lblSL)

if sellSignal and showSLLabels
    lblSL = label.new(bar_index + titleOffset, blkHigh, 'STOPLOSS=' + str.tostring(blkHigh, format.mintick), xloc = xloc.bar_index, yloc = yloc.price, color = slColor, textcolor = color.white, style = label.style_label_left)
    array.push(slStopLbls, lblSL)

// === Detect SL hits & show SL HIT ===
if array.size(slLines) > 0
    for i = 0 to array.size(slLines) - 1 by 1
        if array.get(slActive, i)
            lvl = array.get(slLevels, i)
            isB = array.get(slIsBuy, i)
            hit = isB ? close <= lvl : close >= lvl
            if hit
                line.set_x2(array.get(slLines, i), bar_index)
                line.set_extend(array.get(slLines, i), extend.none)
                array.set(slActive, i, false)
                if showSLLabels
                    label.delete(array.get(slStopLbls, i))
                midB = math.round((array.get(slStartBars, i) + bar_index) * 0.5)
                lblH = label.new(midB, lvl, 'SL HIT', xloc = xloc.bar_index, yloc = yloc.price, color = slHitColor, textcolor = color.white, style = label.style_label_left)
                array.push(slHitLbls, lblH)

// === Move SL labels with new bars ===
if showSLLabels and array.size(slStopLbls) > 0
    for i = 0 to array.size(slLines) - 1 by 1
        if array.get(slActive, i)
            label.set_xy(array.get(slStopLbls, i), bar_index + titleOffset, array.get(slLevels, i))

Overview

Intraday BUY/SELL & AUTO SL (5-min timeframe only) by chaitu50c identifies three-candle reversal patterns synchronized to 15-minute blocks, triggering buy signals when two consecutive green bars break above the preceding red candle's high, and sell signals when two red bars break below the preceding green candle's low. It draws arrow labels and dashed stop loss lines at the three-bar block extremes, resetting all drawings daily. Settings control signal visibility, line widths, and colors.

Details

Published by

Focal-QuantAI on GitHub

Code credit

chaitu50c, as written in the script's header

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Candlestick patterns, Breakout, Support & resistance

Markets

Any symbol

Timeframes

M1-M5, M15-H1

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Show Reversal SignalsbooltrueshowSignals
Buy Signal Colorcolorcolor.greenbuyColor
Sell Signal Colorcolorcolor.redsellColor
Signal SizestringlargesignalSize
Show SL LinesbooltrueshowSLLines
Show SL LabelsbooltrueshowSLLabels
SL Line & Label Colorcolorcolor.blackslColor
SL Line Widthint1slLineWidth
SL Hit Label Colorcolorcolor.grayslHitColor
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

219 stars

This indicator identifies High Of Low Price (HOLP) and Low Of High Price (LOHP) candlestick setups based on price extremes over a specified lookback period. A HOLP signal triggers when the current bar closes above the high of a recent session low, whereas a LO

Indicator v5 Candlestick patternsBreakout
Updated 1 year ago · None stated GitHub repository of Candlestick Patterns - HOLP-LOHP

Reversal Breakout System

by TamaraKGreen
46 stars

This indicator detects inside candles inside larger parent candles on the price chart. It plots colored boxes around inside and parent candles, fills them with user-adjustable transparency, draws Fibonacci retracement lines and mother candle range lines, and d

Indicator v6 Candlestick patternsBreakout
Updated 7 weeks ago · None stated GitHub repository of Reversal Breakout System

Candle Breaks 1v1 L+S

by chargersfan47
7 stars

This indicator detects 1v1 candle break patterns where the current candle breaks and closes beyond the open of the prior opposite-colored candle. It projects a 1.618 Fibonacci extension target based on the previous candle's range, calculating the expected perc

Indicator v5 BreakoutCandlestick patterns
Updated 5 months ago · None stated GitHub repository of Candle Breaks 1v1 L+S
7 stars

This indicator identifies market displacement, structure breaks, and Fair Value Gaps (FVGs) directly on the main price chart. It highlights displacement candles using an average range lookback and multiplier factor, with optional structure break filtering usin

Indicator v6 SMC / ICT / price actionSupport & resistance
Updated 3 months ago · None stated GitHub repository of [CT] Displacement FVG Toolkit

CTF Raid Indicator

by jerryinyang
5 stars

This indicator detects stop hunts, liquidity raids, and Rob Hoffman Inventory Retracement Bar breakouts directly on the main price chart. It tracks bullish and bearish retracement bars using dynamic arrays, identifying when incoming price action breaks these s

Indicator v5 SMC / ICT / price actionBreakout
Updated 2 years ago · None stated GitHub repository of CTF Raid Indicator

TheStrat Setup Screener

by 345-strategies
5 stars

This indicator screens Rob Smith's TheStrat setups across six configurable timeframes for TradingView's Pine Screener. It classifies bars and exposes inside reversals, 2-2 reversals and continuations, failing 2s, range expansions, and outside bars as numeric p

Indicator v6 Candlestick patternsSupport & resistance Repaints
Updated 2 days ago · MPL-2.0 GitHub repository of TheStrat Setup Screener

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers