Pine Script v5 · Strategy
Fair Value Strategy - ekmll
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 - ekmll repaint?
- Yes
- At least one pattern in the source can repaint: intrabar recalculation.
- How did Fair Value Strategy - ekmll do on BTCUSDT 1D with default settings?
- Not measured
- It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its code limits trading to a date window, which can leave this period out. It closed no trades on the other markets either. A backtest, not investment advice.
- Does Fair Value Strategy - ekmll run in Pine Script v6?
- Not tested
- Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download.
- Does Fair Value Strategy - ekmll use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Fair Value Strategy - ekmll run in Zeal Terminal?
- Yes
- It compiles in 33 ms and runs 1,000 bars in 42 ms, in the browser.
BTCUSDT · 1D · default settings
- Zero
- Overbought
- Oversold
- Winning trade
- Losing trade
- Equity
- Buy and hold
Needs (WALCL - WTREGEN - RRPONTSYD) D data, not available: not a Binance spot market Needs SPX D data, not available: not a Binance spot market Values that depend on it are empty on this chart.
- Net profit
- 0.00%
- $0.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 0
- 0 won · 0 lost
- Profitable
- 0.0%
- of closed trades
- Profit factor
- —
- gross profit ÷ gross loss
- Max drawdown
- 0.00%
- $0.00
One run with the author's default settings, $1,000,000 starting capital, commission as the script sets it. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.
Review
What a careful reader of this script would point out, found by checking the source and the backtest.
-
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 37 line 54 line 67 |
| 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 38 line 55 line 68 |
| 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 41 line 43 line 51 line 59 line 65 line 72 line 78 |
| Close Day | 20 | int · min 1 · max 31 | afterEndDate |
| Close Month | 12 | int · min 1 · max 12 | afterEndDate |
| Close Year | 2024 | 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 | 40 |
| Open Short short | ((afterStartDate and oversold_signal) or (useCloseDate and afterEndDate)) | On | 42 |
| Close Short | (useCloseDate and afterEndDate) | On | 44 |
| Close Long | (useCloseDate and afterEndDate) | On | 45 |
| Open Short short | (overbought_signal and afterStartDate) | On | 48 |
| Open Long long | (afterStartDate and oversold_signal) | On | 50 |
| Close Short | (useCloseDate and afterEndDate) | On | 52 |
| Close Long | (useCloseDate and afterEndDate) | On | 53 |
| Open Long long | (overbought_signal and afterStartDate) | On | 57 |
| Close Long | ((afterStartDate and oversold_signal) or (useCloseDate and afterEndDate)) | On | 60 |
| Open Short short | (overbought_signal and afterStartDate) | On | 63 |
| Close Short | ((afterStartDate and oversold_signal) or (useCloseDate and afterEndDate)) | On | 66 |
| Open Short short | (oversold_signal and afterStartDate) | On | 70 |
| Close Short | ((afterStartDate and overbought_signal) or (useCloseDate and afterEndDate)) | On | 73 |
| Open Long long | (oversold_signal and afterStartDate) | On | 76 |
| Close Long | ((afterStartDate and overbought_signal) or (useCloseDate and afterEndDate)) | On | 79 |
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.
- ClearHigher-timeframe data2 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.
Other markets
Not run on other markets: the script requests (WALCL - WTREGEN - RRPONTSYD) D, SPX D, and that data is not available here (not a Binance spot market; not a Binance spot market). Its results would rest on empty values.
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
Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// ©ekmll-//@version=5+//@version=6strategy("Fair Value Strategy ekmll", overlay=false, initial_capital = 1000000, calc_on_every_tick = true)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 33 ms | Yes 1,000 bars in 42 ms | 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/// ©ekmll//@version=5strategy("Fair Value Strategy ekmll", overlay=false, initial_capital = 1000000, calc_on_every_tick = true)fv_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=20, minval=1, maxval=31)closeMonth = input.int(title="Close Month", defval=12, minval=1, maxval=12)closeYear = input.int(title="Close Year", defval=2024, minval=1800, maxval=2100) // See if this bar's time happened on/after end dateafterEndDate = year == closeYear and month == closeMonth and dayofmonth == closeDaynet_liquidity = request.security("(WALCL - WTREGEN - RRPONTSYD)", "D", close)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.blue, 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")