Strategy · Pine Script v5 · On the chart

Davids Ichimoku Conversion Base Break

by fox-buddy· code credited to Liquid1209

This strategy plots Ichimoku conversion and base lines on the price chart using Donchian midpoints.

View on GitHub

GitHub stars4on the repository
Pine versionv5runs as is
Lines of code216
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

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

Ichimoku_Swing_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 Conversion Base 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  **** 
//**********************

linesUpCross = ta.crossover(conversionLine, baseLine)
linesDownCross = ta.crossunder(conversionLine, baseLine)
crossValue = conversionLine

//conv Line Base Line Cross
convBaseLocation = if conversionLine > baseLine
    1
else if conversionLine < baseLine
    -1
else
    0

//Cross Cloud Position
crossZone = if crossValue > leadLine1Past and crossValue > leadLine2Past
    1
else if crossValue < leadLine1Past and crossValue < leadLine2Past
    -1
else
    0

//Price Cloud Position
zone = if close > leadLine1Past and close > leadLine2Past
    1
else if close < leadLine1Past and close < leadLine2Past
    -1
else
    0

    
//Lagging Span Price Position
lagZone = if close > close[26] 
    1
else if close < close[26] 
    -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)

//current Price Position 
// plotshape(zone > 0, color=color.green, style=shape.square, location=location.top, size=size.small)
// plotshape(zone < 0, color=color.red, style=shape.square, location=location.top, size=size.small)
// plotshape(zone == 0, color=color.black, style=shape.square, location=location.top, size=size.small)


//Plotting Lagging Span Price Relation
// plotshape(lagZone > 0, color=color.green, style=shape.circle, location=location.abovebar, size=size.small)
// plotshape(lagZone < 0, color=color.red, style=shape.circle, location=location.abovebar, size=size.small)
// plotshape(lagZone == 0, color=color.black, style=shape.circle, location=location.abovebar, size=size.small)

//Plotting Cross Position
// plotshape(linesUpCross ? crossValue : na, color=color.green, style=shape.xcross, location=location.absolute, size=size.normal)
// plotshape(linesDownCross ? crossValue : na, color=color.red, style=shape.xcross, location=location.absolute, size=size.normal)

//Plotting Cross Cloud Relation
// plotshape(crossZone > 0 and (linesUpCross or linesDownCross), color=color.green, style=shape.square, location=location.bottom, size=size.small)
// plotshape(crossZone < 0 and (linesUpCross or linesDownCross), color=color.red, style=shape.square, location=location.bottom, size=size.small)
// plotshape(crossZone == 0 and (linesUpCross or linesDownCross), color=color.black, style=shape.square, location=location.bottom, size=size.small)

// linesUpCross = ta.crossover(conversionLine, baseLine)
// linesDownCross = ta.crossunder(conversionLine, baseLine)
//**********************
//****   Orders  ***** 
//**********************
longOk = if riskLevel == 3 
    convBaseLocation > 0 and zone > 0 and lagZone > 0
else if riskLevel == 2
    convBaseLocation > 0 and zone > 0 and lagZone > 0 and crossZone >= 0
else 
    convBaseLocation > 0 and zone > 0 and lagZone > 0 and crossZone > 0

shortOk = if riskLevel == 3
    convBaseLocation < 0 and zone < 0 and lagZone < 0
else if riskLevel == 2
    convBaseLocation < 0 and zone < 0 and lagZone < 0 and crossZone <= 0
else 
    convBaseLocation < 0 and zone < 0 and lagZone < 0 and crossZone < 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 Conversion Base Break detects conversion-base crossovers and classifies the cross, the close, and a 26-bar price lag relative to the displaced cloud. Inputs enable or disable long and short trades, an optional MACD entry filter, a risk level from one to three, and a stop source of conversion/base, MACD, or EMA-34, plus a backtest date window. The excerpt does not show the actual order or exit logic.

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, 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
285 stars

Mean Reversion Strategy is an overlay strategy that identifies pullbacks using a long-term EMA, RSI, and candlestick patterns. It generates long signals when a bullish engulfing candle forms below the EMA while RSI is oversold, and short signals when a bearish

Strategy v4 Mean reversionCandlestick patterns
Updated 3 years ago · None stated GitHub repository of Mean Reversion Strategy
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

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