Indicator · Pine Script v5 · On the chart

Donald SPX - Options Trading

by dearvn· code credited to donaldit.net

Donald SPX - Options Trading is an overlay indicator designed for intraday SPX analysis.

View on GitHub

Repaints

GitHub stars257on the repository
Pine versionv5runs as is
Lines of code191
Settings0inputs
LicenceNone statedfile: MPL-2.0
Last update6 weeks ago11 Sep 2026

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

191 lines of Pine Script v5 from SPX-options-new-logic.txt, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

SPX-options-new-logic.txt
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © donaldit.net

//@version=5
//@version=5
indicator(title="Donald SPX - Options Trading", shorttitle="Donald SPX - Options Trading", max_bars_back=4999, overlay = true)


var float open15_6h30 = na

var float wma200_last = na
var float open200_6h30 = na
var float wma200_yesterday = na
var float close200_yesterday = na
var float open15_6h45 = na

var int start_time_15h00 = na
var float open_ema_diff = 0.0
var float open_ema = 0.0

wma_200 = ta.wma(close, 200)

last_close_1d = request.security(symbol=syminfo.tickerid, timeframe="D", expression=close[1], lookahead=barmerge.lookahead_on)
close15 = request.security(symbol=syminfo.tickerid, timeframe="15", expression=close, lookahead=barmerge.lookahead_on)
open15 = request.security(symbol=syminfo.tickerid, timeframe="15", expression=open, lookahead=barmerge.lookahead_on)
close5 = request.security(symbol=syminfo.tickerid, timeframe="5", expression=close, lookahead=barmerge.lookahead_on)

wma200_15 = request.security(symbol=syminfo.tickerid, timeframe="15", expression=wma_200, lookahead=barmerge.lookahead_on)
close_2 = request.security(symbol=syminfo.tickerid, timeframe="2", expression=close, lookahead=barmerge.lookahead_on)
wma200_2 = request.security(symbol=syminfo.tickerid, timeframe="2", expression=wma_200, lookahead=barmerge.lookahead_on)
close_1d = request.security(symbol=syminfo.tickerid, timeframe="D", expression=close, lookahead=barmerge.lookahead_on)


plot(wma_200, title="WMA200", color=color.blue)


if hour(time_close, "UTC-8") == 13 and minute(time_close, "UTC-8") == 00 //and second(time_close, "UTC-8") == 00 //and dayofmonth(time_close, "UTC-7")<dayofmonth(timenow, "UTC-7")
    wma200_yesterday := wma200_2
    close200_yesterday := close_1d

if hour(time_close, "UTC-8") < 6 or hour(time_close, "UTC-8") == 6 and minute(time_close, "UTC-8") == 30 //and second(time_close, "UTC-8") == 00 //and dayofmonth(time_close, "UTC-7")<dayofmonth(timenow, "UTC-7")
    wma200_last := wma200_2
    open200_6h30 := close

if hour(time_close, "UTC-8") < 6 or hour(time_close, "UTC-8") == 6 and minute(time_close, "UTC-8") <= 45 and second(time_close, "UTC-8") == 00 //and dayofmonth(time_close, "UTC-7")<dayofmonth(timenow, "UTC-7")
    open15_6h45 := close15
    open15_6h30 := open15

//wma200_diff = close-wma200_15
wma200_diff = close_2 - wma200_2
wma200_diff15 = close15 - wma200_15
change_15m = open15_6h45 - open15_6h30


// IF EMA_DIFF MOVING FROM  0.50 to 0.10 THEN PUT
// TODO
var color clr1 = na
var string msg1 = na
var time_call1_arr = array.new_float()

if wma200_diff > -1.1
    if array.size(time_call1_arr) == 0
        array.push(time_call1_arr, wma200_diff)

if array.size(time_call1_arr) > 0
    if array.get(time_call1_arr, array.size(time_call1_arr)-1) > -1.1 and wma200_diff < -1.4
        time_call1_arr := array.new_float()
        msg1 := 'MARKET TRENDING CALL ...HOLD PUT'
        clr1 := #ffb52e


var float close_15h00 = 0.0
if hour(time_close, "UTC-8") == 15 and minute(time_close, "UTC-8") == 15 and second(time_close, "UTC-8") == 0 //and dayofmonth(time_close, "UTC-7")<dayofmonth(timenow, "UTC-7")
    close_15h00 := close15

var float close_6h30 = 0.0
if hour(time_close, "UTC-8") < 6 or hour(time_close, "UTC-8") == 6 and minute(time_close, "UTC-8") <= 30 and second(time_close, "UTC-8") == 0 //and dayofmonth(time_close, "UTC-7")<dayofmonth(timenow, "UTC-7")
    close_6h30 := close15

var string trend = ''
if close_6h30 > close_15h00
    trend := 'UP TREND'
if close_6h30 < close_15h00
    trend := 'DOWN TREND'

if barstate.islast
    // Make a new box that immediately uses the input's box style

    var table panel5 = table.new("bottom_right", 6, 50)
      
    table.cell(panel5, 0, 6)

    
    table.cell(panel5, 0, 1, str.format("Open 6h30: {0} Diff: {1}", open15_6h30, wma200_diff), bgcolor=color.new(#660990,70), text_color=color.white, width=20, text_halign=text.align_left)
    table.cell(panel5, 0, 3, str.format("Close 6h30: {0}", close_6h30), bgcolor=color.new(#660990,70), text_color=color.orange, width=20, text_halign=text.align_left)
    table.cell(panel5, 0, 4, str.format("ZERO - Close 15h00: {0}", close_15h00), bgcolor=color.new(#660990,70), text_color=color.orange, width=20, text_halign=text.align_left)
    table.cell(panel5, 0, 5, str.format("Trend: {0}", trend), bgcolor=color.new(#660990,70), text_color=color.blue, width=20, text_halign=text.align_left)
    
    table.cell(panel5, 0, 7, str.format("Change 6h30-6h45: {0}", change_15m), bgcolor=color.new(#660990,70), text_color=color.white, width=20, text_halign=text.align_left)
    table.cell(panel5, 0, 9, str.format("Close yesterday: {0}", close200_yesterday), bgcolor=color.new(#660990,70), text_color=color.white, width=20, text_halign=text.align_left)
    if str.format("{0}", syminfo.ticker) == 'SPX'
        table.cell(panel5, 0, 11, str.format("Strike trading: {0}", int(open15_6h45-open15_6h45%5)), bgcolor=color.new(#660990,70), text_color=color.yellow, width=20, text_halign=text.align_left)
    if str.format("{0}", syminfo.ticker) == 'SPY'
        table.cell(panel5, 0, 11, str.format("Strike trading: {0}", int(open15_6h45)), bgcolor=color.new(#660990,70), text_color=color.yellow, width=20, text_halign=text.align_left)
    

    //if msg1 != ''
    //    table.cell(panel5, 0, 6, str.format("{0}", msg1), bgcolor=color.new(clr1,70), text_color=color.white, width=30, text_halign=text.align_left)




//Create Box
line_len = 10
line_start = 4

line_len2 = line_len/2 + 2

box bx_ema = na
box bx_ema2 = na
box bx_ema3 = na
box bx_ema4 = na

box bx_ema1 = na
box bx_ema21 = na
box bx_ema31 = na
box bx_ema41 = na

label lbl_ema_open = na
label lbl_ema_current = na
label lbl_ema_high = na 
label lbl_ema_low = na 
label lbl_ema_yesterday = na

if hour(time, "UTC-8") == 15 and minute(time, "UTC-8") == 00
    start_time_15h00 := time //- 1800000 - 3600000*2
    

if barstate.islast
    // up trend
    padding_right = 4
        
    lbl_ema_yesterday := label.new(bar_index + line_len2+padding_right+1, close_15h00, str.format("ZERO: {0}", close_15h00), style = label.style_label_right, color = color.new(#660990, 90), textcolor = color.orange)
    label.delete(lbl_ema_yesterday[1])
    
    if close_6h30 > close_15h00 
        bx_ema := box.new(start_time_15h00, close_15h00 + 50, start_time_15h00+3600000*22, close_15h00, xloc=xloc.bar_time, bgcolor=color.new(#660990, 90), border_width=2, border_color=color.yellow)
        box.delete(bx_ema[1])

        bx_ema1 := box.new(start_time_15h00, close_15h00 + 37.5, start_time_15h00+3600000*22, close_15h00 + 37.6, xloc=xloc.bar_time, bgcolor=color.new(#660990, 90), border_width=1, border_color=color.yellow, border_style = line.style_solid)
        box.delete(bx_ema1[1])


        bx_ema2 := box.new(start_time_15h00, close_15h00 + 25, start_time_15h00+3600000*22, close_15h00 + 25.1, xloc=xloc.bar_time, bgcolor=color.new(#660990, 90), border_width=1, border_color=color.yellow, border_style = line.style_solid)
        box.delete(bx_ema2[1])

        bx_ema21 := box.new(start_time_15h00, close_15h00 + 12.5, start_time_15h00+3600000*22, close_15h00 + 12.6, xloc=xloc.bar_time, bgcolor=color.new(#660990, 90), border_width=1, border_color=color.yellow, border_style = line.style_solid)
        box.delete(bx_ema21[1])

        // line sperate
        lbl_ema_open := label.new(bar_index + line_len2+padding_right, close_15h00 + 50, str.format("TOP: {0}", close_15h00 + 50), style = label.style_label_right, color = color.new(#660990, 90), textcolor = color.orange)
        label.delete(lbl_ema_open[1])

        lbl_ema_current := label.new(bar_index + line_len2+padding_right, close_15h00 + 25, str.format("UP: {0}", close_15h00 + 25), style = label.style_label_right, color = color.new(#660990, 90), textcolor = color.orange)
        label.delete(lbl_ema_current[1])


    // down trend
    if close_6h30 <= close_15h00
        bx_ema3 := box.new(start_time_15h00, close_15h00, start_time_15h00+3600000*22, close_15h00 - 50, xloc=xloc.bar_time, bgcolor=color.new(#d1b5dd, 90), border_width=2, border_color=color.red)
        box.delete(bx_ema3[1])

        bx_ema31 := box.new(start_time_15h00, close_15h00 - 12.5, start_time_15h00+3600000*22, close_15h00 - 12.6, xloc=xloc.bar_time, bgcolor=color.new(#d1b5dd, 90), border_width=1, border_color=color.red, border_style = line.style_solid)
        box.delete(bx_ema31[1])

        bx_ema4 := box.new(start_time_15h00, close_15h00 - 25, start_time_15h00+3600000*22, close_15h00 - 25.1, xloc=xloc.bar_time, bgcolor=color.new(#d1b5dd, 90), border_width=1, border_color=color.red, border_style = line.style_solid)
        box.delete(bx_ema4[1])

        bx_ema41 := box.new(start_time_15h00, close_15h00 - 37.5, start_time_15h00+3600000*22, close_15h00 - 37.6, xloc=xloc.bar_time, bgcolor=color.new(#d1b5dd, 90), border_width=1, border_color=color.red, border_style = line.style_solid)
        box.delete(bx_ema41[1])

        lbl_ema_high := label.new(bar_index + line_len2+padding_right, close_15h00 - 25, str.format("LOW {0}", close_15h00 - 25), style = label.style_label_right, color = color.new(#660990, 90), textcolor = color.orange)
        label.delete(lbl_ema_high[1])

        lbl_ema_low := label.new(bar_index + line_len2+padding_right+3, close_15h00 - 50, str.format("BOTTOM: {0}", close_15h00 - 50), style = label.style_label_right, color = color.new(#660990, 90), textcolor = color.orange)
        label.delete(lbl_ema_low[1])
    
    

    
// new box ema diff - END

Overview

Donald SPX - Options Trading plots a 200-period Weighted Moving Average (WMA) on the price chart while evaluating multi-timeframe market structure across Daily, 15-minute, 5-minute, and 2-minute bars. The script tracks price distances relative to the 200 WMA at specific UTC-8 session timestamps to contextualize trend direction. Note that it uses multi-timeframe security requests with lookahead enabled on current bar values, causing historical repainting.

Details

Published by

dearvn on GitHub

Code credit

donaldit.net, as written in the script's header

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Moving averages, Trend, Sessions & time

Markets

Indices, Stocks

Timeframes

M1-M5, M15-H1

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)
  • Reads higher-timeframe data with lookahead on, so the history can show signals that were not there in real time

Topics

futures-markettradingviewtradovatetrading-futureses1best-indicator-tradingviewnq1trading-futurerus-stock-market

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

Market Monitor - 15m

by chris-c-thomas
14 stars

Market Monitor - 15m is a directional bias chart overlay designed for 15-minute intraday chart analysis. It calculates a triple exponential moving average ribbon with EMA cloud shading, session VWAP with multiplier bands, prior day levels, a 30-minute opening

Indicator v6 TrendMoving averages
Updated 6 months ago · MIT GitHub repository of Market Monitor - 15m
948 stars

The Adaptive Laguerre Filter calculates a smoothed, dynamically adjusted trendline plotted directly on the main price chart. It dynamically adjusts its damping factor (alpha) based on recent price range variations and median percentile calculations over a spec

Indicator v4 TrendMoving averages
Updated 10 days ago · GPL-3.0 GitHub repository of Adaptive Laguerre Filter
330 stars

This script plots three moving averages on the price chart: a fast EMA or SMA with 10 periods, a slow EMA or SMA with 20 periods, and a trend EMA or SMA with 100 periods. It signals trend changes by drawing a white cross when the fast moving average crosses ab

Indicator v4 TrendMoving averages
Updated 2 months ago · None stated GitHub repository of 3 EMA/SMA + Cross [Alorse]
318 stars

This indicator plots four customizable moving averages directly on the main price chart using default lengths of 3, 8, 21, and 50 periods. It fills the space between adjacent averages in green or maroon depending on trend alignment. Additionally, it computes B

Indicator v5 Moving averagesTrend
Updated 2 months ago · MIT GitHub repository of Multiple Moving Averages

NVDA Trend Ribbon

by longsurf-ai
277 stars

This indicator plots three exponential moving averages and ATR volatility envelopes on the price chart. It compares the fast and slow EMAs to shade a trend ribbon and marks confirmed upward and downward crossovers with triangle labels. Settings change the thre

Indicator v6 TrendMoving averages
Updated yesterday · MIT GitHub repository of NVDA Trend Ribbon

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