COMBINATION INDICATOR Supertrend Ichimoku Chop (林19).pine
Copy
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © HayashiHitsuji
//@version=5
indicator("Supertrend Ichimoku Chop Combination Indicator (林19)", shorttitle = "Super Ichimoku Chopiness (林19)", overlay = true)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// INDICATOR INPUT =============================================================
// SUPERTREND //
st_ind = input.bool(false, "--------------- ATR INDICATOR ---------------")
st_signal = input.bool(true, "Show supertrend long short signal?")
atr_type = input.bool(true, "Use atr highest lowest calculation?")
atr_src = input.source(hl2, "ATR Source")
atr_length = input.int(1, "ATR")
atr_mult = input.float(1.85, "ATR Mult")
// ICHIMOKU CLOUD //
ichimoku_ind = input.bool(false, "--------------- ICHIMOKU INDICATOR ---------------")
ichimoku = input.bool(true, 'Show Ichimoku?')
con_per = input.int(9, 'Conversion Line Length')
base_per = input.int(26, 'Base Line Length')
lagspan_per = input.int(52, 'Leading Span Length')
displacement = input.int(26, 'Displacement')
// CHOP CANDLE //
chop = input.bool(false, "--------------- CHOP CANDLE INDICATOR ---------------")
show_candle = input.bool(true, "Show the candle?")
// ========================================================================== //
// INDICATOR CALCULATION =======================================================
// SUPERTREND //
// Algo: set the heikin ashi candle source =====================================
ha_open = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, open)
ha_high = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, high)
ha_low = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, low)
ha_close = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, close)
// ========================================================================== //
// Algo: ATR manual calculation, the source from the heikin ashi ===============
pine_atr(length) =>
trueRange = na(ha_high[1])? ha_high-ha_low : math.max(math.max(ha_high - ha_low, math.abs(ha_high - ha_close[1])), math.abs(ha_low - ha_close[1]))
ta.rma(trueRange, length)
atr = atr_mult * pine_atr(atr_length)
// ========================================================================== //
// Algo: set the supertrend value ==============================================
longStop = (atr_type ? ta.highest(ha_close, atr_length) : ta.highest(atr_length)) - atr
longStopPrev = nz(longStop[1], longStop)
longStop := ha_close[1] > longStopPrev ? math.max(longStop, longStopPrev) : longStop
shortStop = (atr_type ? ta.lowest(ha_close, atr_length) : ta.lowest(atr_length)) + atr
shortStopPrev = nz(shortStop[1], shortStop)
shortStop := ha_close[1] < shortStopPrev ? math.min(shortStop, shortStopPrev) : shortStop
var int dir = 1
dir := ha_close > shortStopPrev ? 1 : ha_close < longStopPrev ? -1 : dir
// Supertrend color
var color longColor = color.aqua
var color shortColor = color.fuchsia
// ========================================================================== //
// INCHIMOKU CLOUD //
donchian(len) => math.avg(ta.lowest(len), ta.highest(len))
con_line = donchian(con_per)
base_line = donchian(base_per)
lead_line_1 = math.avg(con_line, base_line)
lead_line_2 = donchian(lagspan_per)
lag_span = close
// CHOP CANDLE //
src = input(close, title = "Source")
avg = input.source(ohlc4, "Indicator Average Source")
pi = math.atan(input.int(1, "Arctan")) * input.int(4, "Arctan Mult")
periods = input.int(30, "High Low Period")
highestHigh = ta.highest(periods)
lowestLow = ta.lowest(periods)
span = input.int(25, "Span") / (highestHigh - lowestLow) * lowestLow
ema34 = ta.ema(src, input.int(34, "EMA"))
x1_ema34 = 0
x2_ema34 = 1
y1_ema34 = 0
y2_ema34 = (ema34[1] - ema34) / avg * span
c_ema34 = math.sqrt((x2_ema34 - x1_ema34) * (x2_ema34 - x1_ema34) + (y2_ema34 - y1_ema34)*(y2_ema34 - y1_ema34))
emaAngle_1 = math.round(180 * math.acos((x2_ema34 - x1_ema34)/c_ema34) / pi)
emaAngle = y2_ema34 > 0 ? - emaAngle_1 : emaAngle_1
chopZoneColor = emaAngle >= 5 ? #00FF00 :
emaAngle < 5 and emaAngle >= 3.57 ? #00FFFF :
emaAngle < 3.57 and emaAngle >= 2.14 ? #005EFF :
emaAngle < 2.14 and emaAngle >= .71 ? #A4E600 :
emaAngle <= -1 * 5 ? #FF0000 :
emaAngle > -1 * 5 and emaAngle <= -1 * 3.57 ? #FF17FF :
emaAngle > -1 * 3.57 and emaAngle <= -1 * 2.14 ? #BE0AFF :
emaAngle > -1 * 2.14 and emaAngle <= -1 * .71 ? #FF5500 :
color.yellow
// candle
plotcandle(show_candle ? open : na, high, low, close, color = chopZoneColor, wickcolor = chopZoneColor, bordercolor = chopZoneColor)
// ========================================================================== //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// INDICATOR CONDITION =========================================================
buy_signal = dir == 1 and dir[1] == -1
sell_signal = dir == -1 and dir[1] == 1
// ========================================================================== //
// INDICATOR PLOT ==============================================================
plotshape(st_signal and buy_signal ? close - low/100 : na, text = "Long", location = location.absolute, style = shape.labelup, size = size.tiny, color = #00FF00, textcolor = color.white)
plotshape(st_signal and sell_signal ? close + high/100 : na, text = "Short", location = location.absolute, style = shape.labeldown, size = size.tiny, color = #FF0000, textcolor = color.white)
// ICHIMOKU CLOUD //
p1 = plot(ichimoku ? lead_line_1 : na, color = #00FF00, title = 'Leading Span A')
p2 = plot(ichimoku ? lead_line_2 : na, color = #FF0000, title = 'Leading Span B')
kumo_color = lead_line_1 >= lead_line_2 ? #00FF00 : #FF0000
fill(p1, p2, color = color.new(kumo_color, 90))
// ========================================================================== //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//add on
ema = input.bool(false, "EMA")
ema50 = ta.ema(close, 50)
ema100 = ta.ema(close, 100)
ema200 = ta.ema(close, 200)
plot(ema ? ema50 : na, color = color.lime)
plot(ema ? ema100 : na, color = color.white)
plot(ema ? ema200 : na, color = color.red)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © HayashiHitsuji
//@version=5
indicator("Supertrend Ichimoku Chop Combination Indicator (林19)", shorttitle = "Super Ichimoku Chopiness (林19)", overlay = true)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// INDICATOR INPUT =============================================================
// SUPERTREND //
st_ind = input.bool(false, "--------------- ATR INDICATOR ---------------")
st_signal = input.bool(true, "Show supertrend long short signal?")
atr_type = input.bool(true, "Use atr highest lowest calculation?")
atr_src = input.source(hl2, "ATR Source")
atr_length = input.int(1, "ATR")
atr_mult = input.float(1.85, "ATR Mult")
// ICHIMOKU CLOUD //
ichimoku_ind = input.bool(false, "--------------- ICHIMOKU INDICATOR ---------------")
ichimoku = input.bool(true, 'Show Ichimoku?')
con_per = input.int(9, 'Conversion Line Length')
base_per = input.int(26, 'Base Line Length')
lagspan_per = input.int(52, 'Leading Span Length')
displacement = input.int(26, 'Displacement')
// CHOP CANDLE //
chop = input.bool(false, "--------------- CHOP CANDLE INDICATOR ---------------")
show_candle = input.bool(true, "Show the candle?")
// ========================================================================== //
// INDICATOR CALCULATION =======================================================
// SUPERTREND //
// Algo: set the heikin ashi candle source =====================================
ha_open = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, open)
ha_high = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, high)
ha_low = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, low)
ha_close = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, close)
// ========================================================================== //
// Algo: ATR manual calculation, the source from the heikin ashi ===============
pine_atr(length) =>
trueRange = na(ha_high[1])? ha_high-ha_low : math.max(math.max(ha_high - ha_low, math.abs(ha_high - ha_close[1])), math.abs(ha_low - ha_close[1]))
ta.rma(trueRange, length)
atr = atr_mult * pine_atr(atr_length)
// ========================================================================== //
// Algo: set the supertrend value ==============================================
longStop = (atr_type ? ta.highest(ha_close, atr_length) : ta.highest(atr_length)) - atr
longStopPrev = nz(longStop[1], longStop)
longStop := ha_close[1] > longStopPrev ? math.max(longStop, longStopPrev) : longStop
shortStop = (atr_type ? ta.lowest(ha_close, atr_length) : ta.lowest(atr_length)) + atr
shortStopPrev = nz(shortStop[1], shortStop)
shortStop := ha_close[1] < shortStopPrev ? math.min(shortStop, shortStopPrev) : shortStop
var int dir = 1
dir := ha_close > shortStopPrev ? 1 : ha_close < longStopPrev ? -1 : dir
// Supertrend color
var color longColor = color.aqua
var color shortColor = color.fuchsia
// ========================================================================== //
// INCHIMOKU CLOUD //
donchian(len) => math.avg(ta.lowest(len), ta.highest(len))
con_line = donchian(con_per)
base_line = donchian(base_per)
lead_line_1 = math.avg(con_line, base_line)
lead_line_2 = donchian(lagspan_per)
lag_span = close
// CHOP CANDLE //
src = input(close, title = "Source")
avg = input.source(ohlc4, "Indicator Average Source")
pi = math.atan(input.int(1, "Arctan")) * input.int(4, "Arctan Mult")
periods = input.int(30, "High Low Period")
highestHigh = ta.highest(periods)
lowestLow = ta.lowest(periods)
span = input.int(25, "Span") / (highestHigh - lowestLow) * lowestLow
ema34 = ta.ema(src, input.int(34, "EMA"))
x1_ema34 = 0
x2_ema34 = 1
y1_ema34 = 0
y2_ema34 = (ema34[1] - ema34) / avg * span
c_ema34 = math.sqrt((x2_ema34 - x1_ema34) * (x2_ema34 - x1_ema34) + (y2_ema34 - y1_ema34)*(y2_ema34 - y1_ema34))
emaAngle_1 = math.round(180 * math.acos((x2_ema34 - x1_ema34)/c_ema34) / pi)
emaAngle = y2_ema34 > 0 ? - emaAngle_1 : emaAngle_1
chopZoneColor = emaAngle >= 5 ? #00FF00 :
emaAngle < 5 and emaAngle >= 3.57 ? #00FFFF :
emaAngle < 3.57 and emaAngle >= 2.14 ? #005EFF :
emaAngle < 2.14 and emaAngle >= .71 ? #A4E600 :
emaAngle <= -1 * 5 ? #FF0000 :
emaAngle > -1 * 5 and emaAngle <= -1 * 3.57 ? #FF17FF :
emaAngle > -1 * 3.57 and emaAngle <= -1 * 2.14 ? #BE0AFF :
emaAngle > -1 * 2.14 and emaAngle <= -1 * .71 ? #FF5500 :
color.yellow
// candle
plotcandle(show_candle ? open : na, high, low, close, color = chopZoneColor, wickcolor = chopZoneColor, bordercolor = chopZoneColor)
// ========================================================================== //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// INDICATOR CONDITION =========================================================
buy_signal = dir == 1 and dir[1] == -1
sell_signal = dir == -1 and dir[1] == 1
// ========================================================================== //
// INDICATOR PLOT ==============================================================
plotshape(st_signal and buy_signal ? close - low/100 : na, text = "Long", location = location.absolute, style = shape.labelup, size = size.tiny, color = #00FF00, textcolor = color.white)
plotshape(st_signal and sell_signal ? close + high/100 : na, text = "Short", location = location.absolute, style = shape.labeldown, size = size.tiny, color = #FF0000, textcolor = color.white)
// ICHIMOKU CLOUD //
p1 = plot(ichimoku ? lead_line_1 : na, color = #00FF00, title = 'Leading Span A')
p2 = plot(ichimoku ? lead_line_2 : na, color = #FF0000, title = 'Leading Span B')
kumo_color = lead_line_1 >= lead_line_2 ? #00FF00 : #FF0000
fill(p1, p2, color = color.new(kumo_color, 90))
// ========================================================================== //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//add on
ema = input.bool(false, "EMA")
ema50 = ta.ema(close, 50)
ema100 = ta.ema(close, 100)
ema200 = ta.ema(close, 200)
plot(ema ? ema50 : na, color = color.lime)
plot(ema ? ema100 : na, color = color.white)
plot(ema ? ema200 : na, color = color.red)
Show all 292 lines