pinescript Copy code
//@version=5
indicator("Ichimoku Cloud with Buy/Sell Signals", overlay=true, shorttitle="Ichimoku Signals")
// Input Settings
tenkan_period = input.int(9, title="Tenkan Sen Period", minval=1, group="Ichimoku Settings")
kijun_period = input.int(26, title="Kijun Sen Period", minval=1, group="Ichimoku Settings")
senkou_span_b_period = input.int(52, title="Senkou Span B Period", minval=1, group="Ichimoku Settings")
displacement = input.int(26, title="Displacement", minval=1, group="Ichimoku Settings")
// Display Toggles
show_tenkan = input.bool(true, title="Show Tenkan Sen", group="Display Options")
show_kijun = input.bool(true, title="Show Kijun Sen", group="Display Options")
show_chikou = input.bool(true, title="Show Chikou Span", group="Display Options")
show_cloud = input.bool(true, title="Show Cloud", group="Display Options")
show_signals_on_chart = input.bool(true, title="Show Buy/Sell Signals on Chart", group="Display Options")
// Pane Label Settings
show_pane_signal_label = input.bool(true, title="Show Signal Status in Pane (Top)", group="Pane Signal Label")
pane_label_position_y_offset = input.float(1.02, title="Vertical Position Offset", step=0.01, group="Pane Signal Label")
pane_label_text_color = input.color(color.white, title="Text Color", group="Pane Signal Label")
pane_label_size_str = input.string("Normal", title="Text Size", options=["Tiny", "Small", "Normal", "Large", "Huge"], group="Pane Signal Label")
// TK Cross Arrow Settings
show_tk_simple_arrows = input.bool(true, title="Show TK Simple Cross Arrows", group="TK Simple Cross")
tk_simple_arrow_size_str = input.string("Normal", title="Arrow Size", options=["Auto", "Tiny", "Small", "Normal", "Large", "Huge"], group="TK Simple Cross")
tk_simple_up_color = input.color(color.new(color.blue, 30), title="TK Cross Up Color", group="TK Simple Cross")
tk_simple_down_color = input.color(color.new(color.maroon, 30), title="TK Cross Down Color", group="TK Simple Cross")
// Ichimoku Calculations
tenkan_sen = (ta.highest(high, tenkan_period) + ta.lowest(low, tenkan_period)) / 2
kijun_sen = (ta.highest(high, kijun_period) + ta.lowest(low, kijun_period)) / 2
senkou_span_a = (tenkan_sen + kijun_sen) / 2
senkou_span_b = (ta.highest(high, senkou_span_b_period) + ta.lowest(low, senkou_span_b_period)) / 2
chikou_span = close
// Signal Conditions
tk_cross_up = ta.crossover(tenkan_sen, kijun_sen)
tk_cross_down = ta.crossunder(tenkan_sen, kijun_sen)
future_senkou_a = senkou_span_a[displacement]
future_senkou_b = senkou_span_b[displacement]
future_cloud_top = math.max(future_senkou_a, future_senkou_b)
future_cloud_bottom = math.min(future_senkou_a, future_senkou_b)
price_above_future_cloud = close > future_cloud_top
price_below_future_cloud = close < future_cloud_bottom
price_inside_future_cloud = close >= future_cloud_bottom and close <= future_cloud_top
future_bullish_cloud = future_senkou_a > future_senkou_b
chikou_above_price = chikou_span > close[displacement]
chikou_below_price = chikou_span < close[displacement]
price_above_kijun = close > kijun_sen
price_below_kijun = close < kijun_sen
strong_buy = tk_cross_up and price_above_future_cloud and future_bullish_cloud and chikou_above_price and price_above_kijun
medium_buy = tk_cross_up and (price_above_future_cloud or price_inside_future_cloud) and tenkan_sen > kijun_sen
strong_sell = tk_cross_down and price_below_future_cloud and not future_bullish_cloud and chikou_below_price and price_below_kijun
medium_sell = tk_cross_down and (price_below_future_cloud or price_inside_future_cloud) and tenkan_sen < kijun_sen
// Plotting Lines
plot(show_tenkan ? tenkan_sen : na, color=color.blue, title="Tenkan Sen", linewidth=2)
plot(show_kijun ? kijun_sen : na, color=color.red, title="Kijun Sen", linewidth=2)
plot(show_chikou ? chikou_span : na, offset=-displacement, color=color.purple, title="Chikou Span", linewidth=1)
// Cloud Plotting
p1 = plot(show_cloud ? senkou_span_a : na, offset=displacement, color=color.green, title="Senkou Span A", display=display.none)
p2 = plot(show_cloud ? senkou_span_b : na, offset=displacement, color=color.red, title="Senkou Span B", display=display.none)
fill(p1, p2, color=senkou_span_a > senkou_span_b ? color.new(color.green, 80) : color.new(color.red, 80), title="Cloud")
// Buy/Sell Signals
if show_signals_on_chart
if strong_buy
label.new(bar_index, low - ta.atr(14) * 0.5, text="BUY++", color=color.green, textcolor=color.white, style=label.style_label_up, size=size.normal)
else if medium_buy and not strong_buy
label.new(bar_index, low - ta.atr(14) * 0.5, text="BUY", color=color.lime, textcolor=color.black, style=label.style_label_up, size=size.small)
if strong_sell
label.new(bar_index, high + ta.atr(14) * 0.5, text="SELL++", color=color.red, textcolor=color.white, style=label.style_label_down, size=size.normal)
else if medium_sell and not strong_sell
label.new(bar_index, high + ta.atr(14) * 0.5, text="SELL", color=color.orange, textcolor=color.black, style=label.style_label_down, size=size.small)
// Background Colors
bgcolor(strong_buy ? color.new(color.green, 90) : na, title="Strong Buy Background")
bgcolor(strong_sell ? color.new(color.red, 90) : na, title="Strong Sell Background")
// Status Label
var label status_info_label = na
if barstate.islast
label.delete(status_info_label)
status_text = ""
current_signal_status = "⚪ NEUTRAL"
current_signal_color = color.gray
if strong_buy
current_signal_status := "🟢 STRONG BUY"
current_signal_color := color.green
else if medium_buy
current_signal_status := "🟢 BUY"
current_signal_color := color.lime
else if strong_sell
current_signal_status := "🔴 STRONG SELL"
current_signal_color := color.red
else if medium_sell
current_signal_status := "🔴 SELL"
current_signal_color := color.orange
status_text := current_signal_status
status_text += "\nTenkan/Kijun: " + (tenkan_sen > kijun_sen ? "Bullish ↑" : "Bearish ↓")
status_text += "\nPrice vs Cloud: " + (price_above_future_cloud ? "Above ↑" : price_below_future_cloud ? "Below ↓" : "Inside ↔")
status_text += "\nCloud: " + (future_bullish_cloud ? "Bullish ☁↑" : "Bearish ☁↓")
status_text += "\nChikou vs Price: " + (chikou_above_price ? "Above ↑" : chikou_below_price ? "Below ↓" : "Neutral/Crossing")
status_text += "\nPrice vs Kijun: " + (price