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
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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Fair Value Index | SPX | string | index |
| Strategy | Long/Short | string | line 38 line 55 line 68 |
| Scalar | 1.1 | float | index_fair_value |
| Subtractor | 1425 | int · step 25 | index_fair_value |
| OB Threshold | 0 | int · step 25 | overbought_signal Overbought |
| OS Threshold | -175 | int · step 25 | oversold_signal Oversold |
| Inverse | false | bool | line 39 line 56 line 69 |
| Start Day | 20 | int · min 1 · max 31 | afterStartDate |
| Start Month | 12 | int · min 1 · max 12 | afterStartDate |
| Start Year | 2021 | int · min 1800 · max 2100 | afterStartDate |
| Use Close Date | true | bool | entry 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 Day | 12 | int · min 1 · max 31 | afterEndDate |
| Close Month | 01 | int · min 1 · max 12 | afterEndDate |
| Close Year | 2023 | int · min 1800 · max 2100 | afterEndDate |
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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long long | (overbought_signal and afterStartDate) | On | 41 |
| Open Short short | ((afterStartDate and oversold_signal) or (useCloseDate and afterEndDate)) | On | 43 |
| Close Short | (useCloseDate and afterEndDate) | On | 45 |
| Close Long | (useCloseDate and afterEndDate) | On | 46 |
| Open Short short | (overbought_signal and afterStartDate) | On | 49 |
| Open Long long | (afterStartDate and oversold_signal) | On | 51 |
| Close Short | (useCloseDate and afterEndDate) | On | 53 |
| Close Long | (useCloseDate and afterEndDate) | On | 54 |
| Open Long long | (overbought_signal and afterStartDate) | On | 58 |
| Close Long | ((afterStartDate and oversold_signal) or (useCloseDate and afterEndDate)) | On | 61 |
| Open Short short | (overbought_signal and afterStartDate) | On | 64 |
| Close Short | ((afterStartDate and oversold_signal) or (useCloseDate and afterEndDate)) | On | 67 |
| Open Short short | (oversold_signal and afterStartDate) | On | 71 |
| Close Short | ((afterStartDate and overbought_signal) or (useCloseDate and afterEndDate)) | On | 74 |
| Open Long long | (oversold_signal and afterStartDate) | On | 77 |
| Close Long | ((afterStartDate and overbought_signal) or (useCloseDate and afterEndDate)) | On | 80 |
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
VerifiedNothing 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
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | No It imports the library calebsandfort/NetLiquidityLibrary/43, whose source is not available here, so it does not run here | Not measured | |
| PineTS | Not tested | Not tested | Not 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")