Pine Script v5 · Strategy
KDJ Strategy @ionvolution
A Pine Script v5 strategy built on SMA (close, 200), Highest (high, 14) and Lowest (low, 14). It has 3 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. 11 settings; defaults include Period 14, Signal 8 and SMA 200.
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 KDJ Strategy @ionvolution repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did KDJ Strategy @ionvolution do on BTCUSDT 1D with default settings?
- Not measured
- It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its code limits trading to a date window, which can leave this period out. It closed no trades on the other markets either. A backtest, not investment advice.
- Does KDJ Strategy @ionvolution run in Pine Script v6?
- No
- The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L60:C40: 'bgcolor' has no 'transp' parameter in Pine Script v6. Use color.new(color, transparency) instead. The v6 version is shown for reference and is not offered as a download.
- Does KDJ Strategy @ionvolution use a stop loss?
- Yes
- strategy.exit sets a stop on line 50.
- Does KDJ Strategy @ionvolution run in Zeal Terminal?
- Yes
- It compiles in 19 ms and runs 1,000 bars in 43 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- 0.00%
- $0.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 0
- 0 won · 0 lost
- Profitable
- 0.0%
- of closed trades
- Profit factor
- —
- gross profit ÷ gross loss
- Max drawdown
- 0.00%
- $0.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
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 53. 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 |
|---|---|---|---|
| Period | 14 | int | h l |
| Signal | 8 | int | pK pD |
| SMA | 200 | int | ma |
| Profit Margin | 1.20 | float · min 1.0 · max 1.99 · step 0.01 | exit S |
| Stop Loss Margin | 0.98 | float · min 0.0 · max 1 · step 0.01 | exit S |
| Start Date | 1 | int · min 1 · max 31 | inDateRange |
| Start Month | 1 | int · min 1 · max 12 | inDateRange |
| Start Year | 2022 | int · min 2018 · max 2023 | inDateRange |
| End Date | 1 | int · min 1 · max 31 | inDateRange |
| End Month | 1 | int · min 1 · max 12 | inDateRange |
| End Year | 2022 | int · min 2018 · max 2099 | inDateRange |
What it calculates
- SMAclose, SMA (200)
ma · line 39 - Highesthigh, Period (14)
h · line 40 - Lowestlow, Period (14)
l · line 41
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 S long | (inDateRange and go_long) | On | 49 |
| Exit S stop and limit | (inDateRange and go_long) | On | 50 |
| Close S | go_shortta.crossover(pD,pJ) or close < ma | On | 53 |
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.
- 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.0% | +102.5% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | 0.0% | +5.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | 0.0% | +9.8% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | 0.0% | +8.4% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | 0.0% | +16.7% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | 0.0% | +21.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | 0.0% | +148.3% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | 0.0% | +17.1% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
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 |
|---|---|---|---|---|---|
| KDJ Strategy @ionvolution this page | — | v5 strategy | 0.0% | 0 | 0.0% |
| ChBrkOutStrategySMA by anshuanshu333 | sma highest lowest | v4 strategy | −4.5% | 42 | 20.9% |
| 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 | ||
| Trend Bounce [racer8] by racer8 | highest lowest sma | v4 strategy | +2.4% | 22 | 32.2% |
| Lawyers Trend Pro Strategy by ErdemDemir | sma lowest highest | v4 strategy | +12.1% | 102 | 41.7% |
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 53). 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
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 53: when = go_short → if block
⋯if (inDateRange and go_short)- strategy.close("S",when=go_short,comment="V")+ if go_short+ strategy.close("S",comment="V") ⋯Does it run in Pine Script v6?
No
The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L60:C40: 'bgcolor' has no 'transp' parameter in Pine Script v6. Use color.new(color, transparency) instead. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © ionvolution-// @version = 5+// @version = 6//strategy("KDJ IAM Strategy",shorttitle="kdj @ionvolution",overlay=true,default_qty_value=1,initial_capital=100,currency=currency.EUR)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 19 ms | With a workaround 1,000 bars in 43 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/// Buys if there is crossover in J and D and the crossover is above an SMA defined as an input parameter// Sells if the close is below the SMA or there is a crossunder in J and D// The KDJ calculation is done using ll21LAMBOS21 script. I added start date, end date, stop loss margin and stop profit margin to // ease the simulation on diferent conditions of the market.// Tested on BTCBUSD pair. Gives good results in 30m candles with K period = 7 and D period = 3, but also works fine with K period = 14 and D period = 8// It works fine when market is bullish and gives false signals in flat markets.// I just developed long strategy, as it is developed to work in SPOT trading.// © ionvolution// @version = 5//strategy("KDJ IAM Strategy",shorttitle="kdj @ionvolution",overlay=true,default_qty_value=1,initial_capital=100,currency=currency.EUR)strategy("KDJ IAM Strategy",shorttitle="kdj @ionvolution",overlay=true)// Input parameters ilong = input.int(14,"Period")isig = input.int(8, "Signal")isma = input.int(200, "SMA")// Function to compute average for KDJbcwsma(s, l, m) => _bcwsma = float(na) _s = s _l = l _m = m _bcwsma := (_m * _s + (_l - _m) * nz(_bcwsma[1])) / _l _bcwsmaprofit_m = input.float(1.20,"Profit Margin",minval=1.0,maxval=1.99,step=0.01)stop_m = input.float(0.98,"Stop Loss Margin",minval=0.0,maxval=1,step=0.01)// Make input options that configure backtest date rangestartDate = input.int(title="Start Date", defval=1, minval=1,maxval=31)startMonth = input.int(title="Start Month", defval=1,minval=1,maxval=12)startYear = input.int(title="Start Year", defval=2022,minval=2018,maxval=2023)endDate = input.int(title="End Date", defval=1, minval=1,maxval=31)endMonth = input.int(title="End Month", defval=1,minval=1,maxval=12)endYear = input.int(title="End Year", defval=2022,minval=2018,maxval=2099)// intialization of variables// Look if the close time of the current bar// falls inside the date rangeinDateRange = (time >= timestamp(syminfo.timezone, startYear,startMonth, startDate, 0, 0)) and (time < timestamp(syminfo.timezone, endYear, endMonth, endDate, 0, 0))c = closema = ta.sma(close,isma)h = ta.highest(high, ilong)l = ta.lowest(low,ilong)RSV = 100*((c-l)/(h-l))pK = bcwsma(RSV, isig, 1)pD = bcwsma(pK, isig, 1)pJ = 3 * pK-2 * pDgo_long= ta.crossover(pJ,pD) and close >mago_short= ta.crossover(pD,pJ) or close < maif (inDateRange and go_long) strategy.entry("S",strategy.long,comment="C") strategy.exit("S", limit=c*profit_m, stop=c*stop_m, comment="SL/SP") if (inDateRange and go_short) strategy.close("S",when=go_short,comment="V") // Plot options//plot(pK, color= #1E88E5,transp=0)//plot(pD, color=#FF6F00,transp=0)plot(ma, color=color.yellow)bgcolor(pJ>pD? color.green : color.red, transp=75)//h0 = hline(80)//h1 = hline(20)