Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

Strategy BackTest Display Statistics - TraderHalai

A Pine Script v5 strategy built on SMA (close, 2) and Crossunder (smallMA, buyMA). It has 3 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 5% of equity and pays 0.1% commission. 5 settings; defaults include Source close, Small Moving Average 2 and Big Moving Average 8.

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 Strategy BackTest Display Statistics - TraderHalai repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 14 of 14 trades.
How did Strategy BackTest Display Statistics - TraderHalai do on BTCUSDT 1D with default settings?
+0.98%
From 26 Jan 2024 to 21 Oct 2026, over 51 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Does Strategy BackTest Display Statistics - TraderHalai 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: 51 before, 51 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
Does Strategy BackTest Display Statistics - TraderHalai use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does Strategy BackTest Display Statistics - TraderHalai run in Zeal Terminal?
Yes
It compiles in 27 ms and runs 1,000 bars in 24 ms, in the browser.

BTCUSDT · 1D · default settings

  • SMA
  • SMA
  • SMA
  • Crossunder
  • 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 (5)
0.0050,000100,000AprJulOct2025AprJulOct2026AprJulOct$10,098$20,253Equity from $10,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. The script plots nothing itself; the lines and the lower pane are its own calculations, drawn for reference.
Table drawn by the script, as it stood on the last bar
Total Trades: 51Starting: $10000Avg Win: $24.93Profit Factor: 1.14Return: +0.98%
Win Rate: 60.78%Ending: $10098.2Avg Loss: $33.74Max Runup: 372.21Max DD: 3.33%
Net profit
+0.98%
$98.20
Buy and hold
+102.5%
same period
Closed trades
51
31 won · 20 lost
Profitable
60.8%
of closed trades
Profit factor
1.15
gross profit ÷ gross loss
Max drawdown
3.25%
−$336.65

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

  • 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
SourceclosesourcesmallMA bigMA buyMA
Small Moving Average2intsmallMA
Big Moving Average8intbigMA buyMA
Percent below to buy %1intbuyMA
Draw Testertrueboolline 57

What it calculates

  • SMASource (close), Small Moving Average (2)smallMA · line 22
  • SMASource (close), Big Moving Average (8)bigMA · line 23
  • SMASource (close), Big Moving Average (8)buyMA · line 24
  • CrossundersmallMA, buyMAbuy · line 25

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.

closecloseprice datasmallMAPeriodSmall Moving Averagesetting · 2bigMAPeriodBig Moving Averagesetting · 8percentBelowToBuyPercent below to buy %setting · 1smallMASMA→ smallMAbigMASMA→ bigMAbuyMASMA→ buyMAbuyCrossunder→ buybalance, testTable, _cellText, _factor, dollarReturnbalance · testTable +35 valuesbgcolorColourbgcolorentry:BUYOpen BUYstrategy.entryclose:BUYClose BUYstrategy.close

Order rules

OrderFires whenBy defaultLine
Open BUY long(buy)On27
Close BUY(strategy.openprofit >= strategy.position_avg_price * 0.01)On29
Close BUY(ta.barssince(buy) >= 7)On31

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, and the live replay matched history.

14/14trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • 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+1.0%+102.5%5161%1.153.2%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−0.1%+5.5%3152%0.890.8%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−2.9%+9.8%6050%0.764.7%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.7%+8.4%4068%1.381.4%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−2.5%+16.7%7276%0.725.3%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.1%+21.5%5074%1.090.7%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+1.4%+148.3%6080%1.322.3%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−0.2%+17.1%3263%0.860.9%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 market1968%$321.82
Sideways market1753%−$77.18
Falling market1560%−$146.45

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

How bad could the drawdown be?

3.7%

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

0%4%
All 51 trades
SideEntryExitBarsP&L
long24 Feb 2024 50,744.202 Mar 2024 62,387.907$113.50
long17 Mar 2024 65,300.6030 Mar 2024 69,850.5013$34.15
long3 Apr 2024 65,464.0010 Apr 2024 69,146.007$27.47
long13 Apr 2024 67,116.5020 Apr 2024 63,818.007−$25.97
long27 Apr 2024 63,770.004 May 2024 62,882.007−$8.07
long11 May 2024 60,800.0018 May 2024 67,024.007$50.79
long2 Jun 2024 67,766.809 Jun 2024 69,310.507$10.57
long12 Jun 2024 67,314.2026 Jun 2024 61,806.0014−$42.68
long5 Jul 2024 57,050.0012 Jul 2024 57,339.907$1.56
long26 Jul 2024 65,799.908 Aug 2024 55,133.8013−$83.21
long16 Aug 2024 57,541.1023 Aug 2024 60,375.807$23.77
long28 Aug 2024 59,415.004 Sep 2024 57,487.707−$17.36
long5 Sep 2024 57,970.9012 Sep 2024 57,338.007−$6.50
long2 Oct 2024 60,804.909 Oct 2024 62,160.507$10.20
long11 Oct 2024 60,326.4018 Oct 2024 67,421.807$58.20
long24 Oct 2024 66,668.603 Nov 2024 69,374.7010$19.54
long4 Nov 2024 68,776.0011 Nov 2024 80,370.007$84.50
long27 Nov 2024 91,965.204 Dec 2024 95,849.707$20.58
long11 Dec 2024 96,593.0018 Dec 2024 106,134.007$49.60
long20 Dec 2024 97,461.9027 Dec 2024 95,791.607−$9.86
long28 Dec 2024 94,299.004 Jan 2025 98,174.207$20.11
long9 Jan 2025 95,060.6016 Jan 2025 100,497.007$28.45
long28 Jan 2025 102,083.009 Feb 2025 96,444.8012−$29.59
long25 Feb 2025 91,552.904 Mar 2025 86,221.207−$31.05
long9 Mar 2025 86,222.5016 Mar 2025 84,338.407−$12.26
long30 Mar 2025 82,648.5014 Apr 2025 83,760.0015$5.88
long30 May 2025 105,590.0013 Jun 2025 105,672.0014−$0.63
long14 Jun 2025 106,067.0028 Jun 2025 107,048.0014$3.72
long2 Aug 2025 113,298.009 Aug 2025 116,675.007$14.28
long17 Aug 2025 117,381.0024 Aug 2025 115,438.007−$9.54
long26 Aug 2025 110,112.006 Sep 2025 110,660.0011$1.53
long23 Sep 2025 112,651.0030 Sep 2025 114,312.007$6.55
long11 Oct 2025 112,774.0018 Oct 2025 106,432.007−$29.96
long31 Oct 2025 108,323.0011 Nov 2025 106,011.0011−$11.97
long14 Nov 2025 99,692.0021 Nov 2025 86,637.207−$68.11
long2 Dec 2025 86,286.0014 Dec 2025 90,240.0012$22.30
long15 Dec 2025 88,172.2022 Dec 2025 88,658.907$1.79
long11 Jan 2026 90,504.7018 Jan 2026 95,147.807$25.15
long20 Jan 2026 92,631.0027 Jan 2026 88,347.107−$24.67
long30 Jan 2026 84,650.206 Feb 2026 62,909.907−$132.03
long12 Feb 2026 67,082.503 Mar 2026 68,830.1019$12.11
long8 Mar 2026 67,262.9015 Mar 2026 71,211.907$28.59
long20 Mar 2026 69,930.0027 Mar 2026 68,820.307−$9.03
long28 Mar 2026 66,407.304 Apr 2026 66,964.307$3.23
long30 Apr 2026 75,780.007 May 2026 81,447.007$36.77
long14 May 2026 79,313.604 Jun 2026 64,142.8021−$98.01
long19 Jun 2026 62,958.002 Jul 2026 60,024.0013−$24.41
long26 Jul 2026 64,375.009 Aug 2026 64,962.6014$3.57
long12 Aug 2026 63,600.0019 Aug 2026 64,725.407$7.86
long3 Sep 2026 77,340.0024 Sep 2026 84,397.6021$44.77
long9 Oct 2026 81,754.5016 Oct 2026 82,245.907$2.02

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
Strategy BackTest Display Statistics - TraderHalai this page—v5 strategy+1.0%513.2%
Follow the Crypto Shorts by xtradernetsmav4 strategyNo trades on this market
buy down and sell high trend 200 sma and ma cross by willi130503smav4 strategyNo trades on this market
Mayer Multiple Strategy by xtradernetsmav4 strategyNo trades on this market
Moving Average Cross Strategy early Closing by Geduldtradersmav4 strategy+73.8%20151.5%
MFI Simple Strategy by OztheWozsmav5 strategy−0.2%283.2%

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.

  • 4 settings use the untyped input() (line 18, 19, 20, 21). It still compiles in v6; input.int, input.float or input.source state the type.
  • No v6-only features. v6 is not needed to run this script.

Clean v5

VerifiedDownload the v5 script

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

  • Line 18: input() → input.source()
  • Line 19: input() → input.int()
  • Line 20: input() → input.int()
  • Line 21: input() → input.int()
⋯//DEMO basic strategy - Use your own strategy here -  Jaws Mean Reversion from my profile used here-source = input(title = "Source", defval = close)+source = input.source(title = "Source", defval = close)-smallMAPeriod = input(title = "Small Moving Average", defval = 2)+smallMAPeriod = input.int(title = "Small Moving Average", defval = 2)-bigMAPeriod = input(title = "Big Moving Average", defval = 8)+bigMAPeriod = input.int(title = "Big Moving Average", defval = 8)-percentBelowToBuy = input(title = "Percent below to buy %", defval = 1)+percentBelowToBuy = input.int(title = "Percent below to buy %", defval = 1)smallMA = ta.sma(source, smallMAPeriod)⋯

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

⋯//Thanks and enjoy! :)-//@version=5+//@version=6strategy("Strategy BackTest Display Statistics - TraderHalai", overlay=true, default_qty_value= 5, default_qty_type = strategy.percent_of_equity, initial_capital=10000,  commission_type=strategy.commission.percent, commission_value=0.1)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 27 msYes 1,000 bars in 24 msNot 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/// © TraderHalai// This script was born out of my quest to be able to display strategy back test statistics on charts to allow for easier backtesting on devices that do not natively support backtest engine (such as mobile phones, when I am backtesting from away from my computer). There are already a few good ones on TradingView, but most / many are too complicated for my needs.////Found an excellent display backtest engine by 'The Art of Trading'. This script is a snippet of his hard work, with some very minor tweaks and changes. Much respect to the original author.////Full credit to the original author of this script. It can be found here: https://www.tradingview.com/script/t776tkZv-Hammers-Stars-Strategy/?offer_id=10&aff_id=15271//// This script can be copied and airlifted onto existing strategy scripts of your own, and integrates out of the box without implementation of additional functions. I've also added Max Runup, Average Win and Average Loss per trade to the orignal script.////Will look to add in more performance metrics in future, as I further develop this script.////Feel free to use this display panel in your scripts and strategies.//Thanks and enjoy! :)//@version=5strategy("Strategy BackTest Display Statistics - TraderHalai", overlay=true, default_qty_value= 5, default_qty_type = strategy.percent_of_equity, initial_capital=10000,  commission_type=strategy.commission.percent, commission_value=0.1)//DEMO basic strategy - Use your own strategy here -  Jaws Mean Reversion from my profile used heresource = input(title = "Source", defval = close)smallMAPeriod = input(title = "Small Moving Average", defval = 2)bigMAPeriod = input(title = "Big Moving Average", defval = 8)percentBelowToBuy = input(title = "Percent below to buy %", defval = 1)smallMA = ta.sma(source, smallMAPeriod)bigMA =  ta.sma(source, bigMAPeriod) buyMA = ((100 - percentBelowToBuy) / 100) * ta.sma(source, bigMAPeriod)[0]buy = ta.crossunder(smallMA, buyMA)if(buy)    strategy.entry("BUY", strategy.long)if(strategy.openprofit >= strategy.position_avg_price * 0.01) // 1% profit target    strategy.close("BUY")if(ta.barssince(buy) >= 7) //Timed Exit, if you fail to make 1 percent in 7 candles.    strategy.close("BUY")    ///////////////////////////// --- BEGIN TESTER CODE --- ////////////////////////// COPY below into your strategy to enable display////////////////////////////////////////////////////////////////////////////////// Declare performance tracking variablesdrawTester = input.bool(true, "Draw Tester")var balance = strategy.initial_capitalvar drawdown = 0.0var maxDrawdown = 0.0var maxBalance = 0.0var totalWins = 0var totalLoss = 0// Prepare stats tablevar table testTable = table.new(position.top_right, 5, 2, border_width=1)f_fillCell(_table, _column, _row, _title, _value, _bgcolor, _txtcolor) =>    _cellText = _title + "\n" + _value    table.cell(_table, _column, _row, _cellText, bgcolor=_bgcolor, text_color=_txtcolor)    // Custom function to truncate (cut) excess decimal placestruncate(_number, _decimalPlaces) =>    _factor = math.pow(10, _decimalPlaces)    int(_number * _factor) / _factor    // Draw stats tablevar bgcolor = color.new(color.black,0)if drawTester    if barstate.islastconfirmedhistory        // Update table        dollarReturn = strategy.netprofit        f_fillCell(testTable, 0, 0, "Total Trades:", str.tostring(strategy.closedtrades), bgcolor, color.white)        f_fillCell(testTable, 0, 1, "Win Rate:", str.tostring(truncate((strategy.wintrades/strategy.closedtrades)*100,2)) + "%", bgcolor, color.white)        f_fillCell(testTable, 1, 0, "Starting:", "$" + str.tostring(strategy.initial_capital), bgcolor, color.white)        f_fillCell(testTable, 1, 1, "Ending:", "$" + str.tostring(truncate(strategy.initial_capital + strategy.netprofit,2)), bgcolor, color.white)        f_fillCell(testTable, 2, 0, "Avg Win:", "$"+ str.tostring(truncate(strategy.grossprofit / strategy.wintrades, 2)), bgcolor, color.white)        f_fillCell(testTable, 2, 1, "Avg Loss:", "$"+ str.tostring(truncate(strategy.grossloss / strategy.losstrades, 2)), bgcolor, color.white)        f_fillCell(testTable, 3, 0, "Profit Factor:", str.tostring(truncate(strategy.grossprofit / strategy.grossloss,2)), strategy.grossprofit > strategy.grossloss ? color.green : color.red, color.white)        f_fillCell(testTable, 3, 1, "Max Runup:",  str.tostring(truncate(strategy.max_runup, 2 )), bgcolor, color.white)        f_fillCell(testTable, 4, 0, "Return:", (dollarReturn > 0 ? "+" : "") + str.tostring(truncate((dollarReturn / strategy.initial_capital)*100,2)) + "%", dollarReturn > 0 ? color.green : color.red, color.white)        f_fillCell(testTable, 4, 1, "Max DD:", str.tostring(truncate((strategy.max_drawdown / strategy.equity) * 100 ,2)) + "%", color.red, color.white)// --- END TESTER CODE --- ///////////////