OPEN-SOURCE SCRIPT

Gold Pray Model - Sweep & Reverse [M5]

1 009
Gold Pray Model - Sweep & Reverse [M5]

Gold Pray Model - Sweep & Reverse [M5] is a visual intraday trading model built around an opening range, liquidity sweep, market structure shift and risk/reward projection.

The indicator is designed to help traders analyze a specific intraday setup where price first creates an initial range, then sweeps one side of that range, and finally confirms a potential reversal through a market structure shift.

This script is an indicator, not a strategy. It does not place trades, does not execute orders and does not provide guaranteed buy or sell signals. It is intended for visual analysis, setup preparation, alerting and educational study. Every signal should be confirmed by the trader’s own analysis, market context and risk management.

Main idea

The model follows a simple but structured logic:

1. Build an initial market range.
2. Wait for price to sweep liquidity above or below that range.
3. Wait for a market structure shift in the opposite direction.
4. Display a potential LONG or SHORT setup.
5. Draw entry, stop loss, take profit and risk/reward zones.
6. Send an alert when the setup condition appears.

The script also includes additional visual context tools:

* London and New York session markers,
* London and New York session backgrounds,
* Order Blocks,
* PDH and PDL levels,
* CHoCH and BOS visual structure,
* 14:15 Warsaw time reminder label,
* dynamic alert message with entry, SL, TP and R:R.

Although the title includes [M5], the script can technically be applied to other timeframes. However, the model was designed with a lower-timeframe intraday workflow in mind, especially around the 5-minute chart.

1. Market Type: Crypto vs Traditional Market

The script includes two different risk calculation modes:

Crypto
Traditional Market

This setting changes how the stop loss and take profit are calculated after a valid setup appears.

Crypto mode

In Crypto mode, the script uses fixed percentage-based targets.

The take profit is calculated using the TP % input.

The stop loss is calculated as a fraction of that TP distance using the Risk:Reward / SL Divisor input.

Example with default settings:

TP = 2.5%
SL divisor = 3.0
Estimated SL distance = 2.5% / 3.0 = approximately 0.83%

For a long setup:

TP is placed above the entry price by the selected percentage.
SL is placed below the entry price by the calculated percentage.

For a short setup:

TP is placed below the entry price by the selected percentage.
SL is placed above the entry price by the calculated percentage.

This mode is designed for markets where percentage-based risk and target planning may be more practical, such as crypto.

Traditional Market mode

In Traditional Market mode, the script uses a structural stop loss.

For a long setup, the stop loss is placed at the lowest price reached during the downside sweep.

For a short setup, the stop loss is placed at the highest price reached during the upside sweep.

The take profit is then calculated mathematically using the selected Risk:Reward multiplier.

Example:

If the entry is 100, the structural stop is 99 and the selected R:R is 3.0, the risk is 1 point and the take profit is placed 3 points away from the entry.

This creates a 1:3 risk/reward projection.

This mode is designed for more traditional markets such as gold, indices, forex or futures, where traders may prefer structure-based stop placement.

2. New York time range and trade window

The model uses New York time for its core setup logic.

The script has two main time windows:

Opening Range
Trade Session

Default Opening Range:

03:00 - 04:00 New York time

Default Trade Session:

04:00 - 16:00 New York time

The opening range is the range the script tracks before looking for a sweep.

During this range window, the script records:

* range high,
* range low,
* range start,
* range box,
* range label.

Once the range is created, the script extends the box visually to the selected hour in Warsaw time.

The trade session is the time window where the script is allowed to detect sweeps and generate LONG or SHORT setup signals.

Signals are not generated outside the selected trade session.

3. Opening range box

At the beginning of the selected range session, the indicator starts building a range box.

The box tracks the high and low formed during the opening range.

As new candles appear inside the range session, the box updates:

* if price makes a higher high, the top of the box moves up,
* if price makes a lower low, the bottom of the box moves down.

The box is labeled “Otwarcie rynku”.

The range box is extended to a user-selected hour based on Warsaw time. This allows the trader to keep the opening range visible throughout the day.

The purpose of this box is to define the initial liquidity range. The later setup logic depends on whether price sweeps above or below this range.

4. Sweep logic

The sweep is the first key condition of the model.

After the opening range is built, the script waits for price to take liquidity above or below the range.

Upside sweep

An upside sweep occurs when price trades above the opening range high.

When this happens, the script marks that the high side has been swept.

The script then tracks the highest price reached during that upside sweep. This value is later used as the structural stop loss in Traditional Market mode for short setups.

After an upside sweep, the model looks for a bearish reversal confirmation.

Downside sweep

A downside sweep occurs when price trades below the opening range low.

When this happens, the script marks that the low side has been swept.

The script then tracks the lowest price reached during that downside sweep. This value is later used as the structural stop loss in Traditional Market mode for long setups.

After a downside sweep, the model looks for a bullish reversal confirmation.

One-side sweep rule

The script is designed to track only the first swept side of the range.

If the high side is swept first, the low-side sweep condition is blocked for that setup cycle.

If the low side is swept first, the high-side sweep condition is blocked for that setup cycle.

This creates a cleaner one-direction setup model and avoids conflicting signals from both sides of the range during the same trade session.

5. MSS logic for entries

After a sweep occurs, the script waits for a Market Structure Shift.

This MSS logic is separate from the visual CHoCH/BOS module.

The entry logic uses its own pivot settings:

MSS Left Side
MSS Right Side

These settings define the swing highs and swing lows used specifically for setup confirmation.

Long setup logic

A long setup can appear only after price sweeps below the opening range low.

After the downside sweep, the script waits for price to close/cross above the latest MSS swing high.

When price crosses above that swing high, the script marks a LONG setup.

Short setup logic

A short setup can appear only after price sweeps above the opening range high.

After the upside sweep, the script waits for price to close/cross below the latest MSS swing low.

When price crosses below that swing low, the script marks a SHORT setup.

This creates a sweep-and-reverse model:

Sweep low → reclaim structure → LONG
Sweep high → lose structure → SHORT

6. Trade taken control

The script includes a tradeTaken variable.

Once a valid LONG or SHORT setup appears, tradeTaken becomes true.

This prevents the indicator from generating multiple entries from the same range cycle.

The logic is designed to show one main setup after the selected range is swept and confirmed.

At the start of a new range session, the script resets:

* sweep state,
* extreme high,
* extreme low,
* tradeTaken,
* range high,
* range low.

This prepares the model for the next session cycle.

7. Stop Loss and Take Profit in Crypto mode

In Crypto mode, SL and TP are calculated using fixed percentages.

The input TP % controls the target distance.

The SL distance is calculated by dividing the TP percentage by the selected SL divisor.

For long setups:

TP = entry price × (1 + TP %)
SL = entry price × (1 - TP % / divisor)

For short setups:

TP = entry price × (1 - TP %)
SL = entry price × (1 + TP % / divisor)

This mode makes the risk model independent from the sweep extreme.

It is useful when the trader wants the same percentage-based target and stop distance across crypto markets.

8. Stop Loss and Take Profit in Traditional Market mode

In Traditional Market mode, the stop loss is based on the sweep extreme.

For long setups:

SL = lowest price reached during the downside sweep

For short setups:

SL = highest price reached during the upside sweep

The script then calculates the risk distance.

For long:

Risk = entry price - SL

For short:

Risk = SL - entry price

The take profit is calculated by multiplying the risk by the selected Risk:Reward value.

For long:

TP = entry price + risk × R:R

For short:

TP = entry price - risk × R:R

If the structural risk becomes invalid or equal to zero, the script uses ATR as a fallback buffer. This protects the calculation from technical cases where the entry and structural stop are too close or incorrectly aligned.

9. Minimum Risk:Reward filter

The script includes a Minimum Risk:Reward filter.

A setup is accepted only if the calculated reward-to-risk ratio is equal to or greater than the selected minimum.

This helps filter out setups where the target does not justify the risk according to the trader’s selected settings.

The default minimum R:R is 1.0.

If the calculated setup does not meet the minimum R:R requirement, the signal is not displayed.

10. Visual LONG and SHORT signals

When a valid setup appears, the script plots a visible entry marker on the chart.

LONG signal:

A green triangle is plotted below the candle.
The text “LONG” is displayed.

SHORT signal:

A red triangle is plotted above the candle.
The text “SHORT” is displayed.

These markers identify candles where the model conditions are met.

They are visual setup markers only. They do not guarantee that price will reach the target or respect the stop level.

11. Entry, SL and TP visualization

When a setup appears and target drawing is enabled, the script draws:

* entry line,
* stop loss line,
* take profit line,
* risk zone,
* reward zone,
* SL label,
* TP label.

The entry line is displayed as a grey dashed line.

The stop loss line is displayed as a red solid line.

The take profit line is displayed as a green solid line.

The risk zone shows the distance between entry and stop loss.

The reward zone shows the distance between entry and take profit.

This gives the trader a clear visual map of the setup structure.

12. Risk and reward boxes

The script draws two boxes after each valid signal.

Risk box

The risk box covers the area between entry and stop loss.

Reward box

The reward box covers the area between entry and take profit.

The boxes extend a fixed number of bars to the right.

This makes it easy to review how the projected setup looks immediately after the signal.

The box colors are customizable in the settings.

13. Dynamic SL and TP percentage labels

The indicator calculates the percentage distance between entry and SL, and between entry and TP.

For long setups:

SL is displayed as a negative percentage.
TP is displayed as a positive percentage.

For short setups:

SL is displayed as a positive percentage.
TP is displayed as a negative percentage.

This makes the visual setup easier to understand because the trader can immediately see the approximate percentage risk and target distance.

14. Alert system

The script includes two alert mechanisms.

Static alertcondition

The script provides a TradingView alert condition titled:

Gold Pray - ENTRY

The message tells the user that an entry setup is ready and that the direction and SL/TP levels are visible on the chart.

Dynamic alert()

When an entry signal appears, the script also creates a dynamic alert message.

The dynamic alert includes:

* market type,
* direction,
* entry price,
* stop loss,
* take profit,
* SL percentage,
* TP percentage,
* actual Risk:Reward.

Example information included in the alert:

LONG or SHORT
Entry price
SL level
TP level
R:R value

The dynamic alert is sent once per bar close.

Alerts are informational only. They do not guarantee execution price, fill quality, slippage or trade outcome.

15. London and New York session markers

The indicator includes visual session markers based on Warsaw time.

Default London open marker:

09:00 - 09:05 Warsaw time

Default New York open marker:

15:30 - 15:35 Warsaw time

When the script detects the start of these windows, it draws a vertical dashed line.

It also adds a label:

“Londyn” for London open
“Nowy Jork” for New York open

These markers are designed to help traders orient themselves around the major market opens.

They are visual timing references only.

16. London and New York session backgrounds

The script can also shade full London and New York sessions.

Default London full session:

09:00 - 17:30 Warsaw time

Default New York full session:

15:30 - 22:00 Warsaw time

London background and New York background colors can be customized.

If New York and London overlap, the New York background has priority in the script’s background display logic.

The session background makes it easier to visually separate different parts of the trading day.

17. Order Blocks module

The indicator includes a simple Order Block visualization module.

Bullish Order Block logic

A bullish OB is created when:

* the current candle is a strong bullish impulse,
* the current candle body is larger than 1.5 × ATR,
* the previous candle was bearish.

The OB box is drawn around the previous candle.

Bearish Order Block logic

A bearish OB is created when:

* the current candle is a strong bearish impulse,
* the current candle body is larger than 1.5 × ATR,
* the previous candle was bullish.

The OB box is drawn around the previous candle.

The script keeps up to five bullish OBs and five bearish OBs in active tracking.

Order Block boxes are extended forward while active.

When price returns into a tracked OB area, the box stops being actively extended by the script.

This OB module is simplified and should be treated as visual context, not as a complete institutional order flow model.

18. PDH and PDL module

The script can display:

PDH — Previous Day High
PDL — Previous Day Low

These levels are pulled from the previous daily candle.

When enabled, the indicator draws dashed horizontal lines for PDH and PDL.

Labels are added next to the lines.

The user can choose whether to hide historical PDH/PDL levels.

When historical PDH/PDL hiding is enabled, the previous lines are removed at the start of a new day, leaving only the most recent previous-day high and low.

These levels can be useful as liquidity reference points, but they are not trade signals by themselves.

19. Visual CHoCH and BOS module

The indicator includes a separate visual structure module for CHoCH and BOS.

This module is independent from the MSS logic used for entries.

It uses its own pivot settings:

Structure Pivot Left
Structure Pivot Right

When price crosses above the last detected structural swing high, the script draws a horizontal line and a label.

When price crosses below the last detected structural swing low, the script also draws a line and a label.

The label is determined by the previous structure trend:

If price breaks in the same direction as the previous structure, the label is BOS.

If price breaks against the previous structure direction, the label is CHoCH.

This module is for visual analysis only and does not generate separate alerts.

20. CHoCH and BOS customization

The structure module can be customized with:

* show/hide CHoCH and BOS,
* pivot left setting,
* pivot right setting,
* line and label color,
* line style.

Available line styles:

Solid
Dashed
Dotted

Higher pivot values produce fewer but more significant structure marks.

Lower pivot values produce more frequent structure marks but may create more noise.

21. Difference between MSS and visual CHoCH/BOS

This script uses two different structure systems.

MSS for entries

The MSS logic is used to confirm the actual sweep-and-reverse setup.

It uses the “MSS Left Side” and “MSS Right Side” settings.

This is the structure logic that affects LONG and SHORT signals.

Visual CHoCH/BOS

The CHoCH/BOS module is used for chart reading and visual context.

It uses the separate “Structure Pivot Left” and “Structure Pivot Right” settings.

It does not directly trigger the entry signal.

This separation is important because changing visual structure settings does not necessarily change entry logic, and changing MSS settings does not necessarily change visual CHoCH/BOS labels.

22. 14:15 Warsaw time label

The script includes a visual reminder label at 14:15 Warsaw time.

The label appears only on weekdays.

It displays:

⏰ 14:15 PL

This is only a visual time marker. It does not create an alert and does not affect the entry logic.

The purpose of this label is to help the trader notice a specific time of day, for example before important market preparation, session transition or scheduled analysis.

23. Best use cases

This indicator may be useful for traders who want to:

* analyze opening range behavior,
* identify liquidity sweeps,
* wait for market structure shift confirmation,
* visualize potential reversal setups,
* compare crypto percentage-based risk with structure-based risk,
* mark London and New York sessions,
* observe PDH and PDL,
* add simplified Order Block context,
* display CHoCH and BOS structure,
* receive alerts when a full entry setup appears.

The model is especially suitable for traders who prefer a structured intraday workflow rather than random entries.

24. Suggested workflow

A possible workflow for using this indicator:

First, let the opening range form.

Second, wait for price to sweep above or below the range.

Third, observe whether price continues or begins to reverse.

Fourth, wait for the MSS confirmation.

Fifth, review the displayed entry, SL, TP and R:R.

Sixth, confirm the setup with your own higher-timeframe bias, market context, liquidity analysis and risk management.

The signal should be treated as a setup notification, not as automatic trade advice.

25. Important limitations

This script does not predict the market.

A sweep does not guarantee reversal.

A market structure shift does not guarantee continuation.

An Order Block does not guarantee a reaction.

PDH and PDL are reference levels, not automatic entry levels.

The visual LONG and SHORT markers are model-based setup signals, not guaranteed profitable trades.

The script does not know about:

* economic news,
* spreads,
* slippage,
* liquidity conditions,
* broker execution,
* commissions,
* higher-timeframe trend,
* macro context,
* manual discretion,
* real order flow.

The trader is responsible for deciding whether a setup is valid enough to trade.

26. Timezone notes

The core opening range and trade session use New York time.

The London and New York visual session markers use Warsaw time.

The range box extension also uses Warsaw time.

Because the script combines New York and Warsaw time logic, traders should check their chart and symbol data carefully, especially around daylight saving time changes.

27. Object limits

The indicator uses TradingView drawing objects such as:

* lines,
* boxes,
* labels,
* shapes.

TradingView has limits for chart drawings created by Pine scripts.

The script includes object management in some modules, such as Order Blocks and PDH/PDL, but users should still keep the chart clean and avoid running too many object-heavy scripts at the same time.

28. Educational disclaimer

This script is provided for educational and analytical purposes only.

It is not financial advice, investment advice or a recommendation to buy or sell any market.

Trading involves risk.

Past behavior on the chart does not guarantee future results.

Always test the model on your own market, timeframe and data before using it in live trading.

29. Summary

Gold Pray Model - Sweep & Reverse [M5] is a structured intraday indicator that combines:

* opening range logic,
* liquidity sweep detection,
* market structure shift confirmation,
* crypto and traditional market risk modes,
* visual SL/TP projections,
* dynamic entry alerts,
* session visualization,
* PDH/PDL levels,
* simplified Order Blocks,
* CHoCH/BOS market structure,
* 14:15 Warsaw time marker.

The goal of the tool is to help traders organize a repeatable sweep-and-reversal model on the chart.

It should be used as a decision-support tool, not as an automatic trading system.

כתב ויתור

המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.