Pine Script v4 · Strategy
Repaint Demonstration in Security Function Call using Higher TF
A Pine Script v4 strategy built on Crossover (close, bigTFClose). It has 2 order rules, 1 entry among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 100% of equity and pays no commission. 1 setting; defaults include Future Sight: W.
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 Repaint Demonstration in Security Function Call using Higher TF repaint?
- Yes
- In a live replay, it did not match history on 24 of 26 trades, and it produced 30 trades that history does not have.
- How did Repaint Demonstration in Security Function Call using Higher TF do on BTCUSDT 1D with default settings?
- +133.82%
- From 26 Jan 2024 to 21 Oct 2026, over 89 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Repaint Demonstration in Security Function Call using Higher TF be converted to Pine Script v5?
- No
- The automatic step from v4 to v5 changes the results, so no v5 download is offered; the edits are shown below.
- Does Repaint Demonstration in Security Function Call using Higher TF use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Repaint Demonstration in Security Function Call using Higher TF run in Zeal Terminal?
- Yes
- It compiles in 6 ms and runs 1,000 bars in 25 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +133.82%
- $133,820.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 89
- 35 won · 54 lost
- Profitable
- 39.3%
- of closed trades
- Profit factor
- 1.54
- gross profit ÷ gross loss
- Max drawdown
- 27.53%
- −$57,171.90
One run with the author's default settings, $100,000 starting capital, commission as the script sets it. A long position was still open at the last bar. 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.
-
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
-
Note
Uses an argument v6 removed
when = on line 13, 14. The upgraded version below moves each call inside an if block.
Upgrade and export
Written in Pine Script v4. The upgrade to v5 takes 1 step, one per version, each applied to the result of the one before. A last clean-v5 pass then types the settings and moves when = into if blocks, which v6 requires. Every step runs before and after on the same candles in Zeal Terminal's engine; a step whose results differ is shown but not offered as a download. Upgrades preserve behaviour: bugs are fixed in the Review, never silently here.
- Upgrading to v5 renames security → request.security, crossover → ta.crossover.
- 2 strategy calls use the when = argument (line 13, 14). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
DiffersTrades differ: 89 before, 89 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 7: input(type = input.resolution) → input.timeframe()
- Line 8: security → request.security
- Line 9: crossover → ta.crossover
- Line 10: crossover → ta.crossover
- Line 13: strategy.entry(…, true) → strategy.entry(…, strategy.long)
⋯// © akrit8888-// @version=4+// @version=5// "This Script is for demonstration of repaint by using security function to lookup the Future" ⋯strategy("Repaint Demonstration in Security Function Call using Higher TF", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100)-bigTF = input("W", "Future Sight: ", input.resolution)+bigTF = input.timeframe("W", "Future Sight: ")-bigTFClose = security(syminfo.tickerid, bigTF, close)+bigTFClose = request.security(syminfo.tickerid, bigTF, close)-buy = crossover(close, bigTFClose)+buy = ta.crossover(close, bigTFClose)-sell = crossover(bigTFClose, close)+sell = ta.crossover(bigTFClose, close)plot(close)plot(bigTFClose)-strategy.entry("L", true, when = buy)+strategy.entry("L", strategy.long, when = buy)strategy.close("L", when = sell)Clean v5
VerifiedSame 89 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 13: when = buy → if block
- Line 14: when = sell → if block
⋯plot(bigTFClose)-strategy.entry("L", strategy.long, when = buy)+if buy+ strategy.entry("L", strategy.long)-strategy.close("L", when = sell)+if sell+ strategy.close("L")Does it run in Pine Script v6?
No
The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 89 before, 74 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © akrit8888-// @version=5+// @version=6// "This Script is for demonstration of repaint by using security function to lookup the Future" ⋯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 |
|---|---|---|---|
| Future Sight: | W | string | bigTFClose |
What it calculates
- Crossover (
crossover,ta.crossoverin v5)close, bigTFClosebuy · line 9 - Crossover (
crossover,ta.crossoverin v5)bigTFClose, closesell · line 10
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 L long | buy | On | 13 |
| Close L | sell | On | 14 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Does it repaint?
Yes
The live replay did not match history.
- ClearHigher-timeframe data1 security call(s), none with lookahead on.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
- 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
The same script with default settings on 8 Binance markets. Each row is a separate backtest over the most recent 1,000 bars.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | +133.8% | +102.5% | 89 | 39% | 1.54 | 27.5% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +15.0% | +5.5% | 37 | 22% | 1.58 | 10.6% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +27.9% | +9.8% | 92 | 27% | 1.08 | 50.6% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −7.6% | +8.4% | 48 | 10% | 0.85 | 18.9% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +107.5% | +16.7% | 93 | 35% | 1.20 | 61.8% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +35.4% | +21.5% | 37 | 22% | 1.95 | 12.4% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +110.5% | +148.3% | 97 | 40% | 1.41 | 26.2% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.9% | +17.1% | 52 | 17% | 1.02 | 12.9% | 8 May 2026 – 21 Oct 2026 |
Higher-timeframe data for request.security(): BINANCE:BTCUSDT W (Binance BTCUSDT 1w), fetched from Binance's public market data for each market.
Backtests are simulations on historical data and are not investment advice.
The trades
By market direction
| At entry, last 90 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 35 | 29% | $26,472.70 |
| Sideways market | 31 | 45% | $26,883.90 |
| Falling market | 23 | 48% | $80,463.40 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
37.7%
The 95th percentile of the worst drawdown when the same 89 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 17.8% to 37.7%; the tick is what actually happened, 23.7%. Order luck alone moves it this much.
All 89 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 30 Jan 2024 43,302.70 | 20 Feb 2024 51,774.70 | 21 | $19,564.70 |
| long | 21 Feb 2024 52,258.80 | 22 Feb 2024 51,849.40 | 1 | −$936.77 |
| long | 27 Feb 2024 54,476.50 | 17 Mar 2024 65,300.60 | 19 | $23,570.70 |
| long | 26 Mar 2024 69,880.00 | 2 Apr 2024 69,649.80 | 7 | −$468.41 |
| long | 9 Apr 2024 71,620.00 | 10 Apr 2024 69,146.00 | 1 | −$4,895.85 |
| long | 11 Apr 2024 70,631.10 | 13 Apr 2024 67,116.50 | 2 | −$6,808.79 |
| long | 23 Apr 2024 66,819.30 | 25 Apr 2024 64,289.60 | 2 | −$4,922.69 |
| long | 30 Apr 2024 63,866.00 | 1 May 2024 60,672.00 | 1 | −$6,256.49 |
| long | 5 May 2024 63,892.00 | 7 May 2024 63,165.20 | 2 | −$1,352.02 |
| long | 14 May 2024 62,940.10 | 29 May 2024 68,398.40 | 15 | $10,189.40 |
| long | 4 Jun 2024 68,809.90 | 11 Jun 2024 69,540.00 | 7 | $1,354.79 |
| long | 2 Jul 2024 62,900.00 | 3 Jul 2024 62,135.50 | 1 | −$1,568.44 |
| long | 9 Jul 2024 56,714.60 | 23 Jul 2024 67,532.00 | 14 | $24,312.80 |
| long | 9 Aug 2024 61,686.00 | 15 Aug 2024 58,683.40 | 6 | −$7,388.14 |
| long | 17 Aug 2024 58,874.60 | 27 Aug 2024 62,834.00 | 10 | $9,710.77 |
| long | 3 Sep 2024 59,132.10 | 6 Sep 2024 56,180.00 | 3 | −$7,693.58 |
| long | 10 Sep 2024 57,042.00 | 17 Sep 2024 58,214.00 | 7 | $3,008.17 |
| long | 18 Sep 2024 60,314.00 | 24 Sep 2024 63,340.00 | 6 | $7,496.52 |
| long | 25 Sep 2024 64,262.70 | 26 Sep 2024 63,152.00 | 1 | −$2,712.08 |
| long | 27 Sep 2024 65,174.00 | 1 Oct 2024 63,327.60 | 4 | −$4,368.64 |
| long | 13 Oct 2024 63,206.20 | 22 Oct 2024 67,377.50 | 9 | $9,888.36 |
| long | 29 Oct 2024 69,962.20 | 5 Nov 2024 67,850.00 | 7 | −$4,822.17 |
| long | 6 Nov 2024 69,372.00 | 26 Nov 2024 93,010.00 | 20 | $52,781.70 |
| long | 5 Dec 2024 98,587.30 | 6 Dec 2024 96,945.60 | 1 | −$3,458.38 |
| long | 7 Dec 2024 99,740.80 | 10 Dec 2024 97,276.50 | 3 | −$5,045.93 |
| long | 12 Dec 2024 101,125.00 | 13 Dec 2024 100,004.00 | 1 | −$2,207.39 |
| long | 14 Dec 2024 101,424.00 | 19 Dec 2024 100,204.00 | 5 | −$2,369.76 |
| long | 25 Dec 2024 98,663.60 | 28 Dec 2024 94,299.00 | 3 | −$8,608.56 |
| long | 29 Dec 2024 95,300.00 | 31 Dec 2024 92,792.10 | 2 | −$4,894.68 |
| long | 2 Jan 2025 94,591.80 | 8 Jan 2025 96,954.60 | 6 | $4,523.70 |
| long | 15 Jan 2025 96,560.90 | 28 Jan 2025 102,083.00 | 13 | $10,615.10 |
| long | 30 Jan 2025 103,733.00 | 1 Feb 2025 102,430.00 | 2 | −$2,466.26 |
| long | 4 Feb 2025 101,329.00 | 6 Feb 2025 96,612.40 | 2 | −$9,018.59 |
| long | 11 Feb 2025 97,430.80 | 12 Feb 2025 95,778.20 | 1 | −$3,133.76 |
| long | 13 Feb 2025 97,870.00 | 18 Feb 2025 95,780.00 | 5 | −$3,878.44 |
| long | 20 Feb 2025 96,644.40 | 25 Feb 2025 91,552.90 | 5 | −$9,363.88 |
| long | 12 Mar 2025 82,933.00 | 29 Mar 2025 84,424.40 | 17 | $3,027.94 |
| long | 1 Apr 2025 82,550.00 | 9 Apr 2025 76,322.40 | 8 | −$12,930.80 |
| long | 10 Apr 2025 82,615.20 | 16 Apr 2025 83,644.00 | 6 | $1,973.41 |
| long | 17 Apr 2025 84,030.40 | 13 May 2025 102,791.00 | 26 | $35,822.10 |
| long | 21 May 2025 106,850.00 | 28 May 2025 108,938.00 | 7 | $3,835.70 |
| long | 3 Jun 2025 105,858.00 | 4 Jun 2025 105,377.00 | 1 | −$909.43 |
| long | 10 Jun 2025 110,263.00 | 13 Jun 2025 105,672.00 | 3 | −$8,294.39 |
| long | 14 Jun 2025 106,067.00 | 15 Jun 2025 105,415.00 | 1 | −$1,173.42 |
| long | 17 Jun 2025 106,795.00 | 18 Jun 2025 104,551.00 | 1 | −$3,985.49 |
| long | 24 Jun 2025 105,334.00 | 1 Jul 2025 107,147.00 | 7 | $3,196.23 |
| long | 3 Jul 2025 108,850.00 | 5 Jul 2025 107,984.00 | 2 | −$1,502.04 |
| long | 10 Jul 2025 111,234.00 | 16 Jul 2025 117,758.00 | 6 | $10,993.50 |
| long | 18 Jul 2025 119,178.00 | 19 Jul 2025 117,925.00 | 1 | −$2,085.78 |
| long | 22 Jul 2025 117,380.00 | 29 Jul 2025 118,062.00 | 7 | $1,140.73 |
| long | 5 Aug 2025 115,055.00 | 6 Aug 2025 114,130.00 | 1 | −$1,588.19 |
| long | 7 Aug 2025 114,992.00 | 12 Aug 2025 118,686.00 | 5 | $6,292.52 |
| long | 13 Aug 2025 120,134.00 | 15 Aug 2025 118,295.00 | 2 | −$3,095.10 |
| long | 2 Sep 2025 109,237.00 | 23 Sep 2025 112,651.00 | 21 | $6,221.51 |
| long | 30 Sep 2025 114,312.00 | 8 Oct 2025 121,333.00 | 8 | $12,610.40 |
| long | 14 Oct 2025 115,166.00 | 15 Oct 2025 113,028.00 | 1 | −$4,045.45 |
| long | 21 Oct 2025 110,532.00 | 22 Oct 2025 108,298.00 | 1 | −$4,323.65 |
| long | 24 Oct 2025 110,078.00 | 28 Oct 2025 114,108.00 | 4 | $7,670.94 |
| long | 11 Nov 2025 106,011.00 | 12 Nov 2025 103,059.00 | 1 | −$6,049.24 |
| long | 25 Nov 2025 88,300.00 | 2 Dec 2025 86,286.00 | 7 | −$4,816.70 |
| long | 3 Dec 2025 91,277.90 | 6 Dec 2025 89,330.00 | 3 | −$4,403.71 |
| long | 9 Dec 2025 90,634.40 | 13 Dec 2025 90,268.40 | 4 | −$815.37 |
| long | 21 Dec 2025 88,360.90 | 23 Dec 2025 88,620.80 | 2 | $591.59 |
| long | 31 Dec 2025 88,485.50 | 1 Jan 2026 87,648.20 | 1 | −$1,908.91 |
| long | 2 Jan 2026 88,839.10 | 8 Jan 2026 91,364.20 | 6 | $5,679.74 |
| long | 13 Jan 2026 91,296.20 | 20 Jan 2026 92,631.00 | 7 | $3,004.58 |
| long | 27 Jan 2026 88,347.10 | 30 Jan 2026 84,650.20 | 3 | −$8,725.20 |
| long | 3 Feb 2026 78,738.60 | 4 Feb 2026 75,770.20 | 1 | −$7,531.76 |
| long | 17 Feb 2026 68,892.40 | 18 Feb 2026 67,503.50 | 1 | −$3,875.94 |
| long | 26 Feb 2026 67,988.00 | 27 Feb 2026 67,485.20 | 1 | −$1,393.27 |
| long | 3 Mar 2026 68,830.10 | 19 Mar 2026 71,246.60 | 16 | $6,564.65 |
| long | 24 Mar 2026 70,906.40 | 28 Mar 2026 66,407.30 | 4 | −$12,281.10 |
| long | 31 Mar 2026 66,797.40 | 7 Apr 2026 68,853.70 | 7 | $5,580.12 |
| long | 8 Apr 2026 71,924.20 | 28 Apr 2026 77,371.30 | 20 | $14,150.70 |
| long | 3 May 2026 78,686.80 | 12 May 2026 81,745.70 | 9 | $7,813.48 |
| long | 21 May 2026 77,552.20 | 23 May 2026 75,539.50 | 2 | −$5,419.37 |
| long | 26 May 2026 77,322.00 | 27 May 2026 75,930.00 | 1 | −$3,661.60 |
| long | 12 Jun 2026 63,626.00 | 17 Jun 2026 65,675.00 | 5 | $6,432.17 |
| long | 23 Jun 2026 64,020.00 | 24 Jun 2026 62,734.60 | 1 | −$4,139.49 |
| long | 30 Jun 2026 60,260.20 | 1 Jul 2026 58,624.70 | 1 | −$5,483.02 |
| long | 2 Jul 2026 60,024.00 | 8 Jul 2026 63,364.00 | 6 | $10,936.40 |
| long | 11 Jul 2026 64,161.70 | 14 Jul 2026 62,334.50 | 3 | −$5,908.54 |
| long | 15 Jul 2026 65,044.00 | 25 Jul 2026 64,140.00 | 10 | −$2,801.43 |
| long | 5 Aug 2026 64,106.60 | 11 Aug 2026 63,970.00 | 6 | −$423.35 |
| long | 18 Aug 2026 64,532.10 | 2 Sep 2026 77,439.00 | 15 | $39,670.20 |
| long | 4 Sep 2026 81,270.40 | 8 Sep 2026 79,112.00 | 4 | −$6,321.15 |
| long | 15 Sep 2026 78,189.20 | 16 Sep 2026 75,644.50 | 1 | −$7,540.60 |
| long | 19 Sep 2026 80,883.90 | 29 Sep 2026 83,500.00 | 10 | $7,250.10 |
| long | 2 Oct 2026 84,880.10 | 6 Oct 2026 85,766.90 | 4 | $2,417.67 |
Similar scripts
No other indicator or strategy here shares enough of its calculations.
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 6 ms | With a workaround 1,000 bars in 25 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
Zeal Terminal's engine currently reads an order side written as true as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 13) so the engine trades the way the script says. The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
“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. PineTS runs Pine Script v5 and v6 only.
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/// © akrit8888// @version=4// "This Script is for demonstration of repaint by using security function to lookup the Future" // "And should NOT by any means be use in as a real trading strategy."strategy("Repaint Demonstration in Security Function Call using Higher TF", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100)bigTF = input("W", "Future Sight: ", input.resolution)bigTFClose = security(syminfo.tickerid, bigTF, close)buy = crossover(close, bigTFClose)sell = crossover(bigTFClose, close)plot(close)plot(bigTFClose)strategy.entry("L", true, when = buy)strategy.close("L", when = sell)