OPEN-SOURCE SCRIPT

Session IB 50% Model

2 767
SESSION IB 50% MODEL


OVERVIEW

This indicator builds an intraday initial-balance model on up to five user-defined
session windows. For each window it records the session high and the session low,
determines which of the two printed FIRST, and from that sequence derives a
directional setup: a retracement entry inside the range, a stop at one extreme and
a target at the other. It then tracks that setup bar by bar until it resolves, and
reports the state of every session in an on-chart dashboard.

The core idea is that the order in which a session's extremes are made describes the
leg that built the range. If the low printed first and the high second, the session
expanded upward; the model then looks for a pullback into the range to continue
higher. If the high printed first, the session expanded downward and the model looks
for a pullback to continue lower.


HOW A SETUP IS BUILT

1. RANGE COLLECTION
While a session window is open, the script tracks the running high and low and
draws a forming range box. Strict comparisons are used, so on equal values the
EARLIER bar keeps the extreme.

2. SEQUENCE
When the window closes, the bar indexes of the high and the low are compared.
The extreme with the lower bar index printed first. A circle marker is placed on
that bar; a second, dimmed marker can optionally be placed on the other extreme.

3. BIAS
Low first -> LONG bias
High first -> SHORT bias

4. LEVELS
Entry - a retracement inside the range. The percentage is measured upward from
the session low for longs and downward from the session high for shorts,
so 50 is the midpoint either way. The default is 50%.
Stop - the extreme that printed FIRST (the session low on a long, the session
high on a short).
Target - the extreme that printed SECOND (the session high on a long, the session
low on a short).

5. TRIGGER
The setup sits in a Waiting state until a bar trades through the entry level. On
that bar the state becomes In Trade, the stop and target lines are drawn, and the
trigger bar can be recoloured so it is easy to find.

6. RESOLUTION
The setup closes as SUCCESS when the target is reached or FAILED when the stop is
reached. Unresolved setups can be voided by a bar-count expiry or by the next
opening of the same session window.


SESSION CONFIGURATION

Five independent windows, each with its own enable toggle, name and time range. The
defaults are Globex 1800-1900, Asia 1900-2000, London 0300-0400, New York 0930-1030
and a disabled custom slot. All windows are evaluated in a single selectable
timezone (New York, Chicago, Los Angeles, London, Tokyo, UTC, or the symbol's native
exchange timezone), so the same settings behave consistently across instruments.


BAR-RESOLUTION LIMITS AND HOW THEY ARE HANDLED

Two situations cannot be resolved from OHLC data alone, and both are exposed as
settings rather than hidden behind an assumption:

SAME-BAR HIGH AND LOW
When one bar sets both the session high and the session low, the sequence is
unknowable. Four options are offered: infer from candle direction (a bullish bar is
assumed to have printed its low first), always assume the low came first, always
assume the high came first, or skip the session entirely.

STOP AND TARGET TAGGED ON THE SAME BAR
The true order inside the bar is unknown. The default resolves the setup as FAILED,
which is the conservative reading; it can be switched to resolve as SUCCESS instead.


DASHBOARD

A table lists every configured session with its current bias, entry, stop and target
prices, and its result state (Off, Forming, Waiting, In Trade, SUCCESS, FAILED,
Void). An optional column shows a running win-loss tally per session. The footer
reports the active timezone, the session window that is live on the current bar, and
the chart timeframe. It also displays a warning if the chart timeframe is outside the
supported range.

The win-loss tally is a plain count of how many setups reached their target versus
their stop over the loaded chart history. It is a visual reference only, not a
backtest, and it includes no costs, slippage or position sizing.


DISPLAY CONTROLS

- Session range box with adjustable transparency and separate forming, bullish and
bearish colours.
- Circle markers on the session extremes with a point-size control that goes finer
than the standard named label sizes.
- Independent colour, width and line style for the entry, stop and target lines.
- Labels can show the level name alone or with its price, in four sizes.
- Labels can anchor to the END of their line or to its CENTER; centre placement
switches the label to a downward pointer so the line does not strike through the
text. Each level also has its own bar offset applied on top of the anchor.
- The 50% line can be anchored back to the session start or begin at the session
close.
- The entry bar can be recoloured, with body, border and wick set independently.
- Old resolved setups are pruned automatically to keep drawing counts bounded.


ALERTS

Create the alert using "Any alert() function call". Three events fire, each naming
the session that produced it:
- a setup is armed at session close, with its entry, stop and target
- the entry level is tagged
- the target or the stop is reached


TIMEFRAMES AND INSTRUMENTS

Intended for intraday charts of 60 minutes or less. The session windows require
intraday data, and the dashboard flags the chart if the timeframe falls outside that
range. The model itself is instrument-agnostic and works on any symbol that has the
relevant session activity, though the default windows are chosen with index futures
in mind.


NOTES

This is a visual analysis tool, not a strategy and not an automated system. It places
no orders, produces no equity curve, and makes no claim about future results. Levels
are derived from completed session ranges and, once a session has closed, do not move
or repaint. Every setting described above is exposed in the settings panel so the
logic can be inspected and adapted.

Nothing here is financial advice. Test any model on your own instruments and
timeframes, and manage risk independently.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.