Zeal Terminal Open Zeal Terminal

Pine Script v5 · Strategy

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. 14 settings; defaults include Fair Value Index SPX, Strategy Long/Short and Scalar 1.1.

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 Fair Value Strategy Ultimate repaint?
Yes
At least one pattern in the source can repaint: intrabar recalculation.
Does 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/43'. 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 Fair Value Strategy Ultimate use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does Fair Value Strategy Ultimate run in Zeal Terminal?
No
Not yet: it imports the library calebsandfort/NetLiquidityLibrary/43, whose source is not available here, so it does not run here
Does not run in Zeal Terminal yetIt imports the library calebsandfort/NetLiquidityLibrary/43, 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
Fair Value IndexSPXstringindex
StrategyLong/Shortstringline 38 line 55 line 68
Scalar1.1floatindex_fair_value
Subtractor1425int · step 25index_fair_value
OB Threshold0int · step 25overbought_signal Overbought
OS Threshold-175int · step 25oversold_signal Oversold
Inversefalseboolline 39 line 56 line 69
Start Day20int · min 1 · max 31afterStartDate
Start Month12int · min 1 · max 12afterStartDate
Start Year2021int · min 1800 · max 2100afterStartDate
Use Close Datetrueboolentry Short close Short close Long close Short close Long close Long close Short close Short close Long line 42 line 44 line 52 line 60 line 66 line 73 line 79
Close Day12int · min 1 · max 31afterEndDate
Close Month01int · min 1 · max 12afterEndDate
Close Year2023int · 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.

scalarScalarsetting · 1.1subtractorSubtractorsetting · 1425closecloseprice datafv_index_tickerFair Value Indexsetting · SPXtimetimeprice datastartYearStart Yearsetting · 2021startMonthStart Monthsetting · 12startDateStart Daysetting · 20closeYearClose Yearsetting · 2023closeMonthClose Monthsetting · 01closeDayClose Daysetting · 12ob_thresholdOB Thresholdsetting · 0os_thresholdOS Thresholdsetting · -175index_fair_valueindex_fair_valuevalueindexindexvaluediffdiffvalueqtyqtyvalueqty_adjqty_adjvalueafterStartDateafterStartDateconditionafterEndDateafterEndDateconditionoverbought_signaloverbought_signalconditionoversold_signaloversold_signalconditionentry:LongOpen Longstrategy.entryentry:ShortOpen Shortstrategy.entryclose:ShortClose Shortstrategy.closeclose:LongClose Longstrategy.closeplotchar:25plotcharplotcharplot:29Spreadplothline:30Zerohlinehline:31Overboughthlinehline:32Oversoldhlinebarcolor:35barcolorbarcolor

Order rules

OrderFires whenBy defaultLine
Open Long long(overbought_signal and afterStartDate)On41
Open Short short((afterStartDate and oversold_signal) or (useCloseDate and afterEndDate))On43
Close Short(useCloseDate and afterEndDate)On45
Close Long(useCloseDate and afterEndDate)On46
Open Short short(overbought_signal and afterStartDate)On49
Open Long long(afterStartDate and oversold_signal)On51
Close Short(useCloseDate and afterEndDate)On53
Close Long(useCloseDate and afterEndDate)On54
Open Long long(overbought_signal and afterStartDate)On58
Close Long((afterStartDate and oversold_signal) or (useCloseDate and afterEndDate))On61
Open Short short(overbought_signal and afterStartDate)On64
Close Short((afterStartDate and oversold_signal) or (useCloseDate and afterEndDate))On67
Open Short short(oversold_signal and afterStartDate)On71
Close Short((afterStartDate and overbought_signal) or (useCloseDate and afterEndDate))On74
Open Long long(oversold_signal and afterStartDate)On77
Close Long((afterStartDate and overbought_signal) or (useCloseDate and afterEndDate))On80

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/43'. 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("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/43, 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("Fair Value Strategy Ultimate", overlay=false, initial_capital = 1000000, calc_on_every_tick = true)import calebsandfort/NetLiquidityLibrary/43 as NetLiquidityLibraryfv_index_ticker = input.string("SPX", "Fair Value Index", ["SPX", "NDX", "RUT"])mode = input.string("Long/Short", "Strategy", ["Short Only", "Long Only", "Long/Short"])scalar = input.float(1.1, "Scalar", 0.0, 5.0, .1)subtractor = input.int(1425, "Subtractor", step = 25)ob_threshold = input.int(0, "OB Threshold", step = 25)os_threshold = input.int(-175, "OS Threshold", step = 25)inverse = input.bool(false, "Inverse")startDate = input.int(title="Start Day", defval=20, 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=12, minval=1, maxval=31)closeMonth = input.int(title="Close Month", defval=01, minval=1, maxval=12)closeYear = input.int(title="Close Year", defval=2023, 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(net_liquidity, "net_liquidity", "", location.top)index_fair_value = net_liquidity/1000000000/scalar - subtractorindex = request.security(fv_index_ticker, "D", close)diff = index - index_fair_valueplot(index_fair_value > 0 ? diff : na, title = "Spread", color = color.orange, trackprice = true, linewidth = 2)hline(0, title='Zero', color=color.gray, linestyle=hline.style_dotted, linewidth=2)hline(ob_threshold, title='Overbought', color=color.red, linestyle=hline.style_dotted, linewidth=2)hline(os_threshold, title='Oversold', color=color.green, linestyle=hline.style_dotted, linewidth=2)overbought_signal = net_liquidity > 0.0 and (diff[1] < ob_threshold and diff[0] > ob_threshold)oversold_signal = net_liquidity > 0.0 and (diff[1] > os_threshold and diff[0] < os_threshold)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 (useCloseDate and 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 (useCloseDate and 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")