Zeal Terminal Open in Zeal Terminal

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
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$1,013,380$2,025,273Equity from $1,000,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. 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. The live re-run is not offered here: the script requests heikinashi:SYMBOL D, heikinashi:BINANCE:BTCUSDT D, which this page cannot load in your browser.
Table drawn by the script, as it stood on the last bar
Total Trades: 113Starting: $1000000Avg Win: $4746.84Profit Factor: 1.1Return: +1.33%
Win Rate: 26.54%Ending: $1013379.76Avg Loss: $1554.52Max Runup: 54106.18Max 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.

SettingDefaultType and rangeFeeds
Use smoothing Heikin AshitrueboolshouldApplySmoothing
MethodSMAstring · options ["SMA", "EMA", "HMA", "VWMA", "RMA"]line 48 line 50 line 52 line 54 line 56
Smoothing period10intsmaSmoothed emaSmoothed hmaSmoothed vwmaSmoothed rmaSmoothed shouldApplySmoothing
Show Info Boxtrueboolunused
Prices Decimal Places2intunused
Info Box Offset5intunused
Repaint - Keep on for live / Off for backtestfalseboolcandleClose candleOpen candleLow candleHigh haClose haOpen haLow haHigh
Long Stop Loss (%)1float · min 0.0 · step 0.1longStopPrice
Short Stop Loss (%)1float · min 0.0 · step 0.1shortStopPrice
Draw Testertrueboolline 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.

i_smoothingPeriodSmoothing periodsetting · 10closecloseprice dataopenopenprice datalowlowprice datahighhighprice datai_longLossPercLong Stop Loss (%)setting · 1i_shortLossPercShort Stop Loss (%)setting · 1smaSmoothedSMA→ smaSmoothedemaSmoothedEMA→ emaSmoothedhmaSmoothedHMA→ hmaSmoothedvwmaSmoothedVWMA→ vwmaSmoothedrmaSmoothedRMA→ rmaSmoothedtimeperiod, haTicker, balance, testTable, _cellText, _factor, dollarReturntimeperiod · haTicker +57 valuescandleClosecandleClosevaluecandleOpencandleOpenvaluecandleLowcandleLowvaluecandleHighcandleHighvaluehaClosehaClosevaluehaOpenhaOpenvaluehaLowhaLowvaluehaHighhaHighvaluereverseClosereverseClosevaluesmoothedReverseClosesmoothedReverseClosevaluelongStopPricelongStopPricevalueshortStopPriceshortStopPricevalueshouldApplySmoothingshouldApplySmoothingconditionhaBullhaBullconditionhaCol, bgcolorColourhaCol · bgcolorentry:LONGOpen LONGstrategy.entrycancel:LONGcancel LONGstrategy.cancelentry:SHORTOpen SHORTstrategy.entrycancel:SHORTcancel SHORTstrategy.cancelexit:XL STPexit XL STPstrategy.exitexit:XS STPexit XS STPstrategy.exitplot:75Long Stop Lossplotplot:78Short Stop Lossplotplot:82plotplot

Order rules

OrderFires whenBy defaultLine
Open LONG long(ta.crossover(candleClose, smoothedReverseClose))On65
cancel LONG(ta.crossover(candleClose, smoothedReverseClose))On67
Open SHORT short(ta.crossunder(candleClose, smoothedReverseClose))On69
cancel SHORT(ta.crossunder(candleClose, smoothedReverseClose))On71
Exit XL STP stop(strategy.position_size > 0)On84
Exit XS STP stop(strategy.position_size < 0)On86

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.

32/32trades 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. On 10 of them the position changed while the bar was forming before it settled. Anyone watching live sees those changes; once the bar closes it matches history.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D+1.3%+102.5%11327%1.105.6%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+2.3%+5.5%13335%1.341.7%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−4.1%+9.8%11520%0.735.9%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−1.4%+8.4%12124%0.842.7%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+1.0%+16.7%11122%1.067.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−0.9%+21.5%10428%0.902.2%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−2.3%+148.3%12023%0.835.3%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+3.0%+17.1%9934%1.521.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 barsTradesWonP&L
Rising market4224%−$12,255.80
Sideways market4730%$33,675.80
Falling market2425%−$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.

0%7%
All 113 trades
SideEntryExitBarsP&L
short18 Mar 2024 68,393.5025 Mar 2024 69,077.407−$1,000.01
long27 Mar 2024 69,988.0028 Mar 2024 69,288.101−$999.00
short4 Apr 2024 65,963.305 Apr 2024 68,487.801−$3,819.52
long9 Apr 2024 71,620.0010 Apr 2024 69,146.001−$3,434.24
short14 Apr 2024 63,924.5015 Apr 2024 65,661.901−$2,692.64
long24 Apr 2024 66,414.0025 Apr 2024 64,289.601−$3,160.54
short26 Apr 2024 64,498.306 May 2024 65,143.3010−$984.90
long7 May 2024 63,165.208 May 2024 62,312.101−$1,328.87
short9 May 2024 61,193.0010 May 2024 63,074.001−$3,020.29
long11 May 2024 60,800.0012 May 2024 60,826.001$41.89
short12 May 2024 60,826.0013 May 2024 61,484.001−$1,059.72
long15 May 2024 61,577.5016 May 2024 66,206.501$7,356.08
short16 May 2024 66,206.5017 May 2024 65,235.201$1,446.39
long17 May 2024 65,235.2031 May 2024 68,352.2014$4,717.57
short31 May 2024 68,352.203 Jun 2024 69,035.703−$992.07
long5 Jun 2024 70,537.807 Jun 2024 69,832.402−$991.07
short13 Jun 2024 68,264.0015 Jul 2024 60,797.9032$10,828.50
long15 Jul 2024 60,797.901 Aug 2024 64,628.0017$6,305.44
short1 Aug 2024 64,628.002 Aug 2024 65,354.001−$1,131.47
long15 Aug 2024 58,683.4016 Aug 2024 57,541.101−$1,958.45
short16 Aug 2024 57,541.1017 Aug 2024 58,874.601−$2,327.10
long18 Aug 2024 59,492.0019 Aug 2024 58,427.301−$1,792.77
short20 Aug 2024 59,438.5021 Aug 2024 59,013.801$714.52
long21 Aug 2024 59,013.8022 Aug 2024 61,156.001$3,632.65
short22 Aug 2024 61,156.0023 Aug 2024 60,375.801$1,281.30
long23 Aug 2024 60,375.8027 Aug 2024 59,772.104−$1,005.63
short29 Aug 2024 59,034.9030 Aug 2024 59,625.301−$1,004.63
long14 Sep 2024 60,498.0015 Sep 2024 59,893.001−$1,003.62
short3 Oct 2024 60,649.304 Oct 2024 61,255.801−$1,002.63
long14 Oct 2024 62,870.0028 Oct 2024 68,021.7014$8,207.40
short28 Oct 2024 68,021.7029 Oct 2024 69,962.201−$2,880.82
long29 Oct 2024 69,962.201 Nov 2024 69,262.603−$1,006.95
short6 Nov 2024 69,372.007 Nov 2024 75,572.001−$8,990.33
long7 Nov 2024 75,572.0028 Nov 2024 95,863.1021$26,768.00
short28 Nov 2024 95,863.1029 Nov 2024 95,644.001$234.00
long29 Nov 2024 95,644.002 Dec 2024 94,687.603−$1,023.95
short4 Dec 2024 95,849.705 Dec 2024 98,587.301−$2,921.64
long6 Dec 2024 96,945.609 Dec 2024 95,976.203−$1,020.00
short12 Dec 2024 101,125.0013 Dec 2024 100,004.001$1,129.28
long13 Dec 2024 100,004.0019 Dec 2024 99,004.206−$1,020.12
short21 Dec 2024 97,805.4024 Dec 2024 98,783.503−$1,019.10
long4 Jan 2025 98,174.207 Jan 2025 97,192.403−$1,018.08
short10 Jan 2025 92,552.5011 Jan 2025 94,726.101−$2,388.56
long17 Jan 2025 99,987.3027 Jan 2025 98,987.4010−$1,014.67
short29 Jan 2025 101,336.0030 Jan 2025 103,733.001−$2,398.43
long31 Jan 2025 104,723.001 Feb 2025 102,430.001−$2,214.59
short2 Feb 2025 100,636.003 Feb 2025 101,642.001−$1,009.04
long17 Feb 2025 96,118.1018 Feb 2025 95,780.001−$354.59
short18 Feb 2025 95,780.0019 Feb 2025 96,737.801−$1,007.68
long22 Feb 2025 96,182.0023 Feb 2025 96,551.001$386.23
short23 Feb 2025 96,551.0024 Feb 2025 96,258.001$305.62
long24 Feb 2025 96,258.0025 Feb 2025 91,552.901−$4,923.99
short25 Feb 2025 91,552.902 Mar 2025 92,468.405−$1,002.43
long8 Mar 2025 86,801.709 Mar 2025 86,222.501−$668.32
short9 Mar 2025 86,222.5020 Mar 2025 87,084.7011−$1,000.77
long21 Mar 2025 84,223.4029 Mar 2025 83,381.108−$999.77
short31 Mar 2025 82,390.001 Apr 2025 83,213.901−$998.76
long13 Apr 2025 85,276.9014 Apr 2025 83,760.001−$1,774.83
short31 May 2025 103,985.001 Jun 2025 105,025.001−$995.99
long11 Jun 2025 110,274.0012 Jun 2025 108,645.001−$1,470.06
short16 Jun 2025 105,594.0017 Jun 2025 106,795.001−$1,129.55
long18 Jun 2025 104,551.0019 Jun 2025 104,887.001$318.57
short19 Jun 2025 104,887.0020 Jun 2025 105,936.001−$992.71
long26 Jun 2025 107,341.001 Jul 2025 106,267.005−$991.72
short26 Jul 2025 117,614.0027 Jul 2025 118,790.001−$990.73
long29 Jul 2025 118,062.0030 Jul 2025 117,951.001−$93.53
short30 Jul 2025 117,951.009 Aug 2025 116,675.0010$1,070.61
long9 Aug 2025 116,675.0018 Aug 2025 115,508.009−$990.72
short20 Aug 2025 112,873.0021 Aug 2025 114,271.001−$1,226.08
long9 Sep 2025 112,065.0010 Sep 2025 110,945.001−$988.50
short24 Sep 2025 111,999.0025 Sep 2025 113,307.001−$1,153.47
long2 Oct 2025 118,595.0010 Oct 2025 117,409.008−$986.36
short12 Oct 2025 110,644.0013 Oct 2025 114,959.001−$3,842.29
long26 Oct 2025 111,646.0029 Oct 2025 110,530.003−$981.53
short1 Nov 2025 109,608.002 Nov 2025 110,704.001−$980.55
long29 Nov 2025 90,890.701 Dec 2025 89,981.802−$979.57
short3 Dec 2025 91,277.904 Dec 2025 93,429.901−$2,307.22
long4 Dec 2025 93,429.905 Dec 2025 92,078.101−$1,412.63
short8 Dec 2025 90,395.309 Dec 2025 91,299.301−$974.87
long11 Dec 2025 92,015.4012 Dec 2025 91,095.201−$973.90
short14 Dec 2025 90,240.0030 Dec 2025 87,237.1016$3,237.52
long30 Dec 2025 87,237.1031 Dec 2025 88,485.501$1,396.88
short31 Dec 2025 88,485.501 Jan 2026 87,648.201$925.00
long1 Jan 2026 87,648.202 Jan 2026 88,839.101$1,329.41
short2 Jan 2026 88,839.103 Jan 2026 89,995.101−$1,275.05
long3 Jan 2026 89,995.1020 Jan 2026 89,095.2017−$978.54
short22 Jan 2026 89,454.7023 Jan 2026 90,349.301−$977.55
long4 Mar 2026 68,338.007 Mar 2026 67,654.603−$976.59
short10 Mar 2026 68,432.2011 Mar 2026 69,948.601−$2,161.96
long11 Mar 2026 69,948.6012 Mar 2026 69,249.101−$973.44
short23 Mar 2026 67,859.0024 Mar 2026 70,906.401−$4,367.18
long7 Apr 2026 68,853.701 May 2026 76,346.6024$10,535.20
short1 May 2026 76,346.602 May 2026 78,231.101−$2,415.66
long3 May 2026 78,686.8015 May 2026 81,090.0012$2,981.44
short15 May 2026 81,090.0016 May 2026 79,113.201$2,387.07
long16 May 2026 79,113.2017 May 2026 78,148.101−$1,197.49
short17 May 2026 78,148.1016 Jun 2026 66,328.7030$14,827.60
long16 Jun 2026 66,328.7017 Jun 2026 65,665.401−$995.22
short20 Jun 2026 63,543.9021 Jun 2026 64,298.001−$1,179.89
long22 Jun 2026 63,312.0023 Jun 2026 64,020.001$1,110.50
short23 Jun 2026 64,020.005 Jul 2026 63,144.0012$1,360.31
long5 Jul 2026 63,144.006 Jul 2026 62,512.601−$995.52
short26 Jul 2026 64,375.0027 Jul 2026 65,400.001−$1,583.48
long28 Jul 2026 63,755.9029 Jul 2026 63,915.001$247.84
short29 Jul 2026 63,915.0030 Jul 2026 64,554.201−$993.18
long7 Aug 2026 64,323.6011 Aug 2026 63,680.404−$992.19
short13 Aug 2026 63,480.0017 Aug 2026 64,114.804−$991.19
long19 Aug 2026 64,725.404 Sep 2026 81,270.4016$25,311.20
short4 Sep 2026 81,270.405 Sep 2026 79,660.801$2,011.27
long5 Sep 2026 79,660.807 Sep 2026 78,864.202−$1,017.53
short10 Sep 2026 78,306.4011 Sep 2026 79,089.501−$1,016.51
long20 Sep 2026 81,250.008 Oct 2026 80,437.5018−$1,015.49
short9 Oct 2026 81,754.5010 Oct 2026 82,635.601−$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.

ScriptSharesTypeNetTradesMax drawdown
Smoothed Heikin Ashi Trend on Chart - TraderHalai BACKTEST this page—v5 strategy+1.3%1135.6%
TriautoETF(TQQQ) Short Strategy B1 by BBcomhma vwma emav5 strategyNo trades on this market
Optimized Keltner Channels SL-TP Strategy for BTC by chanu_lev10ksma ema rmav4 strategy−19.4%3670.0%
RMI + Triple HMRSI + Double EVWRSI + TERSI + CMO Strategy by burgercrisisrma hma emav4 strategyNo trades on this market
Soheil PKO's 5 min Hitman Scalp - 3MA + Laguerre RSI + ADX [Pt] by PtGamblerema sma rmav5 strategyNo trades on this market
Wave Trend w- VWMA overlay by jadamcraigvwma ema smav4 strategyNo 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.

Clean v5

VerifiedDownload the v5 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

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 44 msWith a workaround 1,000 bars in 123 msNot measured
PineTSNot testedNot testedNot 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 --- ///////////////