Ichimoku Oscillator
Ichimoku Oscillator
Ichimoku Oscillator
0 at
https://mozilla.org/MPL/2.0/
// © LonesomeTheBlue
//@version=5
indicator(title="Ichimoku Oscillator", shorttitle="IO", explicit_plot_zorder =
true)
conversionPeriods = input.int(8, minval=1, title="Conversion Line Length", group =
"Setup")
basePeriods = input.int(13, minval=1, title="Base Line Length", group = "Setup")
laggingSpan2Periods = input.int(26, minval=1, title="Leading Span B Length", group
= "Setup")
displacement = input.int(13, minval=1, title="Lagging Span", group = "Setup")
useatr = input.bool(defval = true, title ="Use ATR", tooltip = "Protection from
Whipsaw", group = "Setup")
atrlen = input.int(defval = 9, title = " Length", minval = 1, group = "Setup")
atrmul = input.float(defval = 2.0, title = " Mult", minval = 0.1, step = 0.1,
group = "Setup")
bounceoff = input.bool(defval = false, title = "Bounce Off Support/Resistance",
tooltip = "Enables the Additional Entries when price bounce off Support/Resistance
Zone", group = "Setup")
useema = input.bool(defval = true, title ="Show EMA", group = "Setup")
emalen = input.int(defval = 9, title = " Length", minval = 1, group = "Setup")
emacol = input.color(defval = #d1c4e9, title = " Color", group = "Setup")
emawd = input.int(defval = 1, title = " Width", minval = 1, maxval = 5, group =
"Setup")
ematkpartprft = input.bool(defval = true, title = "Take Partial Profit by EMA")
entexlongcol = input.color(defval = color.white, title = "Entry/Exit Colors",
inline = "entcol", group = "Colors")
entexshortcol = input.color(defval = color.yellow, title = "", inline = "entcol",
group = "Colors")
coloredbg = input.bool(defval = true, title = "Colored Background", group =
"Colors")
bgcolupI = input.string(defval = "Green", title = " Uptrend", options = ["Green",
"Red", "Blue"], group = "Colors")
bgcoldnI = input.string(defval = "Blue", title = " Downtrend", options = ["Green",
"Red", "Blue"], group = "Colors")
bgtransp = input.int(defval = 60, title = " Transparency", step = 10, minval = 0,
maxval = 100, group = "Colors")
upcol1 = input.color(defval = color.rgb(0 , 250, 0, 0), title = "Uptrend Colors",
inline = "upcols", group = "Colors")
upcol2 = input.color(defval = color.rgb(0 , 190, 0, 0), title = "", inline =
"upcols", group = "Colors")
upcol3 = input.color(defval = color.rgb(0 , 130, 0, 0), title = "", inline =
"upcols", group = "Colors")
upcol4 = input.color(defval = color.rgb(0 , 70, 0, 0), title = "", inline =
"upcols", group = "Colors")
dbcol1 = input.color(defval = color.rgb(250, 0, 0, 0), title = "Downtrend Colors",
inline = "dbcols", group = "Colors")
dbcol2 = input.color(defval = color.rgb(190, 0, 0, 0), title = "", inline =
"dbcols", group = "Colors")
dbcol3 = input.color(defval = color.rgb(130, 0, 0, 0), title = "", inline =
"dbcols", group = "Colors")
dbcol4 = input.color(defval = color.rgb(70, 0, 0, 0), title = "", inline =
"dbcols", group = "Colors")
inSRcolor = input.color(defval = #d1d4dc, title = "In Support/Resistance Zone",
group = "Colors")
// Alerts
mainalert = input.bool(defval = true, title = "Main Buy/Sell Alert", group =
"Alerts")
addalert = input.bool(defval = true, title = "Additional Buy/Sell Alert", group =
"Alerts")
alertlongmsg = input.string(defval = "Buy / Main, Close = close", title = " Long
message", group = "Alerts")
alertshortmsg = input.string(defval = "Sell / Main, Close = close", title = "
Short message", group = "Alerts")
alertaddlongmsg = input.string(defval = "Buy / Additonal, Close = close", title =
" Long message", group = "Alerts")
alertaddshortmsg = input.string(defval = "Sell / Additonal, Close = close", title =
" Short message", group = "Alerts")
mainfrequency = input.string(defval = alert.freq_once_per_bar_close, title = "
Frequency", options = [alert.freq_once_per_bar_close, alert.freq_once_per_bar],
group = "Alerts")
closealert = input.bool(defval = true, title = "Close Position Alert", group =
"Alerts")
closepartalert = input.bool(defval = true, title = "Take Partial Profit Alert",
group = "Alerts")
closemainmsg = input.string(defval = "Close Position, Close = close", title = "
Close Position Message", group = "Alerts")
closepartmsg = input.string(defval = "Take Partial Profit, Close = close", title =
" Take Partial Profit Message", group = "Alerts")
closefrequency = input.string(defval = alert.freq_once_per_bar, title = "
Frequency", options = [alert.freq_once_per_bar_close, alert.freq_once_per_bar],
group = "Alerts")
// ichimoku calculation
donchian(len) => math.avg(ta.lowest(len), ta.highest(len))
conversionLine = donchian(conversionPeriods)
baseLine = donchian(basePeriods)
leadLine1 = math.avg(conversionLine, baseLine)
leadLine2 = donchian(laggingSpan2Periods)
// Oscillator calculation
var int mtrend = 0
var int trend = 0
cloudup = leadLine1 >= leadLine2
clouddn = leadLine1 <= leadLine2
CloudMin = math.min(leadLine1[displacement - 1], leadLine2[displacement - 1])
CloudMax = math.max(leadLine1[displacement - 1], leadLine2[displacement - 1])
inthecloud = close >= CloudMin and close <= CloudMax
mtrend := close > CloudMax ? 1 : close < CloudMin ? -1 : mtrend
// first layer
Oscline = mtrend == 1 ? (close - CloudMin) : (close - CloudMax)
Osccolor = inthecloud ? inSRcolor: close > CloudMax ? upcol1 : dbcol1
//second layer
Lagging = Oscline + (mtrend == 1 ? math.max(close - CloudMax[displacement - 1],
0) : // , close - close[displacement - 1]
math.min(close - CloudMin[displacement - 1], 0))
// , close - close[displacement - 1]
//third layer
ConvBase = Lagging + (mtrend == 1 ? math.max((conversionLine - baseLine), 0) :
math.min((conversionLine -baseLine), 0))
ConvBaseColor = conversionLine >= baseLine ? upcol3 : dbcol3
// fourth layer
cloud = ConvBase + (mtrend == 1 ? math.max(leadLine1 - leadLine2, 0) :
math.min(leadLine1 - leadLine2, 0))
// ploting layers
plot(cloud, color = mtrend == 1 ? upcol4 : dbcol4, style = plot.style_area)
plot(ConvBase, color = ConvBaseColor, style = plot.style_area)
plot(Lagging, color = close > CloudMax ? upcol2 : close < CloudMin ? dbcol2 :
color.new(color.white, 100), style = plot.style_area)
plot(Oscline, color = Osccolor, style = plot.style_area)
profitable = trend == 4 and close > entrylevel or trend == -4 and close <
entrylevel