ソースコード
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Portfolio Sample - Multi Condition Signal Dashboard
//@version=6
indicator("Multi Condition Signal [複合条件ダッシュボード]", overlay=true)
// ===== 入力パラメータ =====
// MA設定
ma_fast_len = input.int(20, "短期MA", minval=1, group="移動平均")
ma_slow_len = input.int(50, "長期MA", minval=1, group="移動平均")
// RSI設定
rsi_len = input.int(14, "RSI期間", minval=1, group="RSI")
rsi_ob = input.int(70, "買われすぎ", group="RSI")
rsi_os = input.int(30, "売られすぎ", group="RSI")
// MACD設定
macd_fast = input.int(12, "MACD Fast", minval=1, group="MACD")
macd_slow = input.int(26, "MACD Slow", minval=1, group="MACD")
macd_signal = input.int(9, "MACD Signal",minval=1, group="MACD")
// 出来高設定
vol_ma_len = input.int(20, "出来高MA期間", minval=1, group="出来高")
vol_mult = input.float(1.5, "出来高倍率", minval=1.0, step=0.1, group="出来高")
// ===== 各指標の計算 =====
// MA
ma_fast = ta.ema(close, ma_fast_len)
ma_slow = ta.ema(close, ma_slow_len)
// RSI
rsi = ta.rsi(close, rsi_len)
// MACD
[macd_line, signal_line, hist] = ta.macd(close, macd_fast, macd_slow, macd_signal)
// 出来高
vol_ma = ta.sma(volume, vol_ma_len)
vol_spike = volume > vol_ma * vol_mult
// ===== 個別条件の判定 =====
// 買い条件
cond_ma_bull = ma_fast > ma_slow // MA: 短期 > 長期
cond_rsi_bull = rsi > 50 and rsi < rsi_ob // RSI: 50以上 & 買われすぎ未満
cond_macd_bull = hist > 0 // MACD: ヒストグラムがプラス
cond_vol_bull = vol_spike // 出来高: MA×倍率を超過
// 売り条件
cond_ma_bear = ma_fast < ma_slow
cond_rsi_bear = rsi < 50 and rsi > rsi_os
cond_macd_bear = hist < 0
cond_vol_bear = vol_spike
// ===== スコアリング(0-4点) =====
bull_score = (cond_ma_bull ? 1 : 0) + (cond_rsi_bull ? 1 : 0) + (cond_macd_bull ? 1 : 0) + (cond_vol_bull ? 1 : 0)
bear_score = (cond_ma_bear ? 1 : 0) + (cond_rsi_bear ? 1 : 0) + (cond_macd_bear ? 1 : 0) + (cond_vol_bear ? 1 : 0)
// ===== 複合シグナル(3条件以上一致で発動) =====
strong_buy = bull_score >= 3 and bull_score > bull_score[1]
strong_sell = bear_score >= 3 and bear_score > bear_score[1]
// ===== MA描画 =====
plot(ma_fast, "短期EMA", color.new(#2962FF, 20), 2)
plot(ma_slow, "長期EMA", color.new(#FF6D00, 20), 2)
// ===== シグナル描画 =====
plotshape(strong_buy, "強い買い", shape.labelup, location.belowbar, color.new(#2962FF, 0), text="BUY", textcolor=color.white, size=size.small)
plotshape(strong_sell, "強い売り", shape.labeldown, location.abovebar, color.new(#E91E63, 0), text="SELL", textcolor=color.white, size=size.small)
// ===== 出来高スパイク表示 =====
barcolor(vol_spike ? (close > open ? color.new(#2962FF, 50) : color.new(#E91E63, 50)) : na)
// ===== アラート =====
alertcondition(strong_buy, "複合買いシグナル", "BUY: 3条件以上が買い方向で一致")
alertcondition(strong_sell, "複合売りシグナル", "SELL: 3条件以上が売り方向で一致")
// ===== ダッシュボードテーブル =====
var table dash = table.new(position.top_right, 3, 6, bgcolor=color.new(#1E293B, 5), border_width=1, border_color=color.new(#475569, 50))
f_check(cond) => cond ? "✓" : "—"
f_color(cond, is_bull) => cond ? (is_bull ? color.new(#2962FF, 0) : color.new(#E91E63, 0)) : color.gray
if barstate.islast
// ヘッダー
table.cell(dash, 0, 0, "条件", text_color=color.white, text_size=size.tiny, bgcolor=color.new(#334155, 0))
table.cell(dash, 1, 0, "BULL", text_color=color.white, text_size=size.tiny, bgcolor=color.new(#2962FF, 0))
table.cell(dash, 2, 0, "BEAR", text_color=color.white, text_size=size.tiny, bgcolor=color.new(#E91E63, 0))
// MA
table.cell(dash, 0, 1, "MA", text_color=color.white, text_size=size.tiny)
table.cell(dash, 1, 1, f_check(cond_ma_bull), text_color=f_color(cond_ma_bull, true), text_size=size.tiny)
table.cell(dash, 2, 1, f_check(cond_ma_bear), text_color=f_color(cond_ma_bear, false), text_size=size.tiny)
// RSI
table.cell(dash, 0, 2, "RSI " + str.tostring(rsi, "#"), text_color=color.white, text_size=size.tiny)
table.cell(dash, 1, 2, f_check(cond_rsi_bull), text_color=f_color(cond_rsi_bull, true), text_size=size.tiny)
table.cell(dash, 2, 2, f_check(cond_rsi_bear), text_color=f_color(cond_rsi_bear, false), text_size=size.tiny)
// MACD
table.cell(dash, 0, 3, "MACD", text_color=color.white, text_size=size.tiny)
table.cell(dash, 1, 3, f_check(cond_macd_bull), text_color=f_color(cond_macd_bull, true), text_size=size.tiny)
table.cell(dash, 2, 3, f_check(cond_macd_bear), text_color=f_color(cond_macd_bear, false), text_size=size.tiny)
// 出来高
table.cell(dash, 0, 4, "VOL", text_color=color.white, text_size=size.tiny)
table.cell(dash, 1, 4, f_check(cond_vol_bull), text_color=f_color(cond_vol_bull, true), text_size=size.tiny)
table.cell(dash, 2, 4, f_check(cond_vol_bear), text_color=f_color(cond_vol_bear, false), text_size=size.tiny)
// スコア
table.cell(dash, 0, 5, "SCORE", text_color=color.white, text_size=size.tiny, bgcolor=color.new(#334155, 0))
table.cell(dash, 1, 5, str.tostring(bull_score) + "/4", text_color=color.new(#2962FF, 0), text_size=size.small, bgcolor=color.new(#334155, 0))
table.cell(dash, 2, 5, str.tostring(bear_score) + "/4", text_color=color.new(#E91E63, 0), text_size=size.small, bgcolor=color.new(#334155, 0))