Indicator · Pine Script v5 · On the chart

0DTE IF

by tyler314· code credited to ajalbertin

This indicator simulates zero-day-to-expiration options trades by plotting scheduled entry and exit shapes directly on the price chart.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code86
Settings8inputs
LicenceNone statedfile: MPL-2.0
Last update4 years ago4 Apr 2022

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

86 lines of Pine Script v5 from scripts/0dte_if.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

0dte_if.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ajalbertin

//@version=5
indicator("0DTE_IF",overlay=true)

// Constants
var float profit = 0
var int wins = 0
var int losses = 0
CANDLE_WIDTH = 3 //int(math.round(str.tonumber(timeframe.period)))
MAX_GAIN = 150
MAX_LOSS = 300
atr = ta.atr(14)
var bool is_trade_open = false

// Input
hour_enter = input.int(title="hour", defval=10, minval=9, maxval=15, inline="0", group="enter time")
minute_enter = input.int(title="minute", defval=30, minval=0, maxval=59, step=CANDLE_WIDTH, inline="0", group="enter time")
hour_exit = input.int(title="hour", defval=11, minval=9, maxval=15, inline="1", group="exit time")
minute_exit = input.int(title="minute", defval=30, minval=0, maxval=59, step=CANDLE_WIDTH, inline="1", group="exit time")

vix_limit = input.int(title="vix limit", defval=22, minval=1, maxval=40)
change_in_SPX = input.int(title="change in SPX", defval=10, minval=1, maxval=200)

startDate = input.time(title="Start Date", defval=timestamp("01 Jan 2022 13:30 +0000"))
endDate = input.time(title="End Date", defval=timestamp("01 Jan 2024 19:30 +0000"))
window() => time >= startDate and time <= endDate ? true : false

// Functions
print(string txt) =>
    // Create label on the first bar.
    var lbl = label.new(bar_index, na, txt, xloc.bar_index, yloc.price, color(color.white), label.style_none, color.white, size.large, text.align_left)
    // On next bars, update the label's x and y position, and the text it displays.
    label.set_xy(lbl, bar_index, ta.highest(10)[1])
    label.set_text(lbl, txt)

valid_day_of_week() => dayofweek == dayofweek.monday or dayofweek.wednesday or dayofweek.friday
valid_time(hour_arg, minute_arg) => timestamp(year, month, dayofweek, hour, minute) == timestamp(year, month, dayofweek, hour_arg, minute_arg) and window()
valid_VIX() => request.security("VIX", str.tostring(CANDLE_WIDTH), close) <= vix_limit

get_minutes_past_enter() =>
    start_time_in_minutes = (hour_enter * 60) + minute_enter
    current_time_in_minutes = (hour * 60) + minute
    diff = current_time_in_minutes - start_time_in_minutes
    if diff < 0
        0
    else
        diff

can_enter_trade() => valid_day_of_week() and valid_time(hour_enter, minute_enter) and valid_VIX()
can_exit_trade() => valid_day_of_week() and valid_time(hour_exit, minute_exit) 

// MAIN FUNCTION - START HERE
points_changed_since_enter = math.abs(close[0] - close[int(get_minutes_past_enter()/CANDLE_WIDTH)])
is_win() => points_changed_since_enter  <= change_in_SPX
is_loss() => points_changed_since_enter > change_in_SPX

plotshape(can_enter_trade(), title="CALL", style=shape.triangleup, location=location.abovebar, color=color.green)
plotshape(is_trade_open and can_exit_trade(), title="CALL", style=shape.triangledown, location=location.abovebar, color=color.purple)

if can_enter_trade() == true
    is_trade_open := true

if is_trade_open == true and can_exit_trade()
    if is_win()
        profit += MAX_GAIN
        wins += 1
    if is_loss()
        profit -= MAX_LOSS
        losses += 1
    is_trade_open := false
   
successRate = wins / (wins + losses)   

var table tableDisplay = table.new(position.bottom_right, columns = 2, rows = 6, frame_color= color.gray, frame_width = 2, border_width = 2, border_color = color.gray)
if barstate.islast
    table.cell(table_id = tableDisplay, column = 0, row = 0, text = "Success Rate", text_color = color.gray)
    table.cell(table_id = tableDisplay, column = 0, row = 1, text = "Wins", text_color = color.gray)
    table.cell(table_id = tableDisplay, column = 0, row = 2, text = "Losses", text_color = color.gray)
    table.cell(table_id = tableDisplay, column = 0, row = 5, text = "Final Balance", text_color = color.gray)
    
    table.cell(table_id = tableDisplay, column = 1, row = 0, text = str.tostring(successRate), text_color = color.gray)
    table.cell(table_id = tableDisplay, column = 1, row = 1, text = str.tostring(wins), text_color = color.gray)
    table.cell(table_id = tableDisplay, column = 1, row = 2, text = str.tostring(losses), text_color = color.gray)
    table.cell(table_id = tableDisplay, column = 1, row = 5, text = str.tostring(profit), text_color = color.gray)

Overview

0DTE IF signals entries on Mondays, Wednesdays, and Fridays at a user-defined time when the VIX remains below a specified limit. Exits trigger at a designated exit time, evaluating trade success if index movement stays within an allowed point change threshold. Key inputs configure entry and exit hours, VIX limits, point tolerance, and a backtesting date window. Results display in a corner dashboard table, though simulated outcomes rely on fixed payout amounts rather than dynamic orders.

Details

Published by

tyler314 on GitHub

Code credit

ajalbertin, as written in the script's header

Draws

On the price chart

Markets

Indices

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
hourint10hour_enter
minuteint30minute_enter
hourint11hour_exit
minuteint30minute_exit
vix limitint22vix_limit
change in SPXint10change_in_SPX
Start Datetimetimestamp("01 Jan 2022 13:30 +0000")startDate
End Datetimetimestamp("01 Jan 2024 19:30 +0000")endDate
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

92 stars

This indicator classifies the market into gamma regime types (negative gamma trend, positive gamma mean-reversion, or transition) by calculating a composite score based on daily ATR ratios, session VWAP crossover frequencies, and opening range displacement. It

Indicator v5 Volatility & bandsTrend
Updated 2 months ago · Custom licence GitHub repository of Moon Dev GEX Regime & Trap
56 stars

This indicator marks forex trading sessions and opening ranges on the price chart. It can draw Sydney, Tokyo, Frankfurt, London, and New York session boxes or five- and fifteen-minute opening ranges, plus an optional opening channel and a day-open range. Day r

Indicator v5 Sessions & timeSupport & resistance Repaints
Updated 2 months ago · None stated GitHub repository of Day Trading Booster by DGT

AM TBR — NQ Stats

by TamaraKGreen
46 stars

The AM TBR indicator calculates statistical levels for NQ futures using standard deviation. It plots a sigma ladder showing touch levels at 0.5 to 2.0 standard deviations, marks touch points, displays Mean Absolute Error (MAE) zones after touches, and shows Me

Indicator v6 Volatility & bandsSupport & resistance
Updated 8 weeks ago · None stated GitHub repository of AM TBR — NQ Stats

Zen Trading Toolkit

by Zen-Tim
29 stars

This indicator plots average bar range (ABR) measured move targets, opening range boxes, and historical key reference levels directly on the price chart. It projects bullish and bearish targets (0.5x, 1.0x, 1.5x, 2.0x ABR) from the previous session's close, al

Indicator v6 Support & resistanceVolatility & bands
Updated 2 weeks ago · MIT GitHub repository of Zen Trading Toolkit
9 stars

Peak Trading Activity Graphs displays historical market activity across cyclical timeframes directly on the main chart using an on-screen dashboard table. It evaluates volume or volatility across selected periods, including hours of the day, days of the week,

Indicator v6 VolumeVolatility & bands
Updated 4 months ago · MIT GitHub repository of Peak Trading Activity Graphs [LuxAlgo]

More Sessions & time scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers