Pine Script v4 · Strategy
ICHIMOKU Crypto Swing Strategy
A Pine Script v4 strategy built on Highest (high, ilong), Lowest (low, ilong) and SMA (h, 4). It has 2 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 commits 100% of equity and pays 0.05% commission. 12 settings; defaults include Uptrend Length 4, Downtrend Length 4 and Conversion Periods 9.
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 ICHIMOKU Crypto Swing Strategy repaint?
- No
- No repainting patterns were found in the source.
- Can ICHIMOKU Crypto Swing Strategy be converted to Pine Script v5?
- Not tested
- The steps are shown below, but the original does not run in Zeal Terminal's engine, so they could not be checked.
- Does ICHIMOKU Crypto Swing Strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does ICHIMOKU Crypto Swing Strategy run in Zeal Terminal?
- No
- Not yet: Pine Script v4 Error at @L46:C12: Undeclared identifier 'offset'.
Review
What a careful reader of this script would point out, found by checking the source.
-
Check
No stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
-
Note
4 settings have no label
In the settings dialog conversionPeriods (line 34), basePeriods (line 35), laggingSpan2Periods (line 36), displacement (line 37) show an empty name. The labels on this page come from the variable names.
-
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 70, 71. The upgraded version below moves each call inside an if block.
-
Note
Uses offset(), which v5 removed line 46
offset() on line 46, 47. v5 writes offset(x, n) as x[n].
Upgrade and export
Written in Pine Script v4. The upgrade to v5 takes 1 step, one per version, each applied to the result of the one before. A last clean-v5 pass then types the settings and moves when = into if blocks, which v6 requires. Every step runs before and after on the same candles in Zeal Terminal's engine; a step whose results differ is shown but not offered as a download. Upgrades preserve behaviour: bugs are fixed in the Review, never silently here.
- Upgrading to v5 renames highest → ta.highest, lowest → ta.lowest, avg → math.avg, sma → ta.sma, crossover → ta.crossover, crossunder → ta.crossunder, rising → ta.rising, falling → ta.falling.
- 2 strategy calls use the when = argument (line 70, 71). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
Not verifiedThe v4 script does not run in Zeal Terminal's engine (Pine Script v4 Error at @L46:C12: Undeclared identifier 'offset'.), so this step could not be checked.
- Line 3: //@version=4 → //@version=5
- Line 21: highest → ta.highest
- Line 22: lowest → ta.lowest
- Line 27: avg → math.avg
- Line 29: sma → ta.sma
- Line 30: sma → ta.sma
10 more edits
- Line 38: avg → math.avg
- Line 38: lowest → ta.lowest
- Line 38: highest → ta.highest
- Line 46: offset(x, n) → (x)[n]
- Line 46: avg → math.avg
- Line 47: offset(x, n) → (x)[n]
- Line 48: crossover → ta.crossover
- Line 49: crossunder → ta.crossunder
- Line 56: rising → ta.rising
- Line 57: falling → ta.falling
⋯// © exlux99-//@version=4+//@version=5strategy(title="ICHIMOKU Crypto Swing Strategy", overlay=true, initial_capital = 10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.05 )⋯ _bcwsma-h = highest(high, ilong)+h = ta.highest(high, ilong)-l = lowest(low,ilong)+l = ta.lowest(low,ilong)RSV = 100*((c-l)/(h-l))⋯pJ = 3 * pK-2 * pD-KD = avg(pK,pD)+KD = math.avg(pK,pD)/// --- TREND --- ///-avghigh = sma(h, uptrendlength)+avghigh = ta.sma(h, uptrendlength)-avglow = sma(l, downtrendlength) +avglow = ta.sma(l, downtrendlength) uptrend = h > avghigh⋯displacement = input(26)-donchian(len) => avg(lowest(len), highest(len))+donchian(len) => math.avg(ta.lowest(len), ta.highest(len))resolve(src, default) =>⋯baseLine = donchian(basePeriods)-leadLine1 = offset(avg(conversionLine, baseLine), displacement)+leadLine1 = (math.avg(conversionLine, baseLine))[displacement]-leadLine2 = offset(donchian(laggingSpan2Periods), displacement)+leadLine2 = (donchian(laggingSpan2Periods))[displacement]-tk_cross_bull = crossover(conversionLine, baseLine)+tk_cross_bull = ta.crossover(conversionLine, baseLine)-tk_cross_bear = crossunder(conversionLine, baseLine)+tk_cross_bear = ta.crossunder(conversionLine, baseLine)cross_y = (conversionLine[1] * (baseLine - baseLine[1]) - baseLine[1] * (conversionLine - conversionLine[1])) / ((baseLine - baseLine[1]) - (conversionLine - conversionLine[1]))⋯//BUY & SELL-buycond = (tk_cross_below_kumo or tk_cross_inside_kumo or tk_cross_above_kumo) and rising(pJ[1],1) and uptrend+buycond = (tk_cross_below_kumo or tk_cross_inside_kumo or tk_cross_above_kumo) and ta.rising(pJ[1],1) and uptrend-sellcond = (tk_cross_below_kumo or tk_cross_inside_kumo or tk_cross_above_kumo) and falling(pJ[1],1) and downtrend+sellcond = (tk_cross_below_kumo or tk_cross_inside_kumo or tk_cross_above_kumo) and ta.falling(pJ[1],1) and downtrendfromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)⋯Clean v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 10: input() → input.int()
- Line 11: input() → input.int()
- Line 34: input() → input.int()
- Line 35: input() → input.int()
- Line 36: input() → input.int()
- Line 37: input() → input.int()
8 more edits
- Line 58: input() → input.int()
- Line 59: input() → input.int()
- Line 60: input() → input.int()
- Line 63: input() → input.int()
- Line 64: input() → input.int()
- Line 65: input() → input.int()
- Line 70: when = buycond → if block
- Line 71: when = sellcond → if block
⋯price = close -uptrendlength = input(4, title="Uptrend Length")+uptrendlength = input.int(4, title="Uptrend Length")-downtrendlength = input(4, title="Downtrend Length")+downtrendlength = input.int(4, title="Downtrend Length")//KDJ// ⋯//ICHIMOKU BUY & SELL// -conversionPeriods = input(9)+conversionPeriods = input.int(9)-basePeriods = input(26)+basePeriods = input.int(26)-laggingSpan2Periods = input(52)+laggingSpan2Periods = input.int(52)-displacement = input(26)+displacement = input.int(26)donchian(len) => math.avg(ta.lowest(len), ta.highest(len))⋯sellcond = (tk_cross_below_kumo or tk_cross_inside_kumo or tk_cross_above_kumo) and ta.falling(pJ[1],1) and downtrend-fromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)+fromDay = input.int(defval = 1, title = "From Day", minval = 1, maxval = 31)-fromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)+fromMonth = input.int(defval = 1, title = "From Month", minval = 1, maxval = 12)-fromYear = input(defval = 2020, title = "From Year", minval = 1970)+fromYear = input.int(defval = 2020, title = "From Year", minval = 1970) //monday and session // To Date Inputs-toDay = input(defval = 31, title = "To Day", minval = 1, maxval = 31)+toDay = input.int(defval = 31, title = "To Day", minval = 1, maxval = 31)-toMonth = input(defval = 12, title = "To Month", minval = 1, maxval = 12)+toMonth = input.int(defval = 12, title = "To Month", minval = 1, maxval = 12)-toYear = input(defval = 2021, title = "To Year", minval = 1970)+toYear = input.int(defval = 2021, title = "To Year", minval = 1970)startDate = timestamp(fromYear, fromMonth, fromDay, 00, 00)⋯if(time_cond)- strategy.entry("long",strategy.long,when= buycond, alert_message="LONG")+ if buycond+ strategy.entry("long",strategy.long, alert_message="LONG")- strategy.entry("short",strategy.short,when=sellcond, alert_message="SHORT")+ if sellcond+ strategy.entry("short",strategy.short, alert_message="SHORT")Does it run in Pine Script v6?
Not tested
Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © exlux99-//@version=5+//@version=6strategy(title="ICHIMOKU Crypto Swing Strategy", overlay=true, initial_capital = 10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.05 )⋯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 |
|---|---|---|---|
| Uptrend Length | 4 | int | avghigh |
| Downtrend Length | 4 | int | avglow |
| Conversion Periods (no label in the script) | 9 | int | conversionLine |
| Base Periods (no label in the script) | 26 | int | baseLine |
| Lagging Span2Periods (no label in the script) | 52 | int | leadLine2 |
| Displacement (no label in the script) | 26 | int | leadLine1 leadLine2 |
| From Day | 1 | int · min 1 · max 31 | startDate |
| From Month | 1 | int · min 1 · max 12 | startDate |
| From Year | 2020 | int · min 1970 | startDate |
| To Day | 31 | int · min 1 · max 31 | finishDate |
| To Month | 12 | int · min 1 · max 12 | finishDate |
| To Year | 2021 | int · min 1970 | finishDate |
What it calculates
- Highest (
highest,ta.highestin v5)high, ilongh · line 21 - Lowest (
lowest,ta.lowestin v5)low, ilongl · line 22 - SMA (
sma,ta.smain v5)h, Uptrend Length (4)avghigh · line 29 - SMA (
sma,ta.smain v5)l, Downtrend Length (4)avglow · line 30 - Crossover (
crossover,ta.crossoverin v5)conversionLine, baseLinetk_cross_bull · line 48 - Crossunder (
crossunder,ta.crossunderin v5)conversionLine, baseLinetk_cross_bear · line 49
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 | buycond(tk_cross_below_kumo or tk_cross_inside_kumo or tk_cross_above_kumo) and rising(pJ[1],1) and uptrend | On | 70 |
| Open short short | sellcond(tk_cross_below_kumo or tk_cross_inside_kumo or tk_cross_above_kumo) and falling(pJ[1],1) and downtrend | On | 71 |
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.
The live replay needs a run, and this script does not run in Zeal Terminal yet; the answer comes from the checks on the source alone.
- 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.
Similar scripts
Indicators and strategies built from the same calculations.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Accumulation Stage Identifier and Strategy around for Trading by stocktechbot | sma rising lowest highest falling | v5 strategy | −0.0% | 16 | 4.1% |
| Reversal closing price by EduardoMattje | rising falling sma lowest highest | v4 strategy | −10.0% | 53 | 10.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 | ||
| Trendelicious Strategy by levieux | highest rising falling | v5 strategy | −12.8% | 9 | 41.4% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | No Pine Script v4 Error at @L46:C12: Undeclared identifier 'offset'. | Not measured | |
| PineTS | No v5 and v6 only | — | Not measured |
“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. PineTS runs Pine Script v5 and v6 only.
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/// © exlux99//@version=4strategy(title="ICHIMOKU Crypto Swing Strategy", overlay=true, initial_capital = 10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.05 )//o = openc = closesrc = close price = close uptrendlength = input(4, title="Uptrend Length")downtrendlength = input(4, title="Downtrend Length")//KDJ// ilong = 9isig = 3bcwsma(s,l,m) => _s = s _l = l _m = m _bcwsma = (_m*_s+(_l-_m)) _bcwsmah = highest(high, ilong)l = lowest(low,ilong)RSV = 100*((c-l)/(h-l))pK = bcwsma(RSV, isig, 1)pD = bcwsma(pK, isig, 1)pJ = 3 * pK-2 * pDKD = avg(pK,pD)/// --- TREND --- ///avghigh = sma(h, uptrendlength)avglow = sma(l, downtrendlength) uptrend = h > avghighdowntrend = l < avglow//ICHIMOKU BUY & SELL// conversionPeriods = input(9)basePeriods = input(26)laggingSpan2Periods = input(52)displacement = input(26)donchian(len) => avg(lowest(len), highest(len))resolve(src, default) => if na(src) default else srcconversionLine = donchian(conversionPeriods)baseLine = donchian(basePeriods)leadLine1 = offset(avg(conversionLine, baseLine), displacement)leadLine2 = offset(donchian(laggingSpan2Periods), displacement)tk_cross_bull = crossover(conversionLine, baseLine)tk_cross_bear = crossunder(conversionLine, baseLine)cross_y = (conversionLine[1] * (baseLine - baseLine[1]) - baseLine[1] * (conversionLine - conversionLine[1])) / ((baseLine - baseLine[1]) - (conversionLine - conversionLine[1]))tk_cross_below_kumo = cross_y <= leadLine2[1] and cross_y <= leadLine1[1] and cross_y <= leadLine2 and cross_y <= leadLine1tk_cross_above_kumo = cross_y >= leadLine2[1] and cross_y >= leadLine1[1] and cross_y >= leadLine2 and cross_y >= leadLine1tk_cross_inside_kumo = (not tk_cross_below_kumo) and (not tk_cross_above_kumo)////BUY & SELLbuycond = (tk_cross_below_kumo or tk_cross_inside_kumo or tk_cross_above_kumo) and rising(pJ[1],1) and uptrendsellcond = (tk_cross_below_kumo or tk_cross_inside_kumo or tk_cross_above_kumo) and falling(pJ[1],1) and downtrendfromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)fromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)fromYear = input(defval = 2020, title = "From Year", minval = 1970) //monday and session // To Date InputstoDay = input(defval = 31, title = "To Day", minval = 1, maxval = 31)toMonth = input(defval = 12, title = "To Month", minval = 1, maxval = 12)toYear = input(defval = 2021, title = "To Year", minval = 1970)startDate = timestamp(fromYear, fromMonth, fromDay, 00, 00)finishDate = timestamp(toYear, toMonth, toDay, 00, 00)time_cond = time >= startDate and time <= finishDateif(time_cond) strategy.entry("long",strategy.long,when= buycond, alert_message="LONG") strategy.entry("short",strategy.short,when=sellcond, alert_message="SHORT")