Zeal Terminal Open Zeal Terminal

Pine Script v5 · Strategy

SPX Fair Value Strategy Ultimate

A Pine Script v5 strategy with no technical-analysis calculation. It has 16 order rules, 8 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. 9 settings; defaults include Strategy Short Only, Start Day 31 and Start Month 12.

Generated from the script's code by a template: every clause is a fact read from the source. Not written by a person or a model, and not taken from the author's description.

Does SPX Fair Value Strategy Ultimate repaint?
Yes
At least one pattern in the source can repaint: intrabar recalculation.
Does SPX Fair Value Strategy Ultimate run in Pine Script v6?
Not tested
The v5 script does not run in Zeal Terminal's engine (Pine Script v5 Error at @L5:C0: no source was supplied for the library 'calebsandfort/NetLiquidityLibrary/16'. Libraries cannot be fetched from TradingView; supply the source in the 'libraries' option. No libraries were supplied.), so this step could not be checked. The v6 version is shown for reference and is not offered as a download.
Does SPX Fair Value Strategy Ultimate use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does SPX Fair Value Strategy Ultimate run in Zeal Terminal?
No
Not yet: it imports the library calebsandfort/NetLiquidityLibrary/16, whose source is not available here, so it does not run here
Does not run in Zeal Terminal yetIt imports the library calebsandfort/NetLiquidityLibrary/16, whose source is not available here, so it does not run here. The settings, logic and review below are read from the source, which does not need a run.

Review

What a careful reader of this script would point out, found by checking the source.

  • Check

    No stop loss

    Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.

  • Check

    No commission

    The backtest assumes free trading. Results on any real exchange will be lower.

  • Note

    No slippage

    Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
StrategyShort Onlystringline 36 line 53 line 66
Inversefalseboolline 37 line 54 line 67
Start Day31int · min 1 · max 31afterStartDate
Start Month12int · min 1 · max 12afterStartDate
Start Year2021int · min 1800 · max 2100afterStartDate
Use Close Datetrueboolentry Short close Long close Short close Short close Long line 40 line 58 line 64 line 71 line 77
Close Day21int · min 1 · max 31afterEndDate
Close Month10int · min 1 · max 12afterEndDate
Close Year2022int · min 1800 · max 2100afterEndDate

What it calculates

No technical-analysis calculation: the script works on prices and settings directly.

Signal flow

How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.

closecloseprice datatimetimeprice datastartYearStart Yearsetting · 2021startMonthStart Monthsetting · 12startDateStart Daysetting · 31closeYearClose Yearsetting · 2022closeMonthClose Monthsetting · 10closeDayClose Daysetting · 21spx_fair_valuespx_fair_valuevaluespx, qtyspx · qty2 valuesdiffdiffvalueqty_adjqty_adjvalueafterStartDateafterStartDateconditionafterEndDateafterEndDateconditionoverbought_signaloverbought_signalconditionoversold_signaloversold_signalconditionentry:LongOpen Longstrategy.entryentry:ShortOpen Shortstrategy.entryclose:ShortClose Shortstrategy.closeclose:LongClose Longstrategy.closeplot:27Spreadplothline:28Overboughthlinehline:29Zerohlinehline:30Oversoldhlinebarcolor:33barcolorbarcolor

Order rules

OrderFires whenBy defaultLine
Open Long long(overbought_signal and afterStartDate)On39
Open Short short((afterStartDate and oversold_signal) or (useCloseDate and afterEndDate))On41
Close Short(afterEndDate)On43
Close Long(afterEndDate)On44
Open Short short(overbought_signal and afterStartDate)On47
Open Long long(afterStartDate and oversold_signal)On49
Close Short(afterEndDate)On51
Close Long(afterEndDate)On52
Open Long long(overbought_signal and afterStartDate)On56
Close Long((afterStartDate and oversold_signal) or (useCloseDate and afterEndDate))On59
Open Short short(overbought_signal and afterStartDate)On62
Close Short((afterStartDate and oversold_signal) or (useCloseDate and afterEndDate))On65
Open Short short(oversold_signal and afterStartDate)On69
Close Short((afterStartDate and overbought_signal) or (useCloseDate and afterEndDate))On72
Open Long long(oversold_signal and afterStartDate)On75
Close Long((afterStartDate and overbought_signal) or (useCloseDate and afterEndDate))On78

Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.

Does it repaint?

Yes

At least one pattern in the source can repaint; it is marked Check below.

The live replay needs a run, and this script does not run in Zeal Terminal yet; the answer comes from the checks on the source alone.

  • ClearHigher-timeframe data1 request.security call(s), none with lookahead on.
  • ClearFuture-bar referencesNo negative history offsets such as close[-1].
  • CheckIntrabar recalculationcalc_on_every_tick = true. Live values can differ from history.
  • ClearOrder timingOrders fill at the next bar's open, after the signal bar has closed.

The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.

Similar scripts

No other indicator or strategy here shares enough of its calculations.

Upgrade and export

Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.

  • No v6-only features. v6 is not needed to run this script.

Clean v5

Verified

Nothing to change.

Does it run in Pine Script v6?

Not tested

The v5 script does not run in Zeal Terminal's engine (Pine Script v5 Error at @L5:C0: no source was supplied for the library 'calebsandfort/NetLiquidityLibrary/16'. Libraries cannot be fetched from TradingView; supply the source in the 'libraries' option. No libraries were supplied.), so this step could not be checked. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

⋯// © calebsandfort-//@version=5+//@version=6strategy("SPX Fair Value Strategy Ultimate", overlay=false, initial_capital = 1000000, calc_on_every_tick = true)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2No It imports the library calebsandfort/NetLiquidityLibrary/16, whose source is not available here, so it does not run hereNot measured
PineTSNot testedNot testedNot measured

“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report.

Source

Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © calebsandfort//@version=5strategy("SPX Fair Value Strategy Ultimate", overlay=false, initial_capital = 1000000, calc_on_every_tick = true)import calebsandfort/NetLiquidityLibrary/16 as NetLiquidityLibrarymode = input.string("Short Only", "Strategy", ["Short Only", "Long Only", "Long/Short"])inverse = input.bool(false, "Inverse")startDate = input.int(title="Start Day", defval=31, minval=1, maxval=31)startMonth = input.int(title="Start Month", defval=12, minval=1, maxval=12)startYear = input.int(title="Start Year", defval=2021, minval=1800, maxval=2100)// See if this bar's time happened on/after start dateafterStartDate = (time >= timestamp(syminfo.timezone, startYear, startMonth, startDate, 0, 0))useCloseDate = input.bool(true, title="Use Close Date")closeDay = input.int(title="Close Day", defval=21, minval=1, maxval=31)closeMonth = input.int(title="Close Month", defval=10, minval=1, maxval=12)closeYear = input.int(title="Close Year", defval=2022, minval=1800, maxval=2100)  // See if this bar's time happened on/after end dateafterEndDate = year == closeYear and month == closeMonth and dayofmonth == closeDaynet_liquidity = NetLiquidityLibrary.get_net_liquidity()// plotchar(year, "year", "", location.top)// plotchar(month, "month", "", location.top)// plotchar(dayofmonth, "dayofmonth", "", location.top)// plotchar(net_liquidity, "net_liquidity", "", location.top)spx_fair_value = net_liquidity/1000000000/1.1 -1625spx = request.security("SP:SPX", "D", close)diff = spx - spx_fair_valueplot(spx_fair_value > 0 ? diff : na, title = "Spread", color = color.orange, trackprice = true, linewidth = 2)hline(350, title='Overbought', color=color.red, linestyle=hline.style_dotted, linewidth=2)hline(0, title='Zero', color=color.gray, linestyle=hline.style_dotted, linewidth=2)hline(-150, title='Oversold', color=color.green, linestyle=hline.style_dotted, linewidth=2)overbought_signal = net_liquidity > 0.0 and (diff[1] < 350 and diff[0] > 350)oversold_signal = net_liquidity > 0.0 and (diff[1] > -150 and diff[0] < -150)barcolor(overbought_signal ? color.purple : oversold_signal ? color.blue : na)qty = (strategy.initial_capital + strategy.netprofit + strategy.openprofit)/closeqty_adj = strategy.opentrades > 0 ? math.abs(strategy.opentrades.size(0) * 1) : qty[0]if (mode == "Long/Short")    if (inverse)        if (overbought_signal and afterStartDate)            strategy.entry("Long", strategy.long, qty = qty[0], comment = "LE")                else if ((afterStartDate and oversold_signal) or (useCloseDate and afterEndDate))            strategy.entry("Short", strategy.short, qty = qty[0], comment = "SE")        else if (afterEndDate)            strategy.close("Short", qty_percent=100, comment="close")            strategy.close("Long", qty_percent=100, comment="close")    else        if (overbought_signal and afterStartDate)            strategy.entry("Short", strategy.short, qty = qty[0], comment = "SE")        else if (afterStartDate and oversold_signal)            strategy.entry("Long", strategy.long, qty = qty[0], comment = "LE")        else if (afterEndDate)            strategy.close("Short", qty_percent=100, comment="close")            strategy.close("Long", qty_percent=100, comment="close")else if (mode == "Short Only")    if (inverse)        if (overbought_signal and afterStartDate)            strategy.entry("Long", strategy.long, qty = qty[0], comment = "LE")                        if ((afterStartDate and oversold_signal) or (useCloseDate and afterEndDate))            strategy.close("Long", qty_percent=100, comment="close")    else        if (overbought_signal and afterStartDate)            strategy.entry("Short", strategy.short, qty = qty[0], comment = "SE")                        if ((afterStartDate and oversold_signal) or (useCloseDate and afterEndDate))            strategy.close("Short", qty_percent=100, comment="close")else if (mode == "Long Only")    if (inverse)        if (oversold_signal and afterStartDate)            strategy.entry("Short", strategy.short, qty = qty[0], comment = "SE")                        if ((afterStartDate and overbought_signal) or (useCloseDate and afterEndDate))            strategy.close("Short", qty_percent=100, comment="close")    else        if (oversold_signal and afterStartDate)            strategy.entry("Long", strategy.long, qty = qty[0], comment = "LE")                        if ((afterStartDate and overbought_signal) or (useCloseDate and afterEndDate))            strategy.close("Long", qty_percent=100, comment="close")