Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

Heikin Ashi Candle Startegy for Long Position

A Pine Script v5 strategy with no technical-analysis calculation. It has 2 order rules, 1 entry among them, and trades long only with the default settings. Exits use a stop loss and a profit target. Each trade is one contract and pays no commission. 6 settings; defaults include Validation Period 3, Qty 1.0 and Maximum Active Open Position 1.0.

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 Heikin Ashi Candle Startegy for Long Position repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 20 of 20 trades.
How did Heikin Ashi Candle Startegy for Long Position do on BTCUSDT 1D with default settings?
−0.20%
From 26 Jan 2024 to 21 Oct 2026, over 62 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Does Heikin Ashi Candle Startegy for Long Position 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: 62 before, 52 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 Heikin Ashi Candle Startegy for Long Position use a stop loss?
Yes
strategy.exit sets a stop on line 103.
Does Heikin Ashi Candle Startegy for Long Position run in Zeal Terminal?
Yes
It compiles in 16 ms and runs 1,000 bars in 51 ms, in the browser.

BTCUSDT · 1D · default settings

  • Limit
  • Trailing
  • Stop
  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
0.0050,000100,000AprJulOct2025AprJulOct2026AprJulOct$998,022$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. Zeal Terminal's engine currently reads an order side written as direction = strategy.long as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 96) 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. 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.
Net profit
−0.20%
−$1,975.25
Buy and hold
+102.5%
same period
Closed trades
62
58 won · 4 lost
Profitable
93.5%
of closed trades
Profit factor
0.98
gross profit ÷ gross loss
Max drawdown
4.11%
−$41,849.00

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

    1 setting does nothing

    “Trailing Stop (%)” is 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.

  • Note

    Uses an argument v6 removed

    when = on line 96. The upgraded version below moves each call inside an if block.

Settings

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

SettingDefaultType and rangeFeeds
Candle
Validation Period3intisLong line 63
Order
Qty1.0floatentry Long
Maximum Active Open Position1.0floatline 94
Long
Take Profit (%)1float · min 0.0 · step 0.1limitLong
Stop Loss (%)25float · min 0.0 · step 0.1stopLong
Trailing Stop (%)0.2float · min 0.0 · step 0.1unused

What it calculates

No technical-analysis calculation: the script works on prices and settings directly.

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 dataopenopenprice datatpLongTake Profit (%)setting · 1slLongStop Loss (%)setting · 25validationPeriodValidation Periodsetting · 3haTickerhaTickervaluehaClosehaClosevaluehaOpenhaOpenvaluelimitLonglimitLongvaluestopLongstopLongvaluetrailClosetrailClosevalueisLongisLongconditiontrailLongtrailLongconditionisGreenisGreenconditionentry:LongOpen Longstrategy.entryexit:Long Exitexit Long Exitstrategy.exitplot:66Limitplotplot:72Trailingplotplot:78Stopplot

Order rules

OrderFires whenBy defaultLine
Open Long longisLongisGreen and haClose[validationPeriod] < haOpen[validationPeriod]On96
Exit Long Exit stop and limit(strategy.position_size > 0)On103

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.

20/20trades 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 data2 request.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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D−0.2%+102.5%6294%0.984.1%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+0.2%+5.5%3297%1.112.3%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−0.4%+9.8%5285%0.330.6%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.0%+8.4%3797%1.590.1%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.0%+16.7%6492%1.060.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.0%+21.5%3197%1.380.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+0.1%+148.3%56100%—0.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.0%+17.1%30100%—0.0%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 market2090%−$15,381.60
Sideways market3093%$604.60
Falling market12100%$12,801.80

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

How bad could the drawdown be?

6.8%

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

0%8%
All 62 trades
SideEntryExitBarsP&L
long9 Feb 2024 45,288.7010 Feb 2024 47,132.801$1,844.12
long28 Feb 2024 57,037.3029 Feb 2024 62,432.101$5,394.76
long27 Mar 2024 69,988.0028 Mar 2024 70,687.901$699.88
long8 Apr 2024 69,360.409 Apr 2024 71,620.001$2,259.62
long22 Apr 2024 64,941.2023 Apr 2024 66,819.301$1,878.17
long6 May 2024 64,012.0015 May 2024 64,652.109$640.12
long16 May 2024 66,206.5017 May 2024 66,868.601$662.07
long28 May 2024 69,436.403 Jun 2024 70,130.806$694.37
long6 Jun 2024 71,108.007 Jun 2024 71,819.101$711.08
long3 Jul 2024 62,135.5015 Jul 2024 62,756.8012$621.36
long16 Jul 2024 64,724.1017 Jul 2024 65,371.301$647.25
long29 Jul 2024 68,249.905 Aug 2024 51,187.407−$17,062.50
long11 Aug 2024 60,923.5013 Aug 2024 61,532.802$609.24
long23 Aug 2024 60,375.8024 Aug 2024 64,037.201$3,661.41
long12 Sep 2024 57,338.0013 Sep 2024 58,132.301$794.31
long20 Sep 2024 62,948.0022 Sep 2024 63,577.502$629.48
long8 Oct 2024 62,224.0011 Oct 2024 62,846.303$622.25
long14 Oct 2024 62,870.0015 Oct 2024 66,084.001$3,213.98
long30 Oct 2024 72,736.406 Nov 2024 73,463.807$727.37
long8 Nov 2024 75,857.909 Nov 2024 76,616.501$758.58
long1 Dec 2024 96,408.002 Dec 2024 97,372.101$964.08
long7 Dec 2024 99,740.808 Dec 2024 100,738.001$997.41
long14 Dec 2024 101,424.0015 Dec 2024 102,438.001$1,014.25
long27 Dec 2024 95,791.602 Jan 2025 96,749.506$957.92
long4 Jan 2025 98,174.206 Jan 2025 99,155.902$981.75
long17 Jan 2025 99,987.3018 Jan 2025 104,077.001$4,090.17
long1 Feb 2025 102,430.0011 Mar 2025 76,822.2038−$25,607.40
long17 Mar 2025 82,574.5018 Mar 2025 84,010.001$1,435.50
long26 Mar 2025 87,392.902 Apr 2025 88,266.807$873.93
long12 Apr 2025 83,423.8013 Apr 2025 85,276.901$1,853.08
long20 Apr 2025 85,077.0021 Apr 2025 85,927.801$850.77
long4 May 2025 95,856.406 May 2025 96,815.002$958.57
long9 May 2025 103,262.0010 May 2025 104,294.001$1,032.62
long21 May 2025 106,850.0022 May 2025 109,644.001$2,793.99
long10 Jun 2025 110,263.009 Jul 2025 111,366.0029$1,102.64
long12 Jul 2025 117,528.0013 Jul 2025 118,703.001$1,175.28
long9 Aug 2025 116,675.0010 Aug 2025 117,841.001$1,166.75
long5 Sep 2025 110,731.008 Sep 2025 111,838.003$1,107.31
long10 Sep 2025 111,546.0011 Sep 2025 113,960.001$2,413.62
long1 Oct 2025 114,049.002 Oct 2025 118,595.001$4,546.05
long26 Oct 2025 111,646.0027 Oct 2025 114,559.001$2,913.14
long12 Nov 2025 103,059.0031 Jan 2026 77,294.3080−$25,764.80
long10 Feb 2026 70,138.0015 Feb 2026 70,839.405$701.38
long23 Feb 2026 67,643.4025 Feb 2026 68,319.802$676.44
long4 Mar 2026 68,338.005 Mar 2026 72,666.801$4,328.76
long13 Mar 2026 70,541.3014 Mar 2026 71,246.801$705.42
long26 Mar 2026 71,336.507 Apr 2026 72,049.9012$713.37
long8 Apr 2026 71,924.209 Apr 2026 72,643.501$719.25
long16 Apr 2026 74,810.0017 Apr 2026 75,558.101$748.10
long24 Apr 2026 78,257.5027 Apr 2026 79,040.103$782.58
long4 May 2026 78,568.605 May 2026 79,861.001$1,292.43
long12 May 2026 81,745.705 Jun 2026 61,309.2024−$20,436.40
long14 Jun 2026 64,458.0015 Jun 2026 65,746.401$1,288.44
long23 Jun 2026 64,020.006 Jul 2026 64,660.2013$640.21
long13 Jul 2026 63,780.0014 Jul 2026 64,417.801$637.80
long17 Jul 2026 63,830.2018 Jul 2026 64,468.501$638.31
long21 Jul 2026 65,255.5022 Jul 2026 66,556.101$1,300.64
long6 Aug 2026 64,665.207 Aug 2026 65,311.901$646.66
long20 Aug 2026 69,334.8021 Aug 2026 73,027.001$3,692.24
long6 Sep 2026 79,831.8018 Sep 2026 80,630.1012$798.32
long21 Sep 2026 81,178.0022 Sep 2026 86,620.001$5,442.00
long3 Oct 2026 84,518.004 Oct 2026 85,363.201$845.18

Similar scripts

No other indicator or strategy here shares enough of its calculations.

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.

  • 1 strategy call uses the when = argument (line 96). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
  • No v6-only features. v6 is not needed to run this script.

Clean v5

VerifiedDownload the v5 script

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

  • Line 96: when = isLong → if block
⋯strategy.risk.allow_entry_in(strategy.direction.long)-strategy.entry(-     id = "Long", -     direction = strategy.long, -     qty = qtyOrder,  -     when = isLong,       -     alert_message = "LN")+if isLong+    strategy.entry(+         id = "Long", +         direction = strategy.long, +         qty = qtyOrder,       +         alert_message = "LN")if (strategy.position_size > 0)⋯

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

⋯// © YohanNaftali-//@version=5+//@version=6///////////////////////////////////////////////////////////////////////////////⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 16 msWith a workaround 1,000 bars in 51 msNot measured
PineTSNot testedNot testedNot measured

Zeal Terminal's engine currently reads an order side written as direction = strategy.long as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 96) 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. 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/// © YohanNaftali//@version=5///////////////////////////////////////////////////////////////////////////////// Heikin Ashi Candle Startegy// ver 2021.12.29// © YohanNaftali// This script composed by Yohan Naftali for educational purpose only // Reader who will use this signal must do own research///////////////////////////////////////////////////////////////////////////////strategy(     title = 'Heikin Ashi Candle Startegy Long',       shorttitle = 'HA Strategy Long',       format = format.price,     precision = 6,     overlay = true)// InputvalidationPeriod = input.int(      defval = 3,      title = 'Validation Period',      group = 'Candle')qtyOrder = input.float(     defval = 1.0,     title = 'Qty',      group = 'Order')maxActive = input.float(     defval = 1.0,     title = 'Maximum Active Open Position',      group = 'Order')// Long StrategytpLong = input.float(     defval = 1,     title = "Take Profit (%)",     minval = 0.0,      step = 0.1,      group = "Long") * 0.01slLong = input.float(     defval = 25,     title = "Stop Loss (%)",      minval=0.0,      step=0.1,     group="Long") * 0.01trailingStopLong = input.float(     defval = 0.2,     title = "Trailing Stop (%)",     minval = 0.0,      step = 0.1,     group = 'Long') * 0.01// CalculationhaTicker = ticker.heikinashi(syminfo.tickerid)haClose = request.security(haTicker, timeframe.period, close)haOpen = request.security(haTicker, timeframe.period, open)// LonglimitLong = tpLong > 0.0 ? strategy.position_avg_price * (1 + tpLong) : nastopLong = slLong > 0.0 ? strategy.position_avg_price * (1 - slLong) : nafloat trailLong = 0.0trailLong := if strategy.position_size > 0    trailClose = close * (1 - trailLong)    math.max(trailClose, trailLong[1])else    0isGreen = truefor i = 0 to validationPeriod-1    isGreen := isGreen and haClose[i] > haOpen[i]        isLong = isGreen and haClose[validationPeriod] < haOpen[validationPeriod]plot(     limitLong,     title = 'Limit',      color = color.rgb(0, 0, 255, 0),      style = plot.style_stepline,     linewidth = 1)plot(     trailLong,     title = 'Trailing',      color = color.rgb(255, 255, 0, 0),      style = plot.style_stepline,     linewidth = 1)plot(     stopLong,     title = 'Stop',      style = plot.style_stepline,     color = color.rgb(255, 0, 0, 0),      linewidth = 1)// plotshape(//      isLong, //      title = 'Entry', //      style = shape.arrowup, //      location = location.belowbar, //      offset = 1, //      color = color.new(color.green, 0), //      text = 'Long Entry',//      size = size.small)// Strategystrategy.risk.max_position_size(maxActive)strategy.risk.allow_entry_in(strategy.direction.long)strategy.entry(     id = "Long",      direction = strategy.long,      qty = qtyOrder,       when = isLong,            alert_message = "LN")if (strategy.position_size > 0)    strategy.exit(         id = "Long Exit",         from_entry = "Long",         limit = limitLong,         stop = stopLong,         trail_price = trailLong,         alert_message = "LX")