Indicator · Pine Script v5 · On the chart

Donald SPX - Options Trading

by dearvn· code credited to donaldit.net

This indicator plots a 200-period weighted moving average (WMA) on the main chart and monitors price deviations across multiple timeframes.

View on GitHub

Repaints

GitHub stars257on the repository
Pine versionv5runs as is
Lines of code170
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

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

SPX-options.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_ema = 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 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 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



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, 2, str.format("Close 6h30: {0}", open15_6h45), bgcolor=color.new(#660990,70), text_color=color.white, width=20, text_halign=text.align_left)
    table.cell(panel5, 0, 3, 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, 4, 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, 5, 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, 5, 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

var float open_6h30 = 0.0

if hour(time, "UTC-8") == 6 and minute(time, "UTC-8") == 30
    start_time_ema := time - 1800000 - 3600000*2
    

if hour(time_close, "UTC-8") == 6 and minute(time_close, "UTC-8") == 30 //and dayofmonth(time_close, "UTC-7")<dayofmonth(timenow, "UTC-7")
    open_6h30 := close

if barstate.islast
    bx_ema := box.new(start_time_ema, open_6h30 + 50, start_time_ema+3600000*9, open_6h30 + 25, xloc=xloc.bar_time, bgcolor=color.new(#660990, 90), border_width=2, border_color=color.white)
    box.delete(bx_ema[1])

    bx_ema1 := box.new(start_time_ema, open_6h30 + 37.5, start_time_ema+3600000*9, open_6h30 + 37.4, xloc=xloc.bar_time, bgcolor=color.new(#660990, 90), border_width=1, border_color=color.yellow, border_style = line.style_dotted)
    box.delete(bx_ema1[1])


    bx_ema2 := box.new(start_time_ema, open_6h30 + 25, start_time_ema+3600000*9, open_6h30, xloc=xloc.bar_time, bgcolor=color.new(#660990, 90), border_width=2, border_color=color.white)
    box.delete(bx_ema2[1])

    bx_ema21 := box.new(start_time_ema, open_6h30 + 12.5, start_time_ema+3600000*9, open_6h30 + 12.4, xloc=xloc.bar_time, bgcolor=color.new(#660990, 90), border_width=1, border_color=color.yellow, border_style = line.style_dotted)
    box.delete(bx_ema21[1])

    bx_ema3 := box.new(start_time_ema, open_6h30, start_time_ema+3600000*9, open_6h30 - 25, xloc=xloc.bar_time, bgcolor=color.new(#660990, 90), border_width=2, border_color=color.white)
    box.delete(bx_ema3[1])

    bx_ema31 := box.new(start_time_ema, open_6h30 - 17.5, start_time_ema+3600000*9, open_6h30 - 17.6, xloc=xloc.bar_time, bgcolor=color.new(#660990, 90), border_width=1, border_color=color.yellow, border_style = line.style_dotted)
    box.delete(bx_ema31[1])

    bx_ema4 := box.new(start_time_ema, open_6h30 - 25, start_time_ema+3600000*9, open_6h30 - 50, xloc=xloc.bar_time, bgcolor=color.new(#660990, 90), border_width=2, border_color=color.white)
    box.delete(bx_ema4[1])

    bx_ema41 := box.new(start_time_ema, open_6h30 - 37.5, start_time_ema+3600000*9, open_6h30 - 37.4, xloc=xloc.bar_time, bgcolor=color.new(#660990, 90), border_width=1, border_color=color.yellow, border_style = line.style_dotted)
    box.delete(bx_ema41[1])

    // line sperate
    padding_right = 6
    lbl_ema_open := label.new(bar_index + line_len2+padding_right, open_6h30 + 50, str.format("TOP: {0}", open_6h30 + 50), style = label.style_text_outline, 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, open_6h30 + 25, str.format("UP: {0}", open_6h30 + 25), style = label.style_text_outline, color = color.new(#660990, 90), textcolor = color.orange)
    label.delete(lbl_ema_current[1])

    lbl_ema_yesterday := label.new(bar_index + line_len2+padding_right, open_6h30, str.format("MID: {0}", open_6h30), style = label.style_text_outline, color = color.new(#660990, 90), textcolor = color.orange)
    label.delete(lbl_ema_yesterday[1])

    lbl_ema_high := label.new(bar_index + line_len2+padding_right, open_6h30 - 25, str.format("LOW {0}", open_6h30 - 25), style = label.style_text_outline, 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+4, open_6h30 - 50, str.format("BOTTOM: {0}", open_6h30 - 50), style = label.style_text_outline, color = color.new(#660990, 90), textcolor = color.orange)
    label.delete(lbl_ema_low[1])
// new box ema diff - END

Overview

Donald SPX - Options Trading retrieves daily, 15-minute, 5-minute, and 2-minute price data to track distance from the 200 WMA relative to key session opening times. Key statistics and market condition messages are displayed in a dashboard table in the lower-right corner. Using lookahead parameters in higher-timeframe data requests causes historical values to repaint.

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, Sessions & time, Screeners & dashboards

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
575 stars

This indicator builds Market Profile Time Price Opportunity (TPO) structures across defined session timeframes directly on the main price chart. It visualizes the Point of Control (POC) and Value Area boundaries using dynamic box drawings. An integrated multi-

Indicator v5 Support & resistanceScreeners & dashboards
Updated 1 year ago · MPL-2.0 GitHub repository of Market Profile with Screener

Golden Bullet Strategy

by TradersPost
218 stars

The Golden Bullet Strategy is an overlay signal indicator based on Smart Money Concepts and time-based liquidity models. It identifies liquidity sweeps of a designated reference session range during a specified hunt window. It then confirms Market Structure Sh

Indicator v6 SMC / ICT / price actionSessions & time
Updated 3 months ago · None stated GitHub repository of Golden Bullet Strategy

8zz反指標v2

by hansai-art
121 stars

The 8zz Contrarian Indicator plots reverse sentiment trading signals directly on the price chart based on tracked retail post activity. It generates bullish signals during retail panic and bearish signals during market euphoria. The indicator features adjustab

Indicator v6 Moving averagesOscillators & momentum
Updated 3 months ago · None stated GitHub repository of 8zz反指標v2
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

Price vs MA

by be-thomas
65 stars

This indicator builds a table of simple moving averages and places it on the price chart. It calculates a user-chosen number of SMAs whose periods start at a base length and increase by a fixed step. On the last bar it lists each period and its SMA value, colo

Indicator v4 Moving averagesScreeners & dashboards
Updated 4 days ago · GPL-3.0 GitHub repository of Price vs MA

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