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
- 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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Midline | 0 | int | Zeroline |
| roc Length | 100 | int | roc |
| Stop Loss (%) | 2 | int | unused |
What it calculates
- ROC / SMAta.sma(haClose, rocLength), roc Length (100)
roc · line 16 - Highestroc, 50
rocHigh · line 17 - Lowestroc, 50
rocLow · line 18 - Percentile_linear_interpolationrocHigh, 10, 75
upperKillLine · line 19 - Percentile_linear_interpolationrocLow, 10, 25
lowerKillLine · line 20 - Crossoverroc, lowerKillLine
enterLong · line 22 - Crossunderroc, upperKillLine
exitLong · line 23 - Crossunderroc, upperKillLine
enterShort · line 24 - Crossoverroc, lowerKillLine
exitShort · 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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long long | (enterLong) | On | 29 |
| Close Long | (exitLong) | On | 31 |
| Open Short short | (enterShort) | On | 33 |
| Close Short | (exitShort) | On | 35 |
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 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.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | −0.7% | +102.5% | 7 | 43% | 0.89 | 4.7% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +1.0% | +5.5% | 6 | 33% | 2.55 | 0.9% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +0.3% | +9.8% | 6 | 83% | 8.68 | 0.2% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −0.0% | +8.4% | 6 | 17% | 0.76 | 0.1% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.0% | +16.7% | 6 | 67% | 13.93 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 6 | 67% | 3.91 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +0.1% | +148.3% | 6 | 83% | 21.55 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −0.0% | +17.1% | 6 | 33% | 0.18 | 0.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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 2 | 50% | −$31,176.80 |
| Sideways market | 3 | 67% | $45,001.90 |
| Falling market | 2 | 0% | −$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.
All 7 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 14 Aug 2024 60,587.20 | 27 Sep 2024 65,174.00 | 44 | −$4,586.83 |
| long | 27 Sep 2024 65,174.00 | 4 Nov 2024 68,776.00 | 38 | $3,602.00 |
| short | 4 Nov 2024 68,776.00 | 3 Jun 2025 105,858.00 | 211 | −$37,082.00 |
| long | 3 Jun 2025 105,858.00 | 27 Aug 2025 111,763.00 | 85 | $5,905.22 |
| short | 27 Aug 2025 111,763.00 | 2 Mar 2026 65,776.50 | 187 | $45,986.70 |
| long | 2 Mar 2026 65,776.50 | 2 Aug 2026 62,823.70 | 153 | −$2,952.83 |
| short | 2 Aug 2026 62,823.70 | 7 Sep 2026 80,341.80 | 36 | −$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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Heikin Ashi ROC Percentile Strategy this page | — | v5 strategy | −0.7% | 7 | 4.7% |
| ChBrkOutStrategySMA by anshuanshu333 | sma highest lowest | v4 strategy | −4.5% | 42 | 20.9% |
| KDJ Strategy @ionvolution by ionvolution | sma highest lowest | v5 strategy | No trades on this market | ||
| Trading range display with Box by potatoshop | sma highest lowest | v5 strategy | +0.7% | 27 | 3.9% |
| Open Drive by Marcns_ | highest lowest sma | v5 strategy | No trades on this market | ||
| The Z-score by jensenvilhelm | sma percentile_linear_interpolation highest lowest | v5 strategy | +2.4% | 52 | 5.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.
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
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 29 ms | With a workaround 1,000 bars in 49 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.
“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