Pine Script v5 · Strategy
Smoothed Heikin Ashi Trend on Chart - TraderHalai BACKTEST
A Pine Script v5 strategy built on SMA (reverseClose, 10), EMA (reverseClose, 10) and HMA (reverseClose, 10). It has 6 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss. Each trade commits 10% of equity and pays no commission. 10 settings; defaults include Method SMA, Smoothing period 10 and Prices Decimal Places 2.
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 Smoothed Heikin Ashi Trend on Chart - TraderHalai BACKTEST repaint?
- Yes
- At least one pattern in the source can repaint: higher-timeframe data, intrabar recalculation.
- How did Smoothed Heikin Ashi Trend on Chart - TraderHalai BACKTEST do on BTCUSDT 1D with default settings?
- +1.34%
- From 26 Jan 2024 to 21 Oct 2026, over 113 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does Smoothed Heikin Ashi Trend on Chart - TraderHalai BACKTEST 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: 113 before, 113 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 Smoothed Heikin Ashi Trend on Chart - TraderHalai BACKTEST use a stop loss?
- Yes
- strategy.exit sets a stop on line 84, 86.
- Does Smoothed Heikin Ashi Trend on Chart - TraderHalai BACKTEST run in Zeal Terminal?
- Yes
- It compiles in 44 ms and runs 1,000 bars in 123 ms, in the browser.
BTCUSDT · 1D · default settings
- Long Stop Loss
- Short Stop Loss
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
| Total Trades: 113 | Starting: $1000000 | Avg Win: $4746.84 | Profit Factor: 1.1 | Return: +1.33% |
| Win Rate: 26.54% | Ending: $1013379.76 | Avg Loss: $1554.52 | Max Runup: 54106.18 | Max DD: 5.66% |
- Net profit
- +1.34%
- $13,379.80
- Buy and hold
- +102.5%
- same period
- Closed trades
- 113
- 30 won · 83 lost
- Profitable
- 26.5%
- of closed trades
- Profit factor
- 1.10
- gross profit ÷ gross loss
- Max drawdown
- 5.61%
- −$57,429.50
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
3 settings do nothing
“Show Info Box”, “Prices Decimal Places”, “Info Box Offset” are declared but never read.
-
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 |
|---|---|---|---|
| Use smoothing Heikin Ashi | true | bool | shouldApplySmoothing |
| Method | SMA | string · options ["SMA", "EMA", "HMA", "VWMA", "RMA"] | line 48 line 50 line 52 line 54 line 56 |
| Smoothing period | 10 | int | smaSmoothed emaSmoothed hmaSmoothed vwmaSmoothed rmaSmoothed shouldApplySmoothing |
| Show Info Box | true | bool | unused |
| Prices Decimal Places | 2 | int | unused |
| Info Box Offset | 5 | int | unused |
| Repaint - Keep on for live / Off for backtest | false | bool | candleClose candleOpen candleLow candleHigh haClose haOpen haLow haHigh |
| Long Stop Loss (%) | 1 | float · min 0.0 · step 0.1 | longStopPrice |
| Short Stop Loss (%) | 1 | float · min 0.0 · step 0.1 | shortStopPrice |
| Draw Tester | true | bool | line 112 |
What it calculates
- SMAreverseClose, Smoothing period (10)
smaSmoothed · line 40 - EMAreverseClose, Smoothing period (10)
emaSmoothed · line 41 - HMAreverseClose, Smoothing period (10)
hmaSmoothed · line 42 - VWMAreverseClose, Smoothing period (10)
vwmaSmoothed · line 43 - RMAreverseClose, Smoothing period (10)
rmaSmoothed · line 44
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 | (ta.crossover(candleClose, smoothedReverseClose)) | On | 65 |
| cancel LONG | (ta.crossover(candleClose, smoothedReverseClose)) | On | 67 |
| Open SHORT short | (ta.crossunder(candleClose, smoothedReverseClose)) | On | 69 |
| cancel SHORT | (ta.crossunder(candleClose, smoothedReverseClose)) | On | 71 |
| Exit XL STP stop | (strategy.position_size > 0) | On | 84 |
| Exit XS STP stop | (strategy.position_size < 0) | On | 86 |
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.
- CheckHigher-timeframe data1 request.security call(s) use lookahead_on (line 20). Without a [1] offset this reads future bars in history.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- CheckIntrabar recalculationreads realtime-only state. 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
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 | +1.3% | +102.5% | 113 | 27% | 1.10 | 5.6% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +2.3% | +5.5% | 133 | 35% | 1.34 | 1.7% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −4.1% | +9.8% | 115 | 20% | 0.73 | 5.9% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −1.4% | +8.4% | 121 | 24% | 0.84 | 2.7% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +1.0% | +16.7% | 111 | 22% | 1.06 | 7.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −0.9% | +21.5% | 104 | 28% | 0.90 | 2.2% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −2.3% | +148.3% | 120 | 23% | 0.83 | 5.3% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +3.0% | +17.1% | 99 | 34% | 1.52 | 1.8% | 8 May 2026 – 21 Oct 2026 |
Higher-timeframe data for request.security(): heikinashi:SYMBOL D (Binance BTCUSDT 1d, as Heikin-Ashi by the engine), heikinashi:BINANCE:BTCUSDT D (Binance BTCUSDT 1d, as Heikin-Ashi by the engine), 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 | 42 | 24% | −$12,255.80 |
| Sideways market | 47 | 30% | $33,675.80 |
| Falling market | 24 | 25% | −$8,040.23 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
5.8%
The 95th percentile of the worst drawdown when the same 113 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 2.6% to 5.8%; the tick is what actually happened, 5.5%. Order luck alone moves it this much.
All 113 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 18 Mar 2024 68,393.50 | 25 Mar 2024 69,077.40 | 7 | −$1,000.01 |
| long | 27 Mar 2024 69,988.00 | 28 Mar 2024 69,288.10 | 1 | −$999.00 |
| short | 4 Apr 2024 65,963.30 | 5 Apr 2024 68,487.80 | 1 | −$3,819.52 |
| long | 9 Apr 2024 71,620.00 | 10 Apr 2024 69,146.00 | 1 | −$3,434.24 |
| short | 14 Apr 2024 63,924.50 | 15 Apr 2024 65,661.90 | 1 | −$2,692.64 |
| long | 24 Apr 2024 66,414.00 | 25 Apr 2024 64,289.60 | 1 | −$3,160.54 |
| short | 26 Apr 2024 64,498.30 | 6 May 2024 65,143.30 | 10 | −$984.90 |
| long | 7 May 2024 63,165.20 | 8 May 2024 62,312.10 | 1 | −$1,328.87 |
| short | 9 May 2024 61,193.00 | 10 May 2024 63,074.00 | 1 | −$3,020.29 |
| long | 11 May 2024 60,800.00 | 12 May 2024 60,826.00 | 1 | $41.89 |
| short | 12 May 2024 60,826.00 | 13 May 2024 61,484.00 | 1 | −$1,059.72 |
| long | 15 May 2024 61,577.50 | 16 May 2024 66,206.50 | 1 | $7,356.08 |
| short | 16 May 2024 66,206.50 | 17 May 2024 65,235.20 | 1 | $1,446.39 |
| long | 17 May 2024 65,235.20 | 31 May 2024 68,352.20 | 14 | $4,717.57 |
| short | 31 May 2024 68,352.20 | 3 Jun 2024 69,035.70 | 3 | −$992.07 |
| long | 5 Jun 2024 70,537.80 | 7 Jun 2024 69,832.40 | 2 | −$991.07 |
| short | 13 Jun 2024 68,264.00 | 15 Jul 2024 60,797.90 | 32 | $10,828.50 |
| long | 15 Jul 2024 60,797.90 | 1 Aug 2024 64,628.00 | 17 | $6,305.44 |
| short | 1 Aug 2024 64,628.00 | 2 Aug 2024 65,354.00 | 1 | −$1,131.47 |
| long | 15 Aug 2024 58,683.40 | 16 Aug 2024 57,541.10 | 1 | −$1,958.45 |
| short | 16 Aug 2024 57,541.10 | 17 Aug 2024 58,874.60 | 1 | −$2,327.10 |
| long | 18 Aug 2024 59,492.00 | 19 Aug 2024 58,427.30 | 1 | −$1,792.77 |
| short | 20 Aug 2024 59,438.50 | 21 Aug 2024 59,013.80 | 1 | $714.52 |
| long | 21 Aug 2024 59,013.80 | 22 Aug 2024 61,156.00 | 1 | $3,632.65 |
| short | 22 Aug 2024 61,156.00 | 23 Aug 2024 60,375.80 | 1 | $1,281.30 |
| long | 23 Aug 2024 60,375.80 | 27 Aug 2024 59,772.10 | 4 | −$1,005.63 |
| short | 29 Aug 2024 59,034.90 | 30 Aug 2024 59,625.30 | 1 | −$1,004.63 |
| long | 14 Sep 2024 60,498.00 | 15 Sep 2024 59,893.00 | 1 | −$1,003.62 |
| short | 3 Oct 2024 60,649.30 | 4 Oct 2024 61,255.80 | 1 | −$1,002.63 |
| long | 14 Oct 2024 62,870.00 | 28 Oct 2024 68,021.70 | 14 | $8,207.40 |
| short | 28 Oct 2024 68,021.70 | 29 Oct 2024 69,962.20 | 1 | −$2,880.82 |
| long | 29 Oct 2024 69,962.20 | 1 Nov 2024 69,262.60 | 3 | −$1,006.95 |
| short | 6 Nov 2024 69,372.00 | 7 Nov 2024 75,572.00 | 1 | −$8,990.33 |
| long | 7 Nov 2024 75,572.00 | 28 Nov 2024 95,863.10 | 21 | $26,768.00 |
| short | 28 Nov 2024 95,863.10 | 29 Nov 2024 95,644.00 | 1 | $234.00 |
| long | 29 Nov 2024 95,644.00 | 2 Dec 2024 94,687.60 | 3 | −$1,023.95 |
| short | 4 Dec 2024 95,849.70 | 5 Dec 2024 98,587.30 | 1 | −$2,921.64 |
| long | 6 Dec 2024 96,945.60 | 9 Dec 2024 95,976.20 | 3 | −$1,020.00 |
| short | 12 Dec 2024 101,125.00 | 13 Dec 2024 100,004.00 | 1 | $1,129.28 |
| long | 13 Dec 2024 100,004.00 | 19 Dec 2024 99,004.20 | 6 | −$1,020.12 |
| short | 21 Dec 2024 97,805.40 | 24 Dec 2024 98,783.50 | 3 | −$1,019.10 |
| long | 4 Jan 2025 98,174.20 | 7 Jan 2025 97,192.40 | 3 | −$1,018.08 |
| short | 10 Jan 2025 92,552.50 | 11 Jan 2025 94,726.10 | 1 | −$2,388.56 |
| long | 17 Jan 2025 99,987.30 | 27 Jan 2025 98,987.40 | 10 | −$1,014.67 |
| short | 29 Jan 2025 101,336.00 | 30 Jan 2025 103,733.00 | 1 | −$2,398.43 |
| long | 31 Jan 2025 104,723.00 | 1 Feb 2025 102,430.00 | 1 | −$2,214.59 |
| short | 2 Feb 2025 100,636.00 | 3 Feb 2025 101,642.00 | 1 | −$1,009.04 |
| long | 17 Feb 2025 96,118.10 | 18 Feb 2025 95,780.00 | 1 | −$354.59 |
| short | 18 Feb 2025 95,780.00 | 19 Feb 2025 96,737.80 | 1 | −$1,007.68 |
| long | 22 Feb 2025 96,182.00 | 23 Feb 2025 96,551.00 | 1 | $386.23 |
| short | 23 Feb 2025 96,551.00 | 24 Feb 2025 96,258.00 | 1 | $305.62 |
| long | 24 Feb 2025 96,258.00 | 25 Feb 2025 91,552.90 | 1 | −$4,923.99 |
| short | 25 Feb 2025 91,552.90 | 2 Mar 2025 92,468.40 | 5 | −$1,002.43 |
| long | 8 Mar 2025 86,801.70 | 9 Mar 2025 86,222.50 | 1 | −$668.32 |
| short | 9 Mar 2025 86,222.50 | 20 Mar 2025 87,084.70 | 11 | −$1,000.77 |
| long | 21 Mar 2025 84,223.40 | 29 Mar 2025 83,381.10 | 8 | −$999.77 |
| short | 31 Mar 2025 82,390.00 | 1 Apr 2025 83,213.90 | 1 | −$998.76 |
| long | 13 Apr 2025 85,276.90 | 14 Apr 2025 83,760.00 | 1 | −$1,774.83 |
| short | 31 May 2025 103,985.00 | 1 Jun 2025 105,025.00 | 1 | −$995.99 |
| long | 11 Jun 2025 110,274.00 | 12 Jun 2025 108,645.00 | 1 | −$1,470.06 |
| short | 16 Jun 2025 105,594.00 | 17 Jun 2025 106,795.00 | 1 | −$1,129.55 |
| long | 18 Jun 2025 104,551.00 | 19 Jun 2025 104,887.00 | 1 | $318.57 |
| short | 19 Jun 2025 104,887.00 | 20 Jun 2025 105,936.00 | 1 | −$992.71 |
| long | 26 Jun 2025 107,341.00 | 1 Jul 2025 106,267.00 | 5 | −$991.72 |
| short | 26 Jul 2025 117,614.00 | 27 Jul 2025 118,790.00 | 1 | −$990.73 |
| long | 29 Jul 2025 118,062.00 | 30 Jul 2025 117,951.00 | 1 | −$93.53 |
| short | 30 Jul 2025 117,951.00 | 9 Aug 2025 116,675.00 | 10 | $1,070.61 |
| long | 9 Aug 2025 116,675.00 | 18 Aug 2025 115,508.00 | 9 | −$990.72 |
| short | 20 Aug 2025 112,873.00 | 21 Aug 2025 114,271.00 | 1 | −$1,226.08 |
| long | 9 Sep 2025 112,065.00 | 10 Sep 2025 110,945.00 | 1 | −$988.50 |
| short | 24 Sep 2025 111,999.00 | 25 Sep 2025 113,307.00 | 1 | −$1,153.47 |
| long | 2 Oct 2025 118,595.00 | 10 Oct 2025 117,409.00 | 8 | −$986.36 |
| short | 12 Oct 2025 110,644.00 | 13 Oct 2025 114,959.00 | 1 | −$3,842.29 |
| long | 26 Oct 2025 111,646.00 | 29 Oct 2025 110,530.00 | 3 | −$981.53 |
| short | 1 Nov 2025 109,608.00 | 2 Nov 2025 110,704.00 | 1 | −$980.55 |
| long | 29 Nov 2025 90,890.70 | 1 Dec 2025 89,981.80 | 2 | −$979.57 |
| short | 3 Dec 2025 91,277.90 | 4 Dec 2025 93,429.90 | 1 | −$2,307.22 |
| long | 4 Dec 2025 93,429.90 | 5 Dec 2025 92,078.10 | 1 | −$1,412.63 |
| short | 8 Dec 2025 90,395.30 | 9 Dec 2025 91,299.30 | 1 | −$974.87 |
| long | 11 Dec 2025 92,015.40 | 12 Dec 2025 91,095.20 | 1 | −$973.90 |
| short | 14 Dec 2025 90,240.00 | 30 Dec 2025 87,237.10 | 16 | $3,237.52 |
| long | 30 Dec 2025 87,237.10 | 31 Dec 2025 88,485.50 | 1 | $1,396.88 |
| short | 31 Dec 2025 88,485.50 | 1 Jan 2026 87,648.20 | 1 | $925.00 |
| long | 1 Jan 2026 87,648.20 | 2 Jan 2026 88,839.10 | 1 | $1,329.41 |
| short | 2 Jan 2026 88,839.10 | 3 Jan 2026 89,995.10 | 1 | −$1,275.05 |
| long | 3 Jan 2026 89,995.10 | 20 Jan 2026 89,095.20 | 17 | −$978.54 |
| short | 22 Jan 2026 89,454.70 | 23 Jan 2026 90,349.30 | 1 | −$977.55 |
| long | 4 Mar 2026 68,338.00 | 7 Mar 2026 67,654.60 | 3 | −$976.59 |
| short | 10 Mar 2026 68,432.20 | 11 Mar 2026 69,948.60 | 1 | −$2,161.96 |
| long | 11 Mar 2026 69,948.60 | 12 Mar 2026 69,249.10 | 1 | −$973.44 |
| short | 23 Mar 2026 67,859.00 | 24 Mar 2026 70,906.40 | 1 | −$4,367.18 |
| long | 7 Apr 2026 68,853.70 | 1 May 2026 76,346.60 | 24 | $10,535.20 |
| short | 1 May 2026 76,346.60 | 2 May 2026 78,231.10 | 1 | −$2,415.66 |
| long | 3 May 2026 78,686.80 | 15 May 2026 81,090.00 | 12 | $2,981.44 |
| short | 15 May 2026 81,090.00 | 16 May 2026 79,113.20 | 1 | $2,387.07 |
| long | 16 May 2026 79,113.20 | 17 May 2026 78,148.10 | 1 | −$1,197.49 |
| short | 17 May 2026 78,148.10 | 16 Jun 2026 66,328.70 | 30 | $14,827.60 |
| long | 16 Jun 2026 66,328.70 | 17 Jun 2026 65,665.40 | 1 | −$995.22 |
| short | 20 Jun 2026 63,543.90 | 21 Jun 2026 64,298.00 | 1 | −$1,179.89 |
| long | 22 Jun 2026 63,312.00 | 23 Jun 2026 64,020.00 | 1 | $1,110.50 |
| short | 23 Jun 2026 64,020.00 | 5 Jul 2026 63,144.00 | 12 | $1,360.31 |
| long | 5 Jul 2026 63,144.00 | 6 Jul 2026 62,512.60 | 1 | −$995.52 |
| short | 26 Jul 2026 64,375.00 | 27 Jul 2026 65,400.00 | 1 | −$1,583.48 |
| long | 28 Jul 2026 63,755.90 | 29 Jul 2026 63,915.00 | 1 | $247.84 |
| short | 29 Jul 2026 63,915.00 | 30 Jul 2026 64,554.20 | 1 | −$993.18 |
| long | 7 Aug 2026 64,323.60 | 11 Aug 2026 63,680.40 | 4 | −$992.19 |
| short | 13 Aug 2026 63,480.00 | 17 Aug 2026 64,114.80 | 4 | −$991.19 |
| long | 19 Aug 2026 64,725.40 | 4 Sep 2026 81,270.40 | 16 | $25,311.20 |
| short | 4 Sep 2026 81,270.40 | 5 Sep 2026 79,660.80 | 1 | $2,011.27 |
| long | 5 Sep 2026 79,660.80 | 7 Sep 2026 78,864.20 | 2 | −$1,017.53 |
| short | 10 Sep 2026 78,306.40 | 11 Sep 2026 79,089.50 | 1 | −$1,016.51 |
| long | 20 Sep 2026 81,250.00 | 8 Oct 2026 80,437.50 | 18 | −$1,015.49 |
| short | 9 Oct 2026 81,754.50 | 10 Oct 2026 82,635.60 | 1 | −$1,093.34 |
Similar scripts
Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Smoothed Heikin Ashi Trend on Chart - TraderHalai BACKTEST this page | — | v5 strategy | +1.3% | 113 | 5.6% |
| TriautoETF(TQQQ) Short Strategy B1 by BBcom | hma vwma ema | v5 strategy | No trades on this market | ||
| Optimized Keltner Channels SL-TP Strategy for BTC by chanu_lev10k | sma ema rma | v4 strategy | −19.4% | 36 | 70.0% |
| RMI + Triple HMRSI + Double EVWRSI + TERSI + CMO Strategy by burgercrisis | rma hma ema | v4 strategy | No trades on this market | ||
| Soheil PKO's 5 min Hitman Scalp - 3MA + Laguerre RSI + ADX [Pt] by PtGambler | ema sma rma | v5 strategy | No trades on this market | ||
| Wave Trend w- VWMA overlay by jadamcraig | vwma ema sma | v4 strategy | No trades on this market | ||
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.
- 6 settings use the untyped input() (line 9, 11, 12, 13, 14, 15). 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.
Same 113 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 9: input() → input.bool()
- Line 11: input() → input.int()
- Line 12: input() → input.bool()
- Line 13: input() → input.int()
- Line 14: input() → input.int()
- Line 15: input() → input.bool()
⋯//Inputs-i_useSmooth = input ( true, "Use smoothing Heikin Ashi")+i_useSmooth = input.bool ( true, "Use smoothing Heikin Ashi")i_smoothingMethod = input.string("SMA", "Method", options=["SMA", "EMA", "HMA", "VWMA", "RMA"])-i_smoothingPeriod = input ( 10, "Smoothing period")+i_smoothingPeriod = input.int ( 10, "Smoothing period")-i_infoBox = input ( true, "Show Info Box" )+i_infoBox = input.bool ( true, "Show Info Box" )-i_decimalP = input ( 2, "Prices Decimal Places") +i_decimalP = input.int ( 2, "Prices Decimal Places") -i_boxOffSet = input ( 5, "Info Box Offset" )+i_boxOffSet = input.int ( 5, "Info Box Offset" )-i_repaint = input (false, "Repaint - Keep on for live / Off for backtest")+i_repaint = input.bool (false, "Repaint - Keep on for live / Off for backtest")i_longLossPerc = input.float(title="Long Stop Loss (%)",minval=0.0, step=0.1, defval=1) * 0.01⋯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: 113 before, 113 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.
⋯// This particular back test uses this indicator as a Trend trading tool with a tight stop loss. The equity curve as tested seems promising but requires further work to refine. Note in an actual trading setup, you may wish to use this with volatilty filters as most of the losses are in sideways, low volatility markets.-//@version=5+//@version=6strategy("Smoothed Heikin Ashi Trend on Chart - TraderHalai BACKTEST", " SHA Trend - BACKTEST", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 44 ms | With a workaround 1,000 bars in 123 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
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. Data the page supplies at the chart's own timeframe (another symbol, or Heikin-Ashi) reaches the script one bar later in Zeal Terminal's engine than on TradingView.
“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 is a backtest of the Smoothed Heikin Ashi Trend indicator, which computes the reverse candle close price required to flip a heikin ashi trend from red to green and vice versa. Original indicator can be found on the scripts section of my profile.// Default testing parameters are 10% of equity position size, with a 1% stop loss on short and long strategy.opentrades.commission// This particular back test uses this indicator as a Trend trading tool with a tight stop loss. The equity curve as tested seems promising but requires further work to refine. Note in an actual trading setup, you may wish to use this with volatilty filters as most of the losses are in sideways, low volatility markets.//@version=5strategy("Smoothed Heikin Ashi Trend on Chart - TraderHalai BACKTEST", " SHA Trend - BACKTEST", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)//Inputsi_useSmooth = input ( true, "Use smoothing Heikin Ashi")i_smoothingMethod = input.string("SMA", "Method", options=["SMA", "EMA", "HMA", "VWMA", "RMA"])i_smoothingPeriod = input ( 10, "Smoothing period")i_infoBox = input ( true, "Show Info Box" )i_decimalP = input ( 2, "Prices Decimal Places") i_boxOffSet = input ( 5, "Info Box Offset" )i_repaint = input (false, "Repaint - Keep on for live / Off for backtest")i_longLossPerc = input.float(title="Long Stop Loss (%)",minval=0.0, step=0.1, defval=1) * 0.01i_shortLossPerc = input.float(title="Short Stop Loss (%)", minval=0.0, step=0.1, defval=1) * 0.01timeperiod = timeframe.period//Security functions to avoid repaint, as per PineCodersf_secureSecurity(_symbol, _res, _src) => request.security(_symbol, _res, _src[1], lookahead = barmerge.lookahead_on)f_security(_symbol, _res, _src, _repaint) => request.security(_symbol, _res, _src[_repaint ? 0 : barstate.isrealtime ? 1 : 0])[_repaint ? 0 : barstate.isrealtime ? 0 : 1]f_secSecurity2(_symbol, _res, _src) => request.security(_symbol, _res, _src[1])candleClose = f_security(syminfo.tickerid, timeperiod, close, i_repaint)candleOpen = f_security(syminfo.tickerid, timeperiod, open, i_repaint)candleLow = f_security(syminfo.tickerid, timeperiod, low, i_repaint)candleHigh = f_security(syminfo.tickerid, timeperiod, high, i_repaint)haTicker = ticker.heikinashi(syminfo.tickerid)haClose = f_security(haTicker, timeperiod, close, i_repaint)haOpen = f_security(haTicker, timeperiod, open, i_repaint)haLow = f_security(haTicker, timeperiod, low, i_repaint)haHigh= f_security(haTicker, timeperiod, high, i_repaint)reverseClose = (2 * (haOpen[1] + haClose[1])) - candleHigh - candleLow - candleOpenif(reverseClose < candleLow) reverseClose := (candleLow + reverseClose) / 2if(reverseClose > candleHigh) reverseClose := (candleHigh + reverseClose) / 2 //Smoothing smaSmoothed = ta.sma(reverseClose, i_smoothingPeriod)emaSmoothed = ta.ema(reverseClose, i_smoothingPeriod)hmaSmoothed = ta.hma(reverseClose, i_smoothingPeriod)vwmaSmoothed = ta.vwma(reverseClose, i_smoothingPeriod)rmaSmoothed = ta.rma(reverseClose, i_smoothingPeriod)shouldApplySmoothing = i_useSmooth and i_smoothingPeriod > 1 smoothedReverseClose = reverseCloseif(shouldApplySmoothing) if(i_smoothingMethod == "SMA") smoothedReverseClose := smaSmoothed else if(i_smoothingMethod == "EMA") smoothedReverseClose := emaSmoothed else if(i_smoothingMethod == "HMA") smoothedReverseClose := hmaSmoothed else if(i_smoothingMethod == "VWMA") smoothedReverseClose := vwmaSmoothed else if(i_smoothingMethod == "RMA") smoothedReverseClose := rmaSmoothed else smoothedReverseClose := reverseClose // Default to non-smoothed for invalid smoothing type haBull = candleClose >= smoothedReverseClosehaCol = haBull ? color.green : color.red//Overall trading strategyif(ta.crossover(candleClose, smoothedReverseClose)) strategy.entry("LONG", strategy.long)else strategy.cancel("LONG")if(ta.crossunder(candleClose, smoothedReverseClose)) strategy.entry("SHORT", strategy.short)else strategy.cancel("SHORT") longStopPrice = strategy.position_avg_price * (1 - i_longLossPerc)shortStopPrice = strategy.position_avg_price * (1 + i_shortLossPerc)plot(series=(strategy.position_size > 0) ? longStopPrice : na, color=color.red, style=plot.style_cross, linewidth=2, title="Long Stop Loss")plot(series=(strategy.position_size < 0) ? shortStopPrice : na, color=color.red, style=plot.style_cross, linewidth=2, title="Short Stop Loss") plot(smoothedReverseClose, color=haCol)if (strategy.position_size > 0) strategy.exit(id="XL STP", stop=longStopPrice)if (strategy.position_size < 0) strategy.exit(id="XS STP", stop=shortStopPrice) ///////////////////////////// --- 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 --- ///////////////