本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("MRB - Monthly Range Breakout ", shorttitle="MRB", overlay=true, max_lines_count=500)
// ─────────────────────────────────────────────────────────────
// USER SETTINGS
// ─────────────────────────────────────────────────────────────
// Previous Month High
groupHigh = "Previous Month High"
highColor = input.color(color.lime, "Color", group=groupHigh)
highWidth = input.int(2, "Line Thickness", minval=1, maxval=5, group=groupHigh)
highStyleInput = input.string("Dashed", "Line Style", options=["Solid", "Dashed", "Dotted"], group=groupHigh)
highStyle = highStyleInput == "Solid" ? line.style_solid : highStyleInput == "Dashed" ? line.style_dashed : line.style_dotted
// Previous Month Midpoint
groupMid = "Previous Month Midpoint"
midColor = input.color(color.white, "Color", group=groupMid)
midWidth = input.int(2, "Line Thickness", minval=1, maxval=5, group=groupMid)
midStyleInput = input.string("Dashed", "Line Style", options=["Solid", "Dashed", "Dotted"], group=groupMid)
midStyle = midStyleInput == "Solid" ? line.style_solid : midStyleInput == "Dashed" ? line.style_dashed : line.style_dotted
// Previous Month Low
groupLow = "Previous Month Low"
lowColor = input.color(color.fuchsia, "Color", group=groupLow)
lowWidth = input.int(2, "Line Thickness", minval=1, maxval=5, group=groupLow)
lowStyleInput = input.string("Dashed", "Line Style", options=["Solid", "Dashed", "Dotted"], group=groupLow)
lowStyle = lowStyleInput == "Solid" ? line.style_solid : lowStyleInput == "Dashed" ? line.style_dashed : line.style_dotted
// Price Scale Markers
groupMarkers = "Price Scale Markers"
showPriceMarkers = input.bool(true, "Show High / Mid / Low Price Markers", group=groupMarkers)
// Month Divider Lines
groupMonth = "Month Divider Lines"
showMonthLines = input.bool(true, "Show Month Divider Lines", group=groupMonth)
monthLineColor = input.color(color.gray, "Color", group=groupMonth)
monthLineWidth = input.int(1, "Line Thickness", minval=1, maxval=5, group=groupMonth)
monthLineStyleInput = input.string("Dotted", "Line Style", options=["Solid", "Dashed", "Dotted"], group=groupMonth)
monthLineStyle = monthLineStyleInput == "Solid" ? line.style_solid : monthLineStyleInput == "Dashed" ? line.style_dashed : line.style_dotted
// ─────────────────────────────────────────────────────────────
// PREVIOUS MONTH DATA
// ─────────────────────────────────────────────────────────────
prevMonthHigh = request.security(
syminfo.tickerid,
"1M",
high[1],
gaps=barmerge.gaps_off,
lookahead=barmerge.lookahead_on)
prevMonthLow = request.security(
syminfo.tickerid,
"1M",
low[1],
gaps=barmerge.gaps_off,
lookahead=barmerge.lookahead_on)
prevMonthMid = (prevMonthHigh + prevMonthLow) / 2.0
// Current calendar month timestamps.
currentMonthStart = time("1M")
currentMonthEnd = time_close("1M")
isNewMonth = timeframe.change("1M")
drawMonth = isNewMonth or barstate.isfirst
// ─────────────────────────────────────────────────────────────
// PRICE SCALE MARKERS
// These plots are shown ONLY on the price scale.
// They do not draw extra horizontal lines on the chart.
// ─────────────────────────────────────────────────────────────
plot(
showPriceMarkers ? prevMonthHigh : na,
title="MRB High",
color=highColor,
display=display.price_scale)
plot(
showPriceMarkers ? prevMonthMid : na,
title="MRB Midpoint",
color=midColor,
display=display.price_scale)
plot(
showPriceMarkers ? prevMonthLow : na,
title="MRB Low",
color=lowColor,
display=display.price_scale)
// ─────────────────────────────────────────────────────────────
// DRAW MONTH DIVIDER
// ─────────────────────────────────────────────────────────────
if drawMonth and showMonthLines
line.new(
x1=currentMonthStart,
y1=low,
x2=currentMonthStart,
y2=high,
xloc=xloc.bar_time,
extend=extend.both,
color=monthLineColor,
width=monthLineWidth,
style=monthLineStyle)
// ─────────────────────────────────────────────────────────────
// DRAW PREVIOUS MONTH HIGH / MID / LOW
// ─────────────────────────────────────────────────────────────
if drawMonth and not na(prevMonthHigh) and not na(prevMonthLow)
line.new(
x1=currentMonthStart,
y1=prevMonthHigh,
x2=currentMonthEnd,
y2=prevMonthHigh,
xloc=xloc.bar_time,
extend=extend.none,
color=highColor,
width=highWidth,
style=highStyle)
line.new(
x1=currentMonthStart,
y1=prevMonthMid,
x2=currentMonthEnd,
y2=prevMonthMid,
xloc=xloc.bar_time,
extend=extend.none,
color=midColor,
width=midWidth,
style=midStyle)
line.new(
x1=currentMonthStart,
y1=prevMonthLow,
x2=currentMonthEnd,
y2=prevMonthLow,
xloc=xloc.bar_time,
extend=extend.none,
color=lowColor,
width=lowWidth,
style=lowStyle)