Zeal Terminal Open Zeal Terminal

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'.
Does not run in Zeal Terminal yetPine Script v4 Error at @L46:C12: Undeclared identifier 'offset'. The settings, logic and review below are read from the source, which does not need a run.

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 verified

The 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 verified

Neither 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.

SettingDefaultType and rangeFeeds
Uptrend Length4intavghigh
Downtrend Length4intavglow
Conversion Periods (no label in the script)9intconversionLine
Base Periods (no label in the script)26intbaseLine
Lagging Span2Periods (no label in the script)52intleadLine2
Displacement (no label in the script)26intleadLine1 leadLine2
From Day1int · min 1 · max 31startDate
From Month1int · min 1 · max 12startDate
From Year2020int · min 1970startDate
To Day31int · min 1 · max 31finishDate
To Month12int · min 1 · max 12finishDate
To Year2021int · min 1970finishDate

What it calculates

  • Highest (highest, ta.highest in v5)high, ilongh · line 21
  • Lowest (lowest, ta.lowest in v5)low, ilongl · line 22
  • SMA (sma, ta.sma in v5)h, Uptrend Length (4)avghigh · line 29
  • SMA (sma, ta.sma in v5)l, Downtrend Length (4)avglow · line 30
  • Crossover (crossover, ta.crossover in v5)conversionLine, baseLinetk_cross_bull · line 48
  • Crossunder (crossunder, ta.crossunder in 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.

highhighprice datalowlowprice datauptrendlengthUptrend Lengthsetting · 4downtrendlengthDowntrend Lengthsetting · 4openopenprice dataclosecloseprice dataconversionPeriodsConversion Periodssetting · 9basePeriodsBase Periodssetting · 26displacementDisplacementsetting · 26laggingSpan2PeriodsLagging Span2Periodssetting · 52fromYearFrom Yearsetting · 2020fromMonthFrom Monthsetting · 1fromDayFrom Daysetting · 1toYearTo Yearsetting · 2021toMonthTo Monthsetting · 12toDayTo Daysetting · 31timetimeprice datahHighest→ hlLowest→ lavghighSMA→ avghighavglowSMA→ avglowtk_cross_bullCrossover→ tk_cross_bulltk_cross_bearCrossunder→ tk_cross_bearoovaluec, src, pricec · src +13 values_s, _m_s · _m2 values_l_lvalue_bcwsma_bcwsmavalueRSVRSVvaluepKpKvaluepDpDvaluepJ, KDpJ · KD2 valuesconversionLineconversionLinevaluebaseLinebaseLinevalueleadLine1leadLine1valueleadLine2leadLine2valuecross_ycross_yvaluestartDatestartDatevaluefinishDatefinishDatevaluebuycondbuycondconditionsellcondsellcondconditiontime_condtime_condconditionuptrenduptrendconditiondowntrenddowntrendconditiontk_cross_below_kumo, tk_cross_above_kumo, tk_cross_inside_kumotk_cross_below_kumo · t…3 conditionsentry:longOpen longstrategy.entryentry:shortOpen shortstrategy.entry

Order rules

OrderFires whenBy defaultLine
Open long longbuycond(tk_cross_below_kumo or tk_cross_inside_kumo or tk_cross_above_kumo) and rising(pJ[1],1) and uptrendOn70
Open short shortsellcond(tk_cross_below_kumo or tk_cross_inside_kumo or tk_cross_above_kumo) and falling(pJ[1],1) and downtrendOn71

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.

ScriptSharesTypeNetTradesMax drawdown
Accumulation Stage Identifier and Strategy around for Trading by stocktechbotsma rising lowest highest fallingv5 strategy−0.0%164.1%
Reversal closing price by EduardoMattjerising falling sma lowest highestv4 strategy−10.0%5310.7%
ChBrkOutStrategySMA by anshuanshu333sma highest lowestv4 strategy−4.5%4220.9%
KDJ Strategy @ionvolution by ionvolutionsma highest lowestv5 strategyNo trades on this market
Trendelicious Strategy by levieuxhighest rising fallingv5 strategy−12.8%941.4%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2No Pine Script v4 Error at @L46:C12: Undeclared identifier 'offset'.Not measured
PineTSNo 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")