Strategy · Pine Script v5 · On the chart

Davids Ichimoku Cloud Break

by fox-buddy· code credited to Liquid1209

Davids Ichimoku Cloud Break is an overlay strategy that generates trade signals based on Ichimoku Cloud breakout conditions combined with an optional MACD entry filter.

View on GitHub

GitHub stars4on the repository
Pine versionv5runs as is
Lines of code199
Settings23inputs
LicenceNone statedfile: MPL-2.0
Last update2 years ago4 Aug 2024

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

199 lines of Pine Script v5 from Tradingview/Ichimoku_Position_Trading.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

Ichimoku_Position_Trading.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Liquid1209


//@version=5
// *******************************
// ******** User Inputs **********
// *******************************
strategy("Davids Ichimoku Cloud Break", overlay=true, margin_long=100, margin_short=100)
conversionLength = input.int(9, minval=1, title="Conversion Line Length")
emaCoversion = ta.ema(close, conversionLength)
baseLength = input.int(26, minval=1, title="Base Line Length")
laggingSpan2Length = input.int(52, minval=1, title="Leading Span B Length")
displacementFutPast = input.int(26, minval=1, title="Displacement")

longPossible = input.bool(title="Long Tades", defval=true)
shortPossible = input.bool(title="Short Tades", defval=true)
useMacdFilterEntry = input.bool(title="MACD Entry Filter", defval=true)

riskLevel = input.int(defval=1, minval=1, maxval=3, title="Risk Level (3 marks the highest risk)", step=1)

dateFrom = input.time(title="Start Date", defval=timestamp("01 Jan 2020 00:00"))
dateTo = input.time(title="End Date", defval=timestamp("31 Dec 2170 23:59"))
inDateRange = (time >= dateFrom) and (time < dateTo)

//MACD Inputs
fast_length = input(title="Fast Length MACD", defval=12)
slow_length = input(title="Slow Length MACD", defval=26)
src = input(title="Source", defval=close)
signal_length = input.int(title="Signal Smoothing",  minval = 1, maxval = 50, defval = 9)
sma_source = input.string(title="Oscillator MA Type",  defval="EMA", options=["SMA", "EMA"])
sma_signal = input.string(title="Signal Line MA Type", defval="EMA", options=["SMA", "EMA"])


stop_source = input.string(title="Stop Source",  defval="Conv/Base", options=["Conv/Base", "MACD", "EMA-34"])

// *******************************
// ******** Functions *********
// *******************************
donchian(len) => math.avg(ta.lowest(len), ta.highest(len))

// *******************************
// ******** Calculations *********
// *******************************
//Present Lines
conversionLine = donchian(conversionLength)
baseLine = donchian(baseLength)

//Future Lines
leadLine1 = math.avg(conversionLine, baseLine)
leadLine2 = donchian(laggingSpan2Length)

//PastLinesForCurrentCloud
leadLine1Past = leadLine1[baseLength]
leadLine2Past = leadLine2[baseLength]

//Lagging Span Lines
leadLine1LaggingSpan = leadLine1[baseLength+displacementFutPast]
leadLine2LaggingSpan = leadLine2[baseLength+displacementFutPast]



//**********************
//****  Conditions  **** 
//**********************
//Break Cond
zone = if close > leadLine1Past and close > leadLine2Past
    1
else if close < leadLine1Past and close < leadLine2Past
    -1
else
    0

//Base Line Direction
baseDirection = if baseLine > baseLine[1]
    1
else if baseLine < baseLine[1]
    -1
else
    0
    
//lag Break Cond 
lagZone = if close > leadLine1LaggingSpan and close > leadLine2LaggingSpan
    1
else if close < leadLine1LaggingSpan and close < leadLine2LaggingSpan
    -1
else
    0
    



//**********************
//****   Plotting  ***** 
//**********************
//Indicator Plotting
plot(conversionLine, color=#2962FF, title="Conversion Line")
plot(baseLine, color=#B71C1C, title="Base Line")
plot(close, offset = -displacementFutPast + 1, color=#43A047, title="Lagging Span")
p1 = plot(leadLine1, offset = displacementFutPast - 1, color=#A5D6A7,
     title="Leading Span A")
p2 = plot(leadLine2, offset = displacementFutPast - 1, color=#EF9A9A,
     title="Leading Span B")
fill(p1, p2, color = leadLine1 > leadLine2 ? color.rgb(67, 160, 71, 90) : color.rgb(244, 67, 54, 90))


//MACD Plotting
// Plot colors MACD
col_macd = input(#2962FF, "MACD Line  ", group="Color Settings", inline="MACD")
col_signal = input(#FF6D00, "Signal Line  ", group="Color Settings", inline="Signal")
col_grow_above = input(#26A69A, "Above   Grow", group="Histogram", inline="Above")
col_fall_above = input(#B2DFDB, "Fall", group="Histogram", inline="Above")
col_grow_below = input(#FFCDD2, "Below Grow", group="Histogram", inline="Below")
col_fall_below = input(#FF5252, "Fall", group="Histogram", inline="Below")
// Calculating MACD
fast_ma = sma_source == "SMA" ? ta.sma(src, fast_length) : ta.ema(src, fast_length)
slow_ma = sma_source == "SMA" ? ta.sma(src, slow_length) : ta.ema(src, slow_length)
macd = fast_ma - slow_ma
signal = sma_signal == "SMA" ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length)
hist = macd - signal
plot(hist, title="Histogram", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below)))
plot(macd, title="MACD", color=col_macd)
plot(signal, title="Signal", color=col_signal)

//MACD 
// plotshape(macd > signal, color=color.green, style=shape.square, location=location.top, size=size.small)
// plotshape(macd < signal, color=color.red, style=shape.square, location=location.top, size=size.small)

//MACD Cross
// plotshape(ta.crossunder(macd, signal) and macd > 0, color=color.red, style=shape.square, location=location.bottom, size=size.small)
// plotshape(ta.crossover(macd, signal) and macd < 0, color=color.green, style=shape.square, location=location.bottom, size=size.small)

//EMA 34 Plotting
plot(ta.ema(close, 34), color=color.black, linewidth=2)

//Future Cloud Plotting to show Signal Condition 1
// plotshape(leadLine1 > leadLine2, color=color.green, style=shape.circle, location=location.abovebar, size=size.small)
// plotshape(leadLine2 > leadLine1, color=color.red, style=shape.circle, location=location.abovebar, size=size.small)

//current Price Position Plotting to show Signal Condition 2
// plotshape(zone > 0, color=color.green, style=shape.flag, location=location.belowbar, size=size.small)
// plotshape(zone < 0, color=color.red, style=shape.flag, location=location.belowbar, size=size.small)
// plotshape(zone == 0, color=color.black, style=shape.flag, location=location.belowbar, size=size.small)

//Base Direction Plotting to show Signal Condition 3
// plotshape(baseDirection > 0, color=color.green, style=shape.square, location=location.top, size=size.small)
// plotshape(baseDirection < 0, color=color.red, style=shape.square, location=location.top, size=size.small)
// plotshape(baseDirection == 0, color=color.black, style=shape.square, location=location.top, size=size.small)

//Lagging Position Plotting to show Signal Condition 4
// plotshape(lagZone > 0, color=color.green, style=shape.square, location=location.bottom, size=size.small)
// plotshape(lagZone < 0, color=color.red, style=shape.square, location=location.bottom, size=size.small)
// plotshape(lagZone == 0, color=color.black, style=shape.square, location=location.bottom, size=size.small)

//**********************
//****   Orders  ***** 
//**********************
longOk = if riskLevel == 3 
    zone > 0 and leadLine1 > leadLine2 and baseDirection > 0
else if riskLevel == 2
    zone > 0 and leadLine1 > leadLine2 and baseDirection > 0 and lagZone >= 0
else 
    zone > 0 and leadLine1 > leadLine2 and baseDirection > 0 and lagZone > 0

shortOk = if riskLevel == 3
    zone < 0 and leadLine2 > leadLine1 and baseDirection < 0 
else if riskLevel == 2
    zone < 0 and leadLine2 > leadLine1 and baseDirection < 0 and lagZone <= 0
else 
    zone < 0 and leadLine2 > leadLine1 and baseDirection < 0 and lagZone < 0

//Trade Closing
longClose = if stop_source == "EMA"
    close < ta.ema(close, 34)
else if stop_source == "MACD"
    macd < signal
else
    conversionLine < baseLine
shortClose = if stop_source == "EMA"
    close > ta.ema(close, 34)
else if stop_source == "MACD"
    macd > signal
else
    conversionLine > baseLine


// Submit entry orders
if (longPossible and inDateRange)
    strategy.entry("long", strategy.long, when = longOk and not longClose)
if (shortPossible and inDateRange)
    strategy.entry("short", strategy.short, when = shortOk and not shortClose)
    


// Submit exit orders
if (strategy.position_size > 0 and longClose)
    strategy.exit(id="exit long?", stop=close)
if (strategy.position_size < 0 and shortClose)
    strategy.exit(id="exit short?", stop=close)

Overview

Davids Ichimoku Cloud Break calculates and plots the Conversion Line, Base Line, Lagging Span, and Leading Spans directly on the price chart. The strategy triggers long or short entries depending on price positioning relative to the cloud and lagging span, configured across three distinct risk levels. Users can customize Ichimoku and MACD lengths, adjust trade direction filters, set backtesting date bounds, and choose dynamic stop sources such as Conversion/Base lines, MACD, or an EMA-34.

Details

Published by

fox-buddy on GitHub

Code credit

Liquid1209, as written in the script's header

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Trend, Moving averages, Oscillators & momentum

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Conversion Line Lengthint9conversionLength
Base Line Lengthint26baseLength
Leading Span B Lengthint52laggingSpan2Length
Displacementint26displacementFutPast
Long TadesbooltruelongPossible
Short TadesbooltrueshortPossible
MACD Entry FilterbooltrueuseMacdFilterEntry
Risk Level (3 marks the highest risk)int1riskLevel
Start Datetimetimestamp("01 Jan 2020 00:00")dateFrom
End Datetimetimestamp("31 Dec 2170 23:59")dateTo
Fast Length MACDint12fast_length
Slow Length MACDint26slow_length
Show all 23 settings
SettingTypeDefaultVariable
Sourcesourceclosesrc
Signal Smoothingint9signal_length
Oscillator MA TypestringEMAsma_source
Signal Line MA TypestringEMAsma_signal
Stop SourcestringConv/Basestop_source
MACD Line  color#2962FFcol_macd
Signal Line  color#FF6D00col_signal
Above   Growcolor#26A69Acol_grow_above
Fallcolor#B2DFDBcol_fall_above
Below Growcolor#FFCDD2col_grow_below
Fallcolor#FF5252col_fall_below
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

330 stars

2 EMA/SMA + RSI Strategy [Alorse] combines three configurable moving averages with a short-period Relative Strength Index filter. It plots fast, slow, and trend moving averages on the price chart. Long entries trigger when the fast moving average is above the

Strategy v4 TrendOscillators & momentum
Updated 2 months ago · None stated GitHub repository of 2 EMA/SMA + RSI Strategy [Alorse]

Acrypto - Weighted Strategy

by AlbertoCuadra
318 stars

This strategy plots on the price chart and opens long or short positions when a weighted score from MACD, Stochastic RSI, RSI, Supertrend and a moving-average crossover exceeds a user-set trigger. Each component has its own weight and candle delay. Entries can

Strategy v5 TrendOscillators & momentum
Updated 3 years ago · Custom licence GitHub repository of Acrypto - Weighted Strategy

This strategy combines Arnaud Legoux Moving Average percentage price change calculations with an adaptive Gaussian Moving Average to generate trend-following signals. Long and short entries are triggered when the ALMA change calculation crosses above or below

Strategy v5 Moving averagesOscillators & momentum
Updated 6 weeks ago · None stated GitHub repository of ESM2024 - ALMA Smoothed Gaussian Moving Average
218 stars

This strategy generates trading signals based on a selectable momentum engine, supporting MACD, RSI, Stochastic, or Rate of Change. Entries trigger on signal crosses, zero-line crosses, or threshold crosses, with an optional moving average trend filter. Risk m

Strategy v6 Oscillators & momentumTrend
Updated 3 months ago · None stated GitHub repository of Momentum Strategy Template

255 EMA Strategy

by hasnocool
106 stars

255 EMA Strategy combines an exponential moving average with Average True Range bands and standard MACD crossovers to generate entry signals. Drawn directly on the price chart, it plots the central 255 EMA along with upper and lower volatility envelopes. Trade

Strategy v4 Moving averagesOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of 255 EMA Strategy

SMA RSI Strategy

by PythonForForex
64 stars

This strategy evaluates simple moving averages and the Relative Strength Index to generate trading signals. It calculates a 10-period SMA, a 30-period SMA, and a 14-period RSI. Long positions are entered when the fast SMA crosses above the slow SMA while RSI i

Strategy v5 TrendOscillators & momentum
Updated 4 years ago · None stated GitHub repository of SMA RSI Strategy

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers