PROTECTED SOURCE SCRIPT

Morning Straddle Backtest + Range Filter

61
Morning Straddle Backtest

Purpose:
This script tests a Morning Straddle concept where a trader enters both long and short breakout orders based on the overnight range (22:00–06:00 by default).
It is designed for backtesting the effectiveness of volatility breakouts following low-volume overnight sessions.

Setup

Overnight session: 22:00–06:00 (adjustable).

At the end of the overnight session, the script automatically places:

A long stop order above the range high.

A short stop order below the range low.

Both use an ATR-based buffer for cleaner breakouts (default 5%).

When one side triggers, the opposite order is cancelled if OCO mode is active.

Adjustable Parameters

- Session - Defines the overnight hours used for the range.

- ATR Length - Number of bars used for ATR calculation.

- ATR Buffer % - Distance above/below range for entry & stop placement.

- Risk:Reward Ratio - Determines the TP distance relative to SL.

- Stop-Loss - Choose between “Behind Range” or “Mid-Range (50%)” with ATR buffer added.

- OCO - Cancels opposite order once one side triggers.

- Close All EOD - Closes all open trades at the end of day (default 22:00).

- Range Filter – Enables filtering of trades only when the overnight range size falls within a defined threshold.
-Min Range / Max Range – Define acceptable range size boundaries.
-Display Units – Select whether the filter is measured in Price Change, Pips, or Points.

- Stats Panel Settings – Toggle visibility, position (Top/Bottom Left/Right), and background opacity.

Visual

The overnight range (22:00–06:00) is highlighted on the chart with a teal background for clarity.

No lines are drawn for the high and low.

Strategy Notes

Works best on 5m or 15m charts where the overnight range can be clearly defined.

Backtests should be run over multiple months to gauge performance consistency.

Can be adapted for other markets by adjusting session times and ATR settings. For example, S&P initial balance breakout using 14:30-15:30 range time.

Stats Panel Displays

- 20-Day Range Data: Maximum, Average, and Minimum range sizes.

- Today’s Range: With automatic classification — Huge, Normal, or Small.

- Average Winning Range: Average size of the overnight range on profitable days.

- Average Losing Range: Average size of the overnight range on losing days.

- Filter Status: Displays whether the range met the filter criteria — Range OK, Skipped, or Off.

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.