MHIDa Multi-Signal Confluence Scorer

MHIDa · study · 195 行 · 点赞 7 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=6
// ============================================================================
// Multi-Signal Confluence Scorer
// A context aid for what you observe, NOT a signal nor advice,
// not a standalone winner. You always decide.
// ----------------------------------------------------------------------------
// WHAT IT DOES (in plain words):
//   It lets you TURN ON the signals you care about (RSI, stretch from the
//   moving average, volume, trend) and shows you a CONFLUENCE SCORE: how many
//   of the conditions you enabled are true TOGETHER right now. Build your own
//   combination and watch how many lights are on at the same time.
//
//   Example: enable RSI, Volume and Trend. If RSI and Trend are true now but
//   Volume is not, the score is 2 out of 3. A panel shows it row by row, and
//   the background tints when you cross the threshold you set.
//
// WHY "confluence" (the scoring idea):
//   A single signal, on its own, says little. The idea here is only to COUNT
//   how many things you consider relevant happen at the same moment, to give
//   you a quick read on context. NOTHING more.
//
// HONESTY (mandatory framing):
//   This is NOT a standalone winning tool - and it does not become one by
//   "stacking" signals. These conditions, alone or piled together, are not
//   enough to beat the market. It is an AID to read what you already have in
//   front of you on the chart, not a rule that decides for you. A high score
//   is NOT a "buy/sell". No promises, no performance numbers (that would be
//   inventing them). You always decide.
//
//   METHOD NOTE: the signals here are CORRELATED with each other (high RSI and
//   stretch from the average often light up together). So "3 out of 4" does
//   NOT count as 3 independent pieces of evidence: it is the same phenomenon
//   seen from different angles. Read it that way.
//
// GENERIC BUILDER:
//   A "fill-in-the-blank" tool built with the classic honest method: every
//   building block (RSI, stretch, volume, trend) is computed in a standard,
//   CAUSAL way (only bars up to now). The defaults below are JUST a starting
//   point - change them.
// ============================================================================
 
indicator("MHIDa Multi-Signal Confluence Scorer", shorttitle="Confluence", overlay=true, max_labels_count=200)
 
// ---------------------------------------------------------------------------
// INPUT - turn signals on/off and tune thresholds (defaults = starting point)
// ---------------------------------------------------------------------------
grpEn = "1) Which signals to count (turn on yours)"
useRsi = input.bool(true,  "RSI in chosen zone", group=grpEn,
     tooltip="Counts when RSI is inside the zone you set below.")
useStr = input.bool(true,  "Stretch from the average (distance from the EMA)", group=grpEn,
     tooltip="Counts when price is farther from its average than the threshold.")
useVol = input.bool(true,  "Volume above its average", group=grpEn,
     tooltip="Counts when volume is a multiple of its average.")
useTrn = input.bool(true,  "Trend (price vs slow EMA)", group=grpEn,
     tooltip="Counts when price is on the chosen side of the slow EMA.")
 
grpDir = "Reading direction"
side = input.string("Up side (long)", "Which side you are evaluating",
     options=["Up side (long)", "Down side (short)"], group=grpDir,
     tooltip="Changes only the DIRECTION of the trend/RSI conditions, so you can read context from the side you care about. It is not a position recommendation.")
isLong = side == "Up side (long)"
 
grpRsi = "2) RSI"
rsiLen   = input.int(14, "RSI period", minval=2, group=grpRsi)
rsiHiLvl = input.float(70, "RSI: 'high' threshold", group=grpRsi,
     tooltip="On the long side: counts RSI >= this value.")
rsiLoLvl = input.float(30, "RSI: 'low' threshold", group=grpRsi,
     tooltip="Used on the short side: counts when RSI <= this value.")
 
grpStr = "3) Stretch from the average"
strEmaLen = input.int(20, "Reference EMA for the stretch", minval=2, group=grpStr)
strPct    = input.float(3.0, "Minimum distance from the EMA (%)", minval=0.0, step=0.1, group=grpStr,
     tooltip="Counts when |price - EMA| / EMA * 100 exceeds this percentage.")
 
grpVol = "4) Volume"
volLen  = input.int(20, "Volume average (bars)", minval=2, group=grpVol)
volMult = input.float(1.5, "Multiple above the average", minval=0.1, step=0.1, group=grpVol,
     tooltip="Counts when volume >= volume_average * this multiple.")
 
grpTrn = "5) Trend"
trnEmaLen = input.int(50, "Slow EMA (trend)", minval=2, group=grpTrn)
 
grpScore = "6) Score"
minScore = input.int(2, "Minimum confluence to highlight", minval=1, maxval=4, group=grpScore,
     tooltip="Below this threshold the background stays off. The max possible score = number of enabled signals.")
 
grpView = "7) Appearance"
showBg  = input.bool(true, "Background when confluence >= minimum", group=grpView)
showLbl = input.bool(true, "Label with the score when it triggers", group=grpView)
showTbl = input.bool(true, "Status panel top-right", group=grpView)
 
// ---------------------------------------------------------------------------
// BUILDING BLOCKS (all causal, classic honest method)
// ---------------------------------------------------------------------------
// --- RSI ---
rsiVal = ta.rsi(close, rsiLen)
rsiCond = isLong ? (rsiVal >= rsiHiLvl) : (rsiVal <= rsiLoLvl)
 
// --- Stretch from the average (% distance from the EMA) ---
strEma  = ta.ema(close, strEmaLen)
strDist = strEma != 0 ? math.abs(close - strEma) / strEma * 100.0 : na
// on the long side the "relevant" stretch is above the average; on the short side below.
strSideOk = isLong ? (close > strEma) : (close < strEma)
strCond = not na(strDist) and strDist >= strPct and strSideOk
 
// --- Volume above its average ---
volMa   = ta.sma(volume, volLen)
volCond = not na(volMa) and volMa > 0 and volume >= volMa * volMult
 
// --- Trend (price vs slow EMA) ---
trnEma  = ta.ema(close, trnEmaLen)
trnCond = isLong ? (close > trnEma) : (close < trnEma)
 
// ---------------------------------------------------------------------------
// CONFLUENCE SCORE
//   = how many ENABLED conditions are true right now.
//   We count both the score (enabled & true) and the max possible
//   (how many you enabled), so you read "2/3" and not a number without a scale.
// ---------------------------------------------------------------------------
sRsi = useRsi and rsiCond ? 1 : 0
sStr = useStr and strCond ? 1 : 0
sVol = useVol and volCond ? 1 : 0
sTrn = useTrn and trnCond ? 1 : 0
score = sRsi + sStr + sVol + sTrn
 
nOn = (useRsi ? 1 : 0) + (useStr ? 1 : 0) + (useVol ? 1 : 0) + (useTrn ? 1 : 0)
// the effective threshold cannot exceed the enabled signals
minEff = math.min(minScore, math.max(nOn, 1))
fire = nOn > 0 and score >= minEff
 
// ---------------------------------------------------------------------------
// DRAWING - context highlighting only, no orders
// ---------------------------------------------------------------------------
// color intensity: more lights on together = more loaded
color bgCol = na
if fire
    frac = nOn > 0 ? float(score) / nOn : 0.0
    baseC = isLong ? color.teal : color.orange
    transp = frac >= 1.0 ? 75 : frac >= 0.66 ? 82 : 88
    bgCol := color.new(baseC, transp)
bgcolor(showBg ? bgCol : na, title="Confluence")
 
if showLbl and fire and chart.is_standard
    txt = "confluence: " + str.tostring(score) + "/" + str.tostring(nOn) + "\n" +
          (sRsi == 1 ? "RSI " : "") +
          (sStr == 1 ? "Stretch " : "") +
          (sVol == 1 ? "Vol " : "") +
          (sTrn == 1 ? "Trend" : "")
    lblY   = isLong ? yloc.belowbar : yloc.abovebar
    lblSty = isLong ? label.style_label_up : label.style_label_down
    lblC   = isLong ? color.new(color.teal, 15) : color.new(color.orange, 15)
    label.new(bar_index, isLong ? low : high, txt, yloc=lblY, style=lblSty,
              color=lblC, textcolor=color.white, size=size.small)
 
// discreet marker
plotshape(fire and chart.is_standard, title="confluence",
          style=isLong ? shape.triangleup : shape.triangledown,
          location=isLong ? location.belowbar : location.abovebar,
          color=isLong ? color.teal : color.orange, size=size.tiny)
 
// ---------------------------------------------------------------------------
// STATUS PANEL (quick row-by-row read, no advice)
// ---------------------------------------------------------------------------
f_cellState(bool on, bool cond) =>
    on ? (cond ? "YES" : "-") : "off"
f_cellCol(bool on, bool cond) =>
    not on ? color.new(color.gray, 40) : (cond ? color.lime : color.gray)
 
var table t = table.new(position.top_right, 2, 6, border_width=1)
if showTbl and barstate.islast
    hdr = color.new(color.gray, 0)
    table.cell(t, 0, 0, "MHIDa Confluence", text_color=color.white, bgcolor=hdr, text_size=size.small)
    table.cell(t, 1, 0, isLong ? "long side" : "short side", text_color=color.white, bgcolor=hdr, text_size=size.small)
 
    table.cell(t, 0, 1, "RSI", text_color=color.white, text_size=size.small)
    table.cell(t, 1, 1, f_cellState(useRsi, rsiCond), text_color=f_cellCol(useRsi, rsiCond), text_size=size.small)
 
    table.cell(t, 0, 2, "Stretch", text_color=color.white, text_size=size.small)
    table.cell(t, 1, 2, f_cellState(useStr, strCond), text_color=f_cellCol(useStr, strCond), text_size=size.small)
 
    table.cell(t, 0, 3, "Volume", text_color=color.white, text_size=size.small)
    table.cell(t, 1, 3, f_cellState(useVol, volCond), text_color=f_cellCol(useVol, volCond), text_size=size.small)
 
    table.cell(t, 0, 4, "Trend", text_color=color.white, text_size=size.small)
    table.cell(t, 1, 4, f_cellState(useTrn, trnCond), text_color=f_cellCol(useTrn, trnCond), text_size=size.small)
 
    table.cell(t, 0, 5, "confluence", text_color=color.white, text_size=size.small)
    table.cell(t, 1, 5, str.tostring(score) + "/" + str.tostring(nOn),
         text_color=fire ? (isLong ? color.teal : color.orange) : color.gray, text_size=size.small)
 
// ---------------------------------------------------------------------------
// OPTIONAL ALERT (you arm it; it stays a context notice, not an order)
// ---------------------------------------------------------------------------
alertcondition(fire, title="Confluence threshold reached",
     message="MHIDa Confluence Scorer: your combination reached the minimum confluence. It is an aid to evaluate what you observe, not a signal. Look at the chart and decide for yourself.")

← 返回列表