Indicator · Pine Script v5 · On the chart

1DTE

by tyler314· code credited to tjroberts314

1DTE is an overlay indicator designed for 1-day-to-expiration option trading analysis.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code179
Settings27inputs
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

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

1dte.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © tjroberts314

//@version=5
indicator("1dte", overlay=true)
import tjroberts314/Utils/1

daysInARow = input.int(1, "Successive Bars in a Row", minval=1, maxval=10)
atr_range = input.float(1.0, "ATR value", minval=0, maxval=3, step=0.1)
toggle_mod = input.bool(true, "Modify atr", inline="0", group="toggles")
toggle_vix = input.bool(false, "Modify VIX", inline="0", group="toggles")
toggle_monday = input.bool(true, "Monday DTE", inline="0", group="toggles")
toggle_wednesday = input.bool(true, "Wednesday DTE", inline="0", group="toggles")
toggle_friday = input.bool(true, "Friday DTE", inline="0", group="toggles")
vix_limit = input.int(title="vix limit", defval=22, minval=1, maxval=40)

vix = request.security("VIX", timeframe.period, close)

put1 = input.float(1.8, "1 red day", minval=0.0, maxval=2, step=0.1, inline="1", group="put mod")
put2 = input.float(1.4, "2 red day", minval=0.0, maxval=2, step=0.1, inline="1", group="put mod")
put3 = input.float(1.3, "3 red day", minval=0.0, maxval=2, step=0.1, inline="1", group="put mod")
put4 = input.float(1.0, "4 red day", minval=0.0, maxval=2, step=0.1, inline="1", group="put mod")

call1 = input.float(1.8, "1 green day", minval=0.0, maxval=2, step=0.1, inline="2", group="call mod")
call2 = input.float(1.4, "2 green day", minval=0.0, maxval=2, step=0.1, inline="2", group="call mod")
call3 = input.float(1.3, "3 green day", minval=0.0, maxval=2, step=0.1, inline="2", group="call mod")
call4 = input.float(1.0, "4 green day", minval=0.0, maxval=2, step=0.1, inline="2", group="call mod")

// VIX Mods
put1_vix = input.float(1.8, "1 red day", minval=0.0, maxval=2, step=0.1, inline="3", group="put mod - vix")
put2_vix = input.float(1.4, "2 red day", minval=0.0, maxval=2, step=0.1, inline="3", group="put mod - vix")
put3_vix = input.float(1.3, "3 red day", minval=0.0, maxval=2, step=0.1, inline="3", group="put mod - vix")
put4_vix = input.float(1.0, "4 red day", minval=0.0, maxval=2, step=0.1, inline="3", group="put mod - vix")

call1_vix = input.float(1.8, "1 green day", minval=0.0, maxval=2, step=0.1, inline="4", group="call mod - vix")
call2_vix = input.float(1.4, "2 green day", minval=0.0, maxval=2, step=0.1, inline="4", group="call mod - vix")
call3_vix = input.float(1.3, "3 green day", minval=0.0, maxval=2, step=0.1, inline="4", group="call mod - vix")
call4_vix = input.float(1.0, "4 green day", minval=0.0, maxval=2, step=0.1, inline="4", group="call mod - vix")

redStreak = true
greenStreak = true
rsi_value = ta.rsi(close, 14)
PROFIT = 25 / atr_range
LOSS = 500 - PROFIT

var float sucCnt = 0
var float totalCnt = 0
var int callWins = 0
var int callLosses = 0
var int putWins = 0
var int putLosses = 0
var float seedValue = 0
var float profit = 0
var float loss = 0


startDate = input.time(title="Start Date", defval=timestamp("01 Jan 2015 13:30 +0000"))
endDate = input.time(title="End Date", defval=timestamp("01 Jan 2024 19:30 +0000"))
timeSession = input.session(title="Time Session to Analyze", defval="0600-0915")
window() => time >= startDate and time <= endDate ? true : false
validDayOfWeek() => (dayofweek == dayofweek.monday and toggle_monday) or (dayofweek == dayofweek.wednesday and toggle_wednesday) or (dayofweek == dayofweek.friday and toggle_friday)
valid_VIX() => vix <= vix_limit
canTrade1dte() =>
    if toggle_vix
        validDayOfWeek() and valid_VIX()
    else
        validDayOfWeek()

green_cnt = 0
red_cnt = 0

for day = 1 to daysInARow
    if close[day] <= open[day]
        greenStreak := false
        break

for day = 1 to daysInARow
    if close[day] >= open[day]
        redStreak := false
        break

for day = 1 to 50
    if close[day] <= open[day]
        break
    green_cnt += 1

for day = 1 to 50
    if close[day] >= open[day]
        break
    red_cnt += 1

atr = ta.atr(14)
if toggle_mod and toggle_vix
    if 0 < red_cnt
        if red_cnt == 1
            atr *= put1_vix // 0.4
        else if red_cnt == 2
            atr *= put2_vix // 0.3
        else if red_cnt == 3
            atr *= put3_vix // 0.2
        else
            atr *= put4_vix // 0.1
    else if 0 < green_cnt
        if green_cnt == 1
            atr *= call1_vix
        else if green_cnt == 2
            atr *= call2_vix
        else if green_cnt == 3
            atr *= call3_vix
        else
            atr *= call4_vix
    else
        atr *= atr_range
else if toggle_mod
    if 0 < red_cnt
        if red_cnt == 1
            atr *= put1 // 0.4
        else if red_cnt == 2
            atr *= put2 // 0.3
        else if red_cnt == 3
            atr *= put3 // 0.2
        else
            atr *= put4 // 0.1
    else if 0 < green_cnt
        if green_cnt == 1
            atr *= call1
        else if green_cnt == 2
            atr *= call2
        else if green_cnt == 3
            atr *= call3
        else
            atr *= call4
    else
        atr *= atr_range
else
    atr *= atr_range

putProfit = (close[1] - atr) < close
callProfit = (close[1] + atr) > close

plotshape(canTrade1dte() and window() and redStreak and putProfit, title="PUT", style=shape.triangleup, location=location.belowbar, color=color.green)
plotshape(canTrade1dte() and window() and redStreak and not putProfit, title="PUT", style=shape.triangledown, location=location.belowbar, color=color.red)

plotshape(canTrade1dte() and window() and greenStreak and callProfit, title="CALL", style=shape.triangleup, location=location.abovebar, color=color.green)
plotshape(canTrade1dte() and window() and greenStreak and not callProfit, title="CALL", style=shape.triangledown, location=location.abovebar, color=color.red)

if window() and canTrade1dte()
    if redStreak and putProfit
        putWins += 1
        profit += PROFIT
    else if greenStreak and callProfit
        callWins += 1
        profit += PROFIT
    else if redStreak and not putProfit
        putLosses += 1
        loss += LOSS
    else if greenStreak and not callProfit
        callLosses += 1
        loss += LOSS

float totalWins = callWins + putWins
float successRate = totalWins / (totalWins + callLosses + putLosses)

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 = "Put Wins", text_color = color.gray)
    table.cell(table_id = tableDisplay, column = 0, row = 2, text = "Put Losses", text_color = color.gray)
    table.cell(table_id = tableDisplay, column = 0, row = 3, text = "Call Wins", text_color = color.gray)
    table.cell(table_id = tableDisplay, column = 0, row = 4, text = "Call 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(putWins), text_color = color.gray)
    table.cell(table_id = tableDisplay, column = 1, row = 2, text = str.tostring(putLosses), text_color = color.gray)
    table.cell(table_id = tableDisplay, column = 1, row = 3, text = str.tostring(callWins), text_color = color.gray)
    table.cell(table_id = tableDisplay, column = 1, row = 4, text = str.tostring(callLosses), text_color = color.gray)
    table.cell(table_id = tableDisplay, column = 1, row = 5, text = str.tostring(profit - loss), text_color = color.gray)

Overview

1DTE evaluates market conditions using Average True Range (ATR), consecutive green or red daily streaks, and CBOE Volatility Index (VIX) levels. Users can filter evaluation windows by specific days of the week, session times, and date ranges. The script adjusts trade parameters based on streak duration and volatility thresholds, assisting in structural analysis for short-term options strategies directly on the main price chart.

Details

Published by

tyler314 on GitHub

Code credit

tjroberts314, as written in the script's header

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Volatility & bands, Sessions & time

Markets

Indices, Stocks

Timeframes

M15-H1, H4 and above

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
Successive Bars in a Rowint1daysInARow
ATR valuefloat1.0atr_range
Modify atrbooltruetoggle_mod
Modify VIXboolfalsetoggle_vix
Monday DTEbooltruetoggle_monday
Wednesday DTEbooltruetoggle_wednesday
Friday DTEbooltruetoggle_friday
vix limitint22vix_limit
1 red dayfloat1.8put1
2 red dayfloat1.4put2
3 red dayfloat1.3put3
4 red dayfloat1.0put4
Show all 27 settings
SettingTypeDefaultVariable
1 green dayfloat1.8call1
2 green dayfloat1.4call2
3 green dayfloat1.3call3
4 green dayfloat1.0call4
1 red dayfloat1.8put1_vix
2 red dayfloat1.4put2_vix
3 red dayfloat1.3put3_vix
4 red dayfloat1.0put4_vix
1 green dayfloat1.8call1_vix
2 green dayfloat1.4call2_vix
3 green dayfloat1.3call3_vix
4 green dayfloat1.0call4_vix
Start Datetimetimestamp("01 Jan 2015 13:30 +0000")startDate
End Datetimetimestamp("01 Jan 2024 19:30 +0000")endDate
Time Session to Analyzesession0600-0915timeSession
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 8 weeks 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 7 weeks ago · None stated GitHub repository of AM TBR — NQ Stats

LoD Intraday Entry

by ChartsLector
41 stars

This overlay indicator marks the current day's low and a suggested entry zone a fraction of daily ATR below that low. It compares daily volume with a volume moving average, plots daily SMA and EMA distance, and draws an optional ATR-width price cloud. Labels c

Indicator v6 Support & resistanceVolatility & bands
Updated 2 days ago · None stated GitHub repository of LoD Intraday Entry

Zen Toolkit ETH

by Zen-Tim
29 stars

This indicator plots intraday reference levels, projection targets, and opening range boundaries tailored for continuous electronic trading session instruments such as gold. It calculates Average Bar Range targets in bullish and bearish multiples, previous day

Indicator v6 Support & resistanceSessions & time
Updated 2 weeks ago · MIT GitHub repository of Zen Toolkit ETH

This indicator combines six trading tools into a single chart overlay to optimize indicator limits. It calculates Bollinger Bands, projects weekend price boundaries, plots market structure elements like order blocks, breaker blocks, and MSB lines, marks New Yo

Indicator v6 Support & resistanceSMC / ICT / price action Repaints

More indicators

Trade Your Charts With a Regulated Broker

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

Compare brokers