Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

PSAR w- Extras

A Pine Script v4 strategy built on SAR (0.02, 0.02), Crossunder (psar, close) and Crossover (psar, close). It has 2 order rules, 1 entry among them, and trades long only with the default settings. Exits use a stop loss. Each trade commits 100% of equity and pays 0.25% commission. 1 setting.

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 PSAR w- Extras repaint?
No
No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
How did PSAR w- Extras do on BTCUSDT 1D with default settings?
+70.61%
From 26 Jan 2024 to 21 Oct 2026, over 12 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can PSAR w- Extras be converted to Pine Script v5?
Yes
The upgrade takes 1 step, from v4; each was run before and after on the same candles with identical results, and the v5 script can be downloaded below.
Does PSAR w- Extras use a stop loss?
Yes
strategy.exit sets a stop on line 19.
Does PSAR w- Extras run in Zeal Terminal?
Yes
It compiles in 17 ms and runs 1,000 bars in 24 ms, in the browser.

BTCUSDT · 1D · default settings

  • Plot
  • Plot
  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (1)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$1,547$2,025Equity from $1,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots. 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 18) so the engine trades the way the script says.
Net profit
+70.61%
$706.07
Buy and hold
+102.5%
same period
Closed trades
12
12 won · 0 lost
Profitable
100.0%
of closed trades
Profit factor
166.54
gross profit ÷ gross loss
Max drawdown
38.29%
−$654.88

One run with the author's default settings, $1,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

    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 18. 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 sar → ta.sar, crossunder → ta.crossunder, crossover → ta.crossover, ema → ta.ema.
  • 1 strategy call uses the when = argument (line 18). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

Same 12 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 3: //@version=4 → //@version=5
  • Line 9: sar → ta.sar
  • Line 10: input(type = input.time) → input.time()
  • Line 11: crossunder → ta.crossunder
  • Line 12: crossover → ta.crossover
  • Line 18: strategy.entry(…, true) → strategy.entry(…, strategy.long)
  • Line 23: ema → ta.ema
⋯// © qweporiuqwer-//@version=4+//@version=5strategy("PSAR w/ Extras", overlay=true,⋯    -psar = sar(0.02, 0.02, 0.2) // these are default values+psar = ta.sar(0.02, 0.02, 0.2) // these are default values-var startTime = input(title="Start Date", type=input.time, defval=timestamp("01 Jan 2018 00:00"))+var startTime = input.time(title="Start Date", defval=timestamp("01 Jan 2018 00:00"))-psarLong  = crossunder(psar, close)+psarLong  = ta.crossunder(psar, close)-psarShort = crossover(psar, close)+psarShort = ta.crossover(psar, close)buyCondition  = psarLong⋯if time > startTime-    strategy.entry("Long", true, when=buyCondition)+    strategy.entry("Long", strategy.long, when=buyCondition)    strategy.exit("exit", "Long", ⋯plot(psar, style=plot.style_circles, linewidth=2)-plot(ema(close, 50), color = color.red)+plot(ta.ema(close, 50), color = color.red)

Clean v5

VerifiedDownload the v5 script

Same 12 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 18: when = buyCondition → if block
⋯if time > startTime-    strategy.entry("Long", strategy.long, when=buyCondition)+    if buyCondition+        strategy.entry("Long", strategy.long)    strategy.exit("exit", "Long", ⋯

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: 12 before, 14 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.

⋯// © qweporiuqwer-//@version=5+//@version=6strategy("PSAR w/ Extras", overlay=true,⋯

Settings

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

SettingDefaultType and rangeFeeds
Start Datetimestamp("01 Jan 2018 00:00")timeentry Long exit exit line 17

What it calculates

  • SAR (sar, ta.sar in v5)0.02, 0.02, 0.2psar · line 9
  • Crossunder (crossunder, ta.crossunder in v5)psar, closepsarLong · line 11
  • Crossover (crossover, ta.crossover in v5)psar, closepsarShort · line 12

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.

high · low · closehigh · low · closeprice dataclosecloseprice datatimetimeprice datastartTimeStart Datesetting · timestamp("01 Jan 2…psarSAR→ psarpsarLongCrossunder→ psarLongpsarShortCrossover→ psarShortbuyConditionbuyConditionvaluesellConditionsellConditionvalueentry:LongOpen Longstrategy.entryexit:exitexit exitstrategy.exitplot:22plotplotplot:23plotplot

Order rules

OrderFires whenBy defaultLine
Open Long longbuyConditionOn18
Exit exit stoptime > startTimeOn19

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

Does it repaint?

No

No repainting patterns in the source.

Not measuredNo trades to compareThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, but neither the live nor the historical run produced any trades in them, so the replay says nothing either way.
  • ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D+70.6%+102.5%12100%166.5438.3%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+5.6%+5.5%1100%22.3429.1%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+25.0%+9.8%4100%81.1168.9%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+19.1%+8.4%4100%65.2134.8%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+150.4%+16.7%14100%241.2858.5%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+26.4%+21.5%5100%84.4729.7%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+106.7%+148.3%12100%207.4658.6%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+46.0%+17.1%7100%127.099.7%8 May 2026 – 21 Oct 2026

Backtests are simulations on historical data and are not investment advice.

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market7100%$400.38
Sideways market4100%$249.29
Falling market1100%$60.66

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

0.0%

The 95th percentile of the worst drawdown when the same 12 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 0.0% to 0.0%; the tick is what actually happened, 0.0%. Order luck alone moves it this much.

0%1%
All 12 trades
SideEntryExitBarsP&L
long27 Feb 2024 54,476.5027 Feb 2024 57,043.400$41.90
long26 Mar 2024 69,880.0029 Oct 2024 72,920.50217$39.91
long7 Nov 2024 75,572.0010 Nov 2024 80,733.203$68.12
long30 Nov 2024 97,460.005 Dec 2024 103,102.005$60.50
long15 Dec 2024 101,420.0016 Dec 2024 106,748.001$57.24
long7 Jan 2025 102,236.0020 Jan 2025 108,575.0013$71.89
long21 Feb 2025 98,305.009 May 2025 103,113.0077$58.51
long9 Jun 2025 105,734.0010 Jul 2025 110,887.0031$60.83
long8 Aug 2025 117,472.0014 Aug 2025 123,241.006$64.01
long3 Sep 2025 111,240.0017 Sep 2025 116,119.0014$58.86
long30 Sep 2025 114,312.003 Oct 2025 119,817.003$67.90
long26 Nov 2025 87,370.0028 Nov 2025 91,036.702$60.66

Similar scripts

Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.

ScriptSharesTypeNetTradesMax drawdown
PSAR w- Extras this page—v4 strategy+70.6%1238.3%
Parabolic SAR by Zeal Terminalsarv5 indicatorindicator

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 17 msWith a workaround 1,000 bars in 24 msNot measured
PineTSNo 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 18) so the engine trades the way the script says.

“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/// © qweporiuqwer//@version=4strategy("PSAR w/ Extras", overlay=true,     default_qty_type=strategy.percent_of_equity, default_qty_value=100,     initial_capital=1000,     commission_type=strategy.commission.percent, commission_value=0.25)    psar = sar(0.02, 0.02, 0.2) // these are default valuesvar startTime = input(title="Start Date", type=input.time, defval=timestamp("01 Jan 2018 00:00"))psarLong  = crossunder(psar, close)psarShort = crossover(psar, close)buyCondition  = psarLongsellCondition = psarShorttrailingStopArm = 5trailingStopCatch = 1if time > startTime    strategy.entry("Long", true, when=buyCondition)    strategy.exit("exit", "Long",          trail_points = close * (trailingStopArm * 0.01) / syminfo.mintick,         trail_offset = close * (trailingStopCatch * 0.01) / syminfo.mintick)plot(psar, style=plot.style_circles, linewidth=2)plot(ema(close, 50), color = color.red)