Pine Script v4 · Strategy
Ichimoku Strategy [CDI]
A Pine Script v4 strategy with no technical-analysis calculation. It has 2 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. 7 settings; defaults include Conversion Line Periods 9, Base Line Periods 26 and Lagging Span 2 Periods 52.
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 Strategy [CDI] repaint?
- No
- No repainting patterns were found in the source.
- Can Ichimoku Strategy [CDI] 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.
- What alerts does Ichimoku Strategy [CDI] have?
- 1
- Price (" + tostring(close) + ") crossed over Ichimoku Strategy..
- Does Ichimoku Strategy [CDI] use a stop loss?
- Yes
- strategy.exit sets a stop on line 50.
- Does Ichimoku Strategy [CDI] run in Zeal Terminal?
- No
- Not yet: Pine Script v4 Error at @L15:C12: Undeclared identifier 'offset'.
Review
What a careful reader of this script would point out, found by checking the source.
-
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 offset(), which v5 removed line 15
offset() on line 15, 16. 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 avg → math.avg, lowest → ta.lowest, highest → ta.highest, tostring → str.tostring.
v4 → v5
Not verifiedThe v4 script does not run in Zeal Terminal's engine (Pine Script v4 Error at @L15:C12: Undeclared identifier 'offset'.), so this step could not be checked.
- Line 3: //@version=4 → //@version=5
- Line 12: avg → math.avg
- Line 12: lowest → ta.lowest
- Line 12: highest → ta.highest
- Line 15: offset(x, n) → (x)[n]
- Line 15: avg → math.avg
3 more edits
- Line 16: offset(x, n) → (x)[n]
- Line 17: avg → math.avg
- Line 38: tostring → str.tostring
⋯// © JMLSlop-//@version=4+//@version=5strategy("Ichimoku Strategy [CDI]", shorttitle="Ichimoku Strategy", overlay=true, pyramiding=3, calc_on_order_fills=false )⋯PreBars = input(6, minval=2, title="Crossing Candles:")-donchian(len) => avg(lowest(len), highest(len))+donchian(len) => math.avg(ta.lowest(len), ta.highest(len))conversionLine = donchian(conversionPeriods)baseLine = donchian(basePeriods)-leadLine1 = offset(avg(conversionLine, baseLine),displacement - 1)+leadLine1 = (math.avg(conversionLine, baseLine))[displacement - 1]-leadLine2 = offset(donchian(laggingSpan2Periods),displacement - 1)+leadLine2 = (donchian(laggingSpan2Periods))[displacement - 1]-leadLine1ax = avg(conversionLine, baseLine)+leadLine1ax = math.avg(conversionLine, baseLine)leadLine2ax = donchian(laggingSpan2Periods)⋯barColour = if (conditionEntry)- alert("Price (" + tostring(close) + ") crossed over Ichimoku Strategy.", alert.freq_all)+ alert("Price (" + str.tostring(close) + ") crossed over Ichimoku Strategy.", alert.freq_all) color.yellow⋯Clean v5
VerifiedSame 10 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 5: input() → input.int()
- Line 6: input() → input.int()
- Line 7: input() → input.int()
- Line 8: input() → input.int()
- Line 9: input() → input.int()
- Line 10: input() → input.int()
- Line 11: input() → input.int()
⋯strategy("Ichimoku Strategy [CDI]", shorttitle="Ichimoku Strategy", overlay=true, pyramiding=3, calc_on_order_fills=false )-conversionPeriods = input(9, minval=1, title="Conversion Line Periods")+conversionPeriods = input.int(9, minval=1, title="Conversion Line Periods")-basePeriods = input(26, minval=1, title="Base Line Periods")+basePeriods = input.int(26, minval=1, title="Base Line Periods")-laggingSpan2Periods = input(52, minval=1, title="Lagging Span 2 Periods")+laggingSpan2Periods = input.int(52, minval=1, title="Lagging Span 2 Periods")-displacement = input(26, minval=1, title="Displacement")+displacement = input.int(26, minval=1, title="Displacement")-limmit = input(6, minval=1, title="Profit %") * 0.01+limmit = input.int(6, minval=1, title="Profit %") * 0.01-stop = input(3, minval=1, title="Loss %") * 0.01+stop = input.int(3, minval=1, title="Loss %") * 0.01-PreBars = input(6, minval=2, title="Crossing Candles:")+PreBars = input.int(6, minval=2, title="Crossing Candles:")donchian(len) => math.avg(ta.lowest(len), ta.highest(len))⋯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: 10 before, 8 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.
⋯// © JMLSlop-//@version=5+//@version=6strategy("Ichimoku Strategy [CDI]", shorttitle="Ichimoku Strategy", overlay=true, pyramiding=3, calc_on_order_fills=false )⋯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 |
|---|---|---|---|
| Conversion Line Periods | 9 | int · min 1 | conversionLine |
| Base Line Periods | 26 | int · min 1 | baseLine |
| Lagging Span 2 Periods | 52 | int · min 1 | leadLine2 leadLine2ax |
| Displacement | 26 | int · min 1 | leadLine1 leadLine2 Lead 1 Lead 2 Lagging Span |
| Profit % | 6 | int · min 1 | takeProfitPrice |
| Loss % | 3 | int · min 1 | longStopPrice |
| Crossing Candles: | 6 | int · min 2 | line 32 |
What it calculates
No technical-analysis calculation: the script works on prices and settings directly.
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 Entry long | (conditionEntry) | On | 49 |
| Exit Exit stop and limit | every bar | On | 50 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Alerts
| Alert | Call | Message | Line |
|---|---|---|---|
| (no title) | alert | Price (" + tostring(close) + ") crossed over Ichimoku Strategy. | 38 |
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
No other indicator or strategy here shares enough of its calculations.
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | No Pine Script v4 Error at @L15: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/// © JMLSlop//@version=4strategy("Ichimoku Strategy [CDI]", shorttitle="Ichimoku Strategy", overlay=true, pyramiding=3, calc_on_order_fills=false )conversionPeriods = input(9, minval=1, title="Conversion Line Periods")basePeriods = input(26, minval=1, title="Base Line Periods")laggingSpan2Periods = input(52, minval=1, title="Lagging Span 2 Periods")displacement = input(26, minval=1, title="Displacement")limmit = input(6, minval=1, title="Profit %") * 0.01stop = input(3, minval=1, title="Loss %") * 0.01PreBars = input(6, minval=2, title="Crossing Candles:")donchian(len) => avg(lowest(len), highest(len))conversionLine = donchian(conversionPeriods)baseLine = donchian(basePeriods)leadLine1 = offset(avg(conversionLine, baseLine),displacement - 1)leadLine2 = offset(donchian(laggingSpan2Periods),displacement - 1)leadLine1ax = avg(conversionLine, baseLine)leadLine2ax = donchian(laggingSpan2Periods)plot(conversionLine, color=#0496ff, title="Conversion Line", display=display.none)plot(baseLine, color=#991515, title="Base Line", display=display.none)plot(close, offset = -displacement + 1, color=#459915, title="Lagging Span", display=display.none)p1 = plot(leadLine1ax, offset = displacement - 1, color=color.green, title="Lead 1",display=display.none)p2 = plot(leadLine2ax, offset = displacement - 1, color=color.red, title="Lead 2",display=display.none)fill(p1, p2, color = leadLine1ax > leadLine2ax ? color.green : color.red)// Orders confighigherLine = leadLine1 > leadLine2 ? leadLine1 : leadLine2downLine = leadLine1 < leadLine2 ? leadLine1 : leadLine2crossConfim = falsevar float auxlead = nafor i = 1 to PreBars auxlead := leadLine1[i] < leadLine2 [i] ? leadLine1[i] : leadLine2[i] crossConfim:= crossConfim or (auxlead >= open[i]) or auxlead >= close[i] conditionEntry = (open > higherLine or close > higherLine) and crossConfim and (open[1] < higherLine[1] and close[1] < higherLine[1])barColour = if (conditionEntry) alert("Price (" + tostring(close) + ") crossed over Ichimoku Strategy.", alert.freq_all) color.yellowelse nabarcolor(color=barColour)bgcolor(color=barColour)takeProfitPrice = 0.0longStopPrice = 0.0takeProfitPrice := conditionEntry and strategy.position_size == 0 ? close + (close * limmit) : takeProfitPrice[1]longStopPrice := conditionEntry ? close - (close * stop) : longStopPrice[1]if (conditionEntry) strategy.entry("Entry", strategy.long)strategy.exit("Exit", limit=takeProfitPrice, stop=longStopPrice)//alertcondition(condition=conditionEntry,title="Crossover Ichimoku",message="Price (" + tostring(close) + ") crossed over Ichimoku Strategy.")