Bar-close signal rules

Bollinger Bands crossover signals: define the line and direction

A Bollinger Bands crossover occurs when price crosses a chosen upper, middle, or lower line. The phrase is incomplete until you name the line, crossing direction, price source, and whether the candle must close.

Direct answer

Define crossover signals as closed-bar state changes. For example, a lower-band re-entry requires the previous close below the lower band and the current close above it. Keep breakouts and re-entries as different alerts.

Starting values

Default length

20 bars

Default deviation

2.0

Signal timing

Bar close

Lines to name

Upper, basis, lower

How I test the setup

  1. 1

    When I test an AAPL crossover, I write the previous-bar and current-bar conditions in plain language before coding them.

  2. 2

    I give breakout and re-entry alerts different names. A cross above the upper band is not the same event as a cross back below it.

  3. 3

    I count repeated crosses during sideways markets. A rule that looks clean on one screenshot can fire often when tested across several years.

Four outer-band crossover events

Each outer band supports a breakout event and a re-entry event. These four cases carry different hypotheses, so a script should expose them separately instead of drawing one generic buy or sell arrow.

  • Upper breakout: close crosses from at or below the upper band to above it.
  • Upper re-entry: close crosses from at or above the upper band to below it.
  • Lower breakout: close crosses from at or above the lower band to below it.
  • Lower re-entry: close crosses from at or below the lower band to above it.

The middle-band crossover answers another question

Crossing the basis tracks price relative to its moving average, not an outer-band extreme. It can act as a trend state or exit condition. If the same strategy uses outer-band entry and basis exit, label both in the test report.

Why crossover arrows repaint expectations

The Bollinger values and the current price both change while a candle is open. An intrabar cross may vanish by the close even when the script itself does not look ahead. Use bar-close alerts for reproducible historical and live behavior, then include fees and slippage in any strategy test.

Breakout and re-entry are opposite events

EventPrevious closeCurrent close
Upper breakoutAt or below upper bandAbove upper band
Upper re-entryAt or above upper bandBelow upper band
Lower breakoutAt or above lower bandBelow lower band
Lower re-entryAt or below lower bandAbove lower band

Bollinger crossover Pine Script prompt

The prompt names all four events and waits for the candle to close.

Create a Pine Script v6 Bollinger Bands crossover indicator with close, length 20, and multiplier 2. Detect upper breakout, upper re-entry, lower breakout, and lower re-entry using previous and current closed-bar values. Plot a different shape and create a separate alertcondition for each event. Add an optional basis crossover alert. Do not label any event as a guaranteed buy or sell signal.
Generate crossover alerts

Pineify is an information tool, not investment advice. A crossover is a coded event, not a promise of direction or returns. Historical signals can fail in live markets.

Common questions