Pine Script v5 · Strategy
Heiken Ashi & Super Trend
A Pine Script v5 strategy with no technical-analysis calculation. It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a profit target and no stop loss. Each trade commits 100% of equity and pays 0.02% commission. 9 settings; defaults include ATR Length 10, Factor 3.0 and TP [%] 1.1.
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 Heiken Ashi & Super Trend repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 5 of 5 trades.
- How did Heiken Ashi & Super Trend do on BTCUSDT 1D with default settings?
- +3.42%
- From 26 Jan 2024 to 21 Oct 2026, over 17 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does Heiken Ashi & Super Trend run in Pine Script v6?
- No
- The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L62:C0: a 'bool' cannot be 'na' in Pine Script v6 — declare it as true or false. The v6 version is shown for reference and is not offered as a download.
- Does Heiken Ashi & Super Trend use a stop loss?
- No
- Its exits set a profit target but no stop.
- Does Heiken Ashi & Super Trend run in Zeal Terminal?
- Yes
- It compiles in 34 ms and runs 1,000 bars in 127 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Up Trend
- Down Trend
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +3.42%
- $342.50
- Buy and hold
- +102.5%
- same period
- Closed trades
- 17
- 16 won · 1 lost
- Profitable
- 94.1%
- of closed trades
- Profit factor
- 1.24
- gross profit ÷ gross loss
- Max drawdown
- 15.60%
- −$1,772.28
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
strategy.exit is used without a stop, loss or trailing stop.
-
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
-
Note
Uses an argument v6 removed
when = on line 89, 91. 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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| ATR Length | 10 | int | atr direction supertrend |
| Factor | 3.0 | float · step 0.01 | upperBand lowerBand direction supertrend |
| TP [%] | 1.1 | float · step 0.1 | exit TP_L exit TP_S |
| BACKTEST | |||
| start year | 2000 | int · min 1997 · max 3000 | testPeriodStart |
| start month | 01 | int · min 1 · max 12 | testPeriodStart |
| start day | 01 | int · min 1 · max 31 | testPeriodStart |
| stop year | 3333 | int · min 1980 · max 3333 | testPeriodStop |
| stop month | 12 | int · min 1 · max 12 | testPeriodStop |
| stop day | 31 | int · min 1 · max 31 | testPeriodStop |
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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open L long | testPeriod | On | 89 |
| Open S short | testPeriod | On | 91 |
| Exit TP_L limit | every bar | On | 93 |
| Exit TP_S limit | every bar | On | 94 |
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.
- ClearHigher-timeframe data4 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.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | +3.4% | +102.5% | 17 | 94% | 1.24 | 15.6% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −5.9% | +5.5% | 14 | 71% | 0.64 | 11.3% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −2.0% | +9.8% | 16 | 94% | 0.89 | 30.1% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −2.2% | +8.4% | 14 | 79% | 0.83 | 10.2% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −0.8% | +16.7% | 20 | 95% | 0.96 | 25.5% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +6.2% | +21.5% | 14 | 93% | 1.82 | 9.5% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +13.5% | +148.3% | 12 | 100% | — | 3.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −6.1% | +17.1% | 19 | 79% | 0.71 | 12.7% | 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 | 3 | 100% | $326.37 |
| Sideways market | 12 | 92% | −$198.54 |
| Falling market | 2 | 100% | $214.67 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
12.7%
The 95th percentile of the worst drawdown when the same 17 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 12.7% to 12.7%; the tick is what actually happened, 12.7%. Order luck alone moves it this much.
All 17 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 11 Feb 2024 47,751.10 | 11 Feb 2024 48,269.60 | 0 | $104.53 |
| short | 2 May 2024 58,365.00 | 2 May 2024 57,697.60 | 0 | $111.50 |
| long | 22 May 2024 70,148.30 | 4 Jun 2024 70,934.30 | 13 | $110.33 |
| short | 24 Jun 2024 63,210.00 | 24 Jun 2024 62,503.10 | 0 | $111.35 |
| long | 20 Jul 2024 66,660.00 | 20 Jul 2024 67,363.90 | 0 | $106.00 |
| short | 5 Aug 2024 58,161.00 | 5 Aug 2024 57,493.30 | 0 | $116.82 |
| long | 21 Sep 2024 63,201.10 | 22 Sep 2024 63,893.50 | 1 | $112.49 |
| short | 26 Feb 2025 88,680.40 | 26 Feb 2025 87,673.30 | 0 | $118.03 |
| long | 24 Apr 2025 93,691.10 | 25 Apr 2025 94,718.90 | 1 | $115.08 |
| short | 26 Aug 2025 110,112.00 | 26 Aug 2025 108,864.00 | 0 | $120.38 |
| long | 3 Oct 2025 120,529.00 | 3 Oct 2025 121,834.00 | 0 | $115.93 |
| short | 12 Oct 2025 110,644.00 | 16 Oct 2025 109,404.00 | 4 | $121.55 |
| long | 15 Jan 2026 96,951.80 | 30 Jan 2026 84,650.20 | 15 | −$1,445.88 |
| short | 30 Jan 2026 84,650.20 | 30 Jan 2026 83,667.90 | 0 | $111.15 |
| long | 18 Apr 2026 77,072.00 | 22 Apr 2026 77,898.70 | 4 | $103.52 |
| short | 29 May 2026 73,617.50 | 29 May 2026 72,798.60 | 0 | $108.67 |
| long | 20 Aug 2026 69,334.80 | 20 Aug 2026 70,046.80 | 0 | $101.03 |
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.
- 2 strategy calls use the when = argument (line 89, 91). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
- 1 setting uses the untyped input() (line 51). 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 17 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 51: input() → input.int()
- Line 89: when = testPeriod → if block
- Line 91: when = testPeriod → if block
⋯///////////////////////////////////////////////////-atrPeriod = input(10, "ATR Length")+atrPeriod = input.int(10, "ATR Length")factor = input.float(3.0, "Factor", step = 0.01)⋯if longCond- strategy.entry("L", strategy.long, when=testPeriod)+ if testPeriod+ strategy.entry("L", strategy.long)if shortCond- strategy.entry("S", strategy.short, when=testPeriod)+ if testPeriod+ strategy.entry("S", strategy.short) ⋯Does it run in Pine Script v6?
No
The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L62:C0: a 'bool' cannot be 'na' in Pine Script v6 — declare it as true or false. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © RingsCherrY-//@version=5+//@version=6strategy("Heiken Ashi & Super Trend", overlay=true, pyramiding=1,initial_capital = 10000, default_qty_type= strategy.percent_of_equity, default_qty_value = 100, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.percent,commission_value=0.02)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 34 ms | With a workaround 1,000 bars in 127 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/// © RingsCherrY//@version=5strategy("Heiken Ashi & Super Trend", overlay=true, pyramiding=1,initial_capital = 10000, default_qty_type= strategy.percent_of_equity, default_qty_value = 100, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.percent,commission_value=0.02)///////////////////////////////////////////////////////////////////////Function//////////////////////////////////////////////////////////////////////////heikinashi_open = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, open)heikinashi_high = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, high)heikinashi_low = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, low)heikinashi_close= request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, close)heikinashi_color = heikinashi_open < heikinashi_close ? #53b987 : #eb4d5c// plotbar(heikinashi_open, heikinashi_high, heikinashi_low, heikinashi_close, color=heikinashi_color)x_sma(x, y) => sumx = 0.0 for i = 0 to y - 1 sumx := sumx + x[i] / y sumxx_rma(src, length) => alpha = 1/length sum = 0.0 sum := na(sum[1]) ? x_sma(src, length) : alpha * src + (1 - alpha) * nz(sum[1])x_atr(length) => trueRange = na(heikinashi_high[1])? heikinashi_high-heikinashi_low : math.max(math.max(heikinashi_high - heikinashi_low, math.abs(heikinashi_high - heikinashi_close[1])), math.abs(heikinashi_low - heikinashi_close[1])) //true range can be also calculated with ta.tr(true) x_rma(trueRange, length)x_supertrend(factor, atrPeriod) => src = (heikinashi_high+heikinashi_low)/2 atr = x_atr(atrPeriod) upperBand = src + factor * atr lowerBand = src - factor * atr prevLowerBand = nz(lowerBand[1]) prevUpperBand = nz(upperBand[1]) lowerBand := lowerBand > prevLowerBand or heikinashi_close[1] < prevLowerBand ? lowerBand : prevLowerBand upperBand := upperBand < prevUpperBand or heikinashi_close[1] > prevUpperBand ? upperBand : prevUpperBand int direction = na float superTrend = na prevSuperTrend = superTrend[1] if na(atr[1]) direction := 1 else if prevSuperTrend == prevUpperBand direction := heikinashi_close > upperBand ? -1 : 1 else direction := heikinashi_close < lowerBand ? 1 : -1 superTrend := direction == -1 ? lowerBand : upperBand [superTrend, direction] ///////////////////////////////////////////////////////////////////////Indicators////////////////////////////////////////////////////////////////////////atrPeriod = input(10, "ATR Length")factor = input.float(3.0, "Factor", step = 0.01)[supertrend, direction] = x_supertrend(factor, atrPeriod)bodyMiddle = plot((heikinashi_open + heikinashi_close) / 2, display=display.none)upTrend = plot(direction < 0 ? supertrend : na, "Up Trend", color = color.green, style=plot.style_linebr)downTrend = plot(direction < 0? na : supertrend, "Down Trend", color = color.red, style=plot.style_linebr)fill(bodyMiddle, upTrend, color.new(color.green, 90), fillgaps=false)fill(bodyMiddle, downTrend, color.new(color.red, 90), fillgaps=false)///////////////////////////////////////////////////////////////////////Strategy//////////////////////////////////////////////////////////////////////////var bool longCond = na, var bool shortCond = na, longCond := nz(longCond[1]), shortCond := nz(shortCond[1])var int CondIni_long = 0, var int CondIni_short = 0, CondIni_long := nz(CondIni_long[1]), CondIni_short := nz(CondIni_short[1])var float open_longCondition = na, var float open_shortCondition = nalong = ta.change(direction) < 0short = ta.change(direction) > 0longCond := longshortCond := shortCondIni_long := longCond[1] ? 1 : shortCond[1] ? -1 : nz(CondIni_long[1])CondIni_short := longCond[1] ? 1 : shortCond[1] ? -1 : nz(CondIni_short[1])longCondition = (longCond[1] and nz(CondIni_long[1]) == -1)shortCondition = (shortCond[1] and nz(CondIni_short[1]) == 1)open_longCondition := long ? close[1] : nz(open_longCondition[1])open_shortCondition := short ? close[1] : nz(open_shortCondition[1])//TPtp = input.float(1.1 , "TP [%]", step = 0.1) //BACKTESTING inputs --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------testStartYear = input.int(2000, title="start year", minval = 1997, maxval = 3000, group= "BACKTEST") testStartMonth = input.int(01, title="start month", minval = 1, maxval = 12, group= "BACKTEST")testStartDay = input.int(01, title="start day", minval = 1, maxval = 31, group= "BACKTEST")testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)testStopYear = input.int(3333, title="stop year", minval=1980, maxval = 3333, group= "BACKTEST")testStopMonth = input.int(12, title="stop month", minval=1, maxval=12, group= "BACKTEST")testStopDay = input.int(31, title="stop day", minval=1, maxval=31, group= "BACKTEST")testPeriodStop = timestamp(testStopYear, testStopMonth, testStopDay, 0, 0)testPeriod = time >= testPeriodStart and time <= testPeriodStop ? true : false// Backtest ==================================================================================================================================================================================================================================================================================================================================if longCond strategy.entry("L", strategy.long, when=testPeriod)if shortCond strategy.entry("S", strategy.short, when=testPeriod) strategy.exit("TP_L", "L", profit =((open_longCondition * (1+(tp/100))) - open_longCondition)/syminfo.mintick)strategy.exit("TP_S", "S", profit =((open_shortCondition * (1+(tp/100))) - open_shortCondition)/syminfo.mintick)