Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

Heikin Ashi ROC Percentile Strategy

A Pine Script v5 strategy built on ROC or SMA (haClose, rocLength, 100), Highest (roc, 50) and Lowest (roc, 50). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. 3 settings; defaults include Midline 0, roc Length 100 and Stop Loss (%) 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 Heikin Ashi ROC Percentile Strategy repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 2 of 2 trades.
How did Heikin Ashi ROC Percentile Strategy do on BTCUSDT 1D with default settings?
−0.66%
From 26 Jan 2024 to 21 Oct 2026, over 7 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Does Heikin Ashi ROC Percentile Strategy 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: 7 before, 7 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 ROC Percentile Strategy use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does Heikin Ashi ROC Percentile Strategy run in Zeal Terminal?
Yes
It compiles in 29 ms and runs 1,000 bars in 49 ms, in the browser.

BTCUSDT · 1D · default settings

  • Zeroline
  • RSI
  • Roc High
  • Roc Low
  • Upper Kill Line
  • Lower Kill Line
  • 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 (3)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctZeroline$997,713$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.
Net profit
−0.66%
−$6,645.89
Buy and hold
+102.5%
same period
Closed trades
7
3 won · 4 lost
Profitable
42.9%
of closed trades
Profit factor
0.89
gross profit ÷ gross loss
Max drawdown
4.66%
−$46,598.00

One run with the author's default settings, $1,000,000 starting capital, commission as the script sets it. A long position was still open at the last bar. 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

    “Stop Loss (%)” is declared but never read.

  • Check

    No stop loss

    Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.

  • 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
Midline0intZeroline
roc Length100introc
Stop Loss (%)2intunused

What it calculates

  • ROC / SMAta.sma(haClose, rocLength), roc Length (100)roc · line 16
  • Highestroc, 50rocHigh · line 17
  • Lowestroc, 50rocLow · line 18
  • Percentile_linear_interpolationrocHigh, 10, 75upperKillLine · line 19
  • Percentile_linear_interpolationrocLow, 10, 25lowerKillLine · line 20
  • Crossoverroc, lowerKillLineenterLong · line 22
  • Crossunderroc, upperKillLineexitLong · line 23
  • Crossunderroc, upperKillLineenterShort · line 24
  • Crossoverroc, lowerKillLineexitShort · 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.

rocLengthroc Lengthsetting · 100ohlc4ohlc4price dataclosecloseprice dataopenopenprice datazerohLineMidlinesetting · 0rocROC / SMA→ rocrocHighHighest→ rocHighrocLowLowest→ rocLowupperKillLinePercentile_linear_inter…→ upperKillLinelowerKillLinePercentile_linear_inter…→ lowerKillLineenterLongCrossover→ enterLongexitLongCrossunder→ exitLongenterShortCrossunder→ enterShortexitShortCrossover→ exitShorthaClosehaClosevaluehaOpenhaOpenvalueentry:LongOpen Longstrategy.entryclose:LongClose Longstrategy.closeentry:ShortOpen Shortstrategy.entryclose:ShortClose Shortstrategy.closeplot:37Zerolineplotplot:38RSIplotplot:39Roc Highplotplot:40Roc Lowplotplot:41Upper Kill Lineplotplot:42Lower Kill Lineplot

Order rules

OrderFires whenBy defaultLine
Open Long long(enterLong)On29
Close Long(exitLong)On31
Open Short short(enterShort)On33
Close Short(exitShort)On35

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.

2/2trades 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−0.7%+102.5%743%0.894.7%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+1.0%+5.5%633%2.550.9%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+0.3%+9.8%683%8.680.2%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−0.0%+8.4%617%0.760.1%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.0%+16.7%667%13.930.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.0%+21.5%667%3.910.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+0.1%+148.3%683%21.550.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−0.0%+17.1%633%0.180.0%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 market250%−$31,176.80
Sideways market367%$45,001.90
Falling market20%−$20,471.00

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

How bad could the drawdown be?

6.1%

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

0%7%
All 7 trades
SideEntryExitBarsP&L
short14 Aug 2024 60,587.2027 Sep 2024 65,174.0044−$4,586.83
long27 Sep 2024 65,174.004 Nov 2024 68,776.0038$3,602.00
short4 Nov 2024 68,776.003 Jun 2025 105,858.00211−$37,082.00
long3 Jun 2025 105,858.0027 Aug 2025 111,763.0085$5,905.22
short27 Aug 2025 111,763.002 Mar 2026 65,776.50187$45,986.70
long2 Mar 2026 65,776.502 Aug 2026 62,823.70153−$2,952.83
short2 Aug 2026 62,823.707 Sep 2026 80,341.8036−$17,518.20

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
Heikin Ashi ROC Percentile Strategy this page—v5 strategy−0.7%74.7%
ChBrkOutStrategySMA by anshuanshu333sma highest lowestv4 strategy−4.5%4220.9%
KDJ Strategy @ionvolution by ionvolutionsma highest lowestv5 strategyNo trades on this market
Trading range display with Box by potatoshopsma highest lowestv5 strategy+0.7%273.9%
Open Drive by Marcns_highest lowest smav5 strategyNo trades on this market
The Z-score by jensenvilhelmsma percentile_linear_interpolation highest lowestv5 strategy+2.4%525.5%

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.

  • 3 settings use the untyped input() (line 6, 7, 8). 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 7 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 6: input() → input.int()
  • Line 7: input() → input.int()
  • Line 8: input() → input.int()
⋯// User Inputs-zerohLine = input(0, title="Midline")  // Zero line, baseline for ROC (customer can modify this to adjust midline)+zerohLine = input.int(0, title="Midline")  // Zero line, baseline for ROC (customer can modify this to adjust midline)-rocLength = input(100, title="roc Length")  // Lookback period for SMA and ROC (customer can modify this to adjust lookback period)+rocLength = input.int(100, title="roc Length")  // Lookback period for SMA and ROC (customer can modify this to adjust lookback period)-stopLossLevel = input(2, title="Stop Loss (%)")  // Level at which the strategy stops the loss (customer can modify this to adjust stop loss level)+stopLossLevel = input.int(2, title="Stop Loss (%)")  // Level at which the strategy stops the loss (customer can modify this to adjust stop loss level)startDate = timestamp("2015 03 03")  // Start date for the strategy (customer can modify this to adjust start date)⋯

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

⋯// © jensenvilhelm-//@version=5+//@version=6strategy("Heikin Ashi ROC Percentile Strategy", shorttitle="ROC ON" , overlay=false)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 29 msWith a workaround 1,000 bars in 49 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.

“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/// © jensenvilhelm//@version=5strategy("Heikin Ashi ROC Percentile Strategy", shorttitle="ROC ON" , overlay=false)// User InputszerohLine = input(0, title="Midline")  // Zero line, baseline for ROC (customer can modify this to adjust midline)rocLength = input(100, title="roc Length")  // Lookback period for SMA and ROC (customer can modify this to adjust lookback period)stopLossLevel = input(2, title="Stop Loss (%)")  // Level at which the strategy stops the loss (customer can modify this to adjust stop loss level)startDate = timestamp("2015 03 03")  // Start date for the strategy (customer can modify this to adjust start date)// Heikin Ashi valuesvar float haClose = na  // Define Heikin Ashi close pricevar float haOpen = na  // Define Heikin Ashi open pricehaClose := ohlc4  // Calculate Heikin Ashi close price as average of OHLC4 (no customer modification needed here)haOpen := na(haOpen[1]) ? (open + close) / 2 : (haOpen[1] + haClose[1]) / 2  // Calculate Heikin Ashi open price (no customer modification needed here)// ROC Calculationroc = ta.roc(ta.sma(haClose, rocLength), rocLength)  // Calculate Rate of Change (ROC) (customer can modify rocLength in the inputs)rocHigh = ta.highest(roc, 50)  // Get the highest ROC of the last 50 periods (customer can modify this to adjust lookback period)rocLow = ta.lowest(roc, 50)  // Get the lowest ROC of the last 50 periods (customer can modify this to adjust lookback period)upperKillLine = ta.percentile_linear_interpolation(rocHigh, 10, 75)  // Calculate upper kill line (customer can modify parameters to adjust this line)lowerKillLine = ta.percentile_linear_interpolation(rocLow, 10, 25)  // Calculate lower kill line (customer can modify parameters to adjust this line)// Trade conditionsenterLong = ta.crossover(roc, lowerKillLine)  // Define when to enter long positions (customer can modify conditions to adjust entry points)exitLong = ta.crossunder(roc, upperKillLine)  // Define when to exit long positions (customer can modify conditions to adjust exit points)enterShort = ta.crossunder(roc, upperKillLine)  // Define when to enter short positions (customer can modify conditions to adjust entry points)exitShort = ta.crossover(roc, lowerKillLine )  // Define when to exit short positions (customer can modify conditions to adjust exit points)// Strategy executionif(time >= startDate)  // Start strategy from specified start date    if (enterLong)        strategy.entry("Long", strategy.long)  // Execute long trades    if (exitLong)        strategy.close("Long")  // Close long trades    if (enterShort)        strategy.entry("Short", strategy.short)  // Execute short trades    if (exitShort)        strategy.close("Short")  // Close short trades// Plottingplot(zerohLine,title="Zeroline")  // Plot zero lineplot(roc, "RSI", color=color.rgb(248, 248, 248))  // Plot ROCplot(rocHigh, "Roc High", color = color.rgb(175, 78, 76))  // Plot highest ROCplot(rocLow, "Roc Low", color = color.rgb(175, 78, 76))  // Plot lowest ROCplot(upperKillLine, "Upper Kill Line", color = color.aqua)  // Plot upper kill lineplot(lowerKillLine, "Lower Kill Line", color = color.aqua)  // Plot lower kill line