Market Structure by The Noiseless Trader

kaushikakiwatkar · study · 48 行 · 点赞 124 · TradingView 原页

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

Pine Script

//@version=6
indicator("Market Structure by The Noiseless Trader", overlay=true)
 
// ===== Inputs =====
showLabels        = input.bool(true,  "Show labels")
paintBars         = input.bool(true,  "Paint signal bar")
labelSizeInp      = input.string("Small", "Label size", options=["Tiny","Small","Normal","Large"])
minBodyPct        = input.float(2.0, "Min body (%) on Candle 0", step=0.1, minval=0.0)   // default 2%
labelOffsetPct    = input.float(1.0, "Label offset (%)", step=0.1, minval=0.0)           // default 1%
confirmCloseOnly  = input.bool(true, "Confirm on bar close only (avoid repaint)")
 
// ===== Label size map =====
ls = switch labelSizeInp
    "Tiny"   => size.tiny
    "Small"  => size.small
    "Normal" => size.normal
    => size.large
 
// ===== Helpers =====
isBull(i) => close[i] > open[i]
isBear(i) => close[i] < open[i]
 
// Candle 0 body % (relative to close)
bodyPct0 = math.abs(close - open) / close * 100.0
bodyOK   = bodyPct0 >= minBodyPct
 
// ===== Patterns =====
raw_msl = bar_index >= 2 and isBear(2) and isBear(1) and (close[1] < close[2]) and isBull(0) and (close > open[1]) and bodyOK
raw_msh = bar_index >= 2 and isBull(2) and isBull(1) and (close[1] > close[2]) and isBear(0) and (close < open[1]) and bodyOK
 
confirmed = not confirmCloseOnly or barstate.isconfirmed
msl = raw_msl and confirmed
msh = raw_msh and confirmed
 
// ===== Visuals =====
barcolor(paintBars ? (msl ? color.new(color.lime, 0) : msh ? color.new(color.red, 0) : na) : na)
 
// Keep labels away from candle 0
offsetValue = close * labelOffsetPct / 100.0
 
if showLabels and msl
    label.new(bar_index, low - offsetValue, "MSL", xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_up, color=color.new(color.lime, 0), textcolor=color.black, size=ls)
if showLabels and msh
    label.new(bar_index, high + offsetValue, "MSH", xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_down, color=color.new(color.red, 0), textcolor=color.white, size=ls)
 
// ===== Alerts =====
alertcondition(msl, title="MSL (Market Structure Low)",  message="MSL on {{ticker}} {{interval}}")
alertcondition(msh, title="MSH (Market Structure High)", message="MSH on {{ticker}} {{interval}}")

← 返回列表