本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This Pine Script code is subject to the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// Copyright Heard_Floor
//@version=6
indicator("MOVE vs VIX - 1-Year Range Position", shorttitle="MOVE-VIX Range", overlay=false, precision=2)
// Range position, not statistical percentile rank. Use a standard 1D chart.
// Add three copies and select MOVE, VIX, and Difference for three aligned panes.
string panel = input.string("Difference", "Panel", options=["MOVE", "VIX", "Difference"], group="Display")
bool fractionScale = input.bool(true, "Use 0-1 scale", group="Display")
bool showTable = input.bool(true, "Show table when Panel is Difference", group="Display")
bool highlightCrossings = input.bool(true, "Mark upward threshold crossings on the price chart", group="Display")
string moveSymbol = input.symbol("TVC:MOVE", "MOVE symbol", group="Calculation")
string vixSymbol = input.symbol("CBOE:VIX", "VIX symbol", group="Calculation")
int length = input.int(252, "Daily closes in window", minval=2, maxval=1250, group="Calculation")
float threshold = input.float(60.0, "Difference threshold (percentage points)", minval=0, maxval=100, step=1, group="Calculation")
color moveColor = input.color(color.rgb(160, 160, 160), "MOVE line", group="Colors")
color vixColor = chart.fg_color
color positiveColor = input.color(color.rgb(34, 139, 65), "Positive difference", group="Colors")
color negativeColor = input.color(color.rgb(180, 45, 45), "Negative difference", group="Colors")
if not chart.is_standard or not timeframe.isdaily or timeframe.multiplier != 1
runtime.error("Use a standard 1D chart (line, bars, or candles). This indicator compares daily closes.")
// This function executes inside each index's DAILY context.
// Window includes the current daily close and the preceding length - 1 closes.
// Intraday highs/lows are deliberately not used.
dailyStats() =>
float lowestClose = ta.lowest(close, length)
float highestClose = ta.highest(close, length)
float validCloses = math.sum(na(close) ? 0.0 : 1.0, length)
bool fullWindow = bar_index >= length - 1 and validCloses == length
float span = highestClose - lowestClose
float rangePosition = fullWindow and span > 0 ? 100.0 * (close - lowestClose) / span : na
[rangePosition, time_tradingday, time_close]
[moveRange, moveDay, moveEnd] = request.security(moveSymbol, "1D", dailyStats(), gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_off)
[vixRange, vixDay, vixEnd] = request.security(vixSymbol, "1D", dailyStats(), gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_off)
// Scheduled source closes must have passed at the latest script execution.
// A just-finished session may need a reload if the chart has not updated.
// Never plot a different source date on this chart bar, subtract different dates,
// replace missing values with zero, or carry an old source into a new spread.
bool moveReady = not na(moveRange) and not na(moveEnd) and moveEnd <= timenow and moveDay == time_tradingday
bool vixReady = not na(vixRange) and not na(vixEnd) and vixEnd <= timenow and vixDay == time_tradingday
bool sameDay = not na(moveDay) and not na(vixDay) and moveDay == vixDay
bool matched = moveReady and vixReady and sameDay
float spread = matched ? moveRange - vixRange : na
float divisor = fractionScale ? 100.0 : 1.0
bool differencePanel = panel == "Difference"
plot(panel == "MOVE" and moveReady ? moveRange / divisor : na, "MOVE range position", color=moveColor, linewidth=1, style=plot.style_linebr, display=panel == "MOVE" ? display.all : display.none)
plot(panel == "VIX" and vixReady ? vixRange / divisor : na, "VIX range position", color=vixColor, linewidth=1, style=plot.style_linebr, display=panel == "VIX" ? display.all : display.none)
plot(differencePanel ? spread / divisor : na, "MOVE minus VIX", color=spread >= 0 ? positiveColor : negativeColor, style=plot.style_columns, histbase=0, display=differencePanel ? display.all : display.none)
plot(differencePanel ? spread / divisor : na, "Difference outline", color=chart.fg_color, linewidth=1, style=plot.style_linebr, display=differencePanel ? display.pane : display.none)
hline(0, "Zero", color=color.new(chart.fg_color, 50))
hline(100.0 / divisor, "Range maximum", color=color.new(chart.fg_color, 80), display=differencePanel ? display.none : display.all)
hline(50.0 / divisor, "Range midpoint", color=color.new(chart.fg_color, 85), linestyle=hline.style_dotted, display=differencePanel ? display.none : display.all)
hline(threshold / divisor, "Positive difference threshold", color=color.orange, linestyle=hline.style_solid, display=differencePanel ? display.all : display.none)
// An orange marker means a fresh move ABOVE the threshold, not a forecast.
// Crossing marks require a valid difference on two consecutive chart bars.
bool crossedUp = ta.crossover(spread, threshold)
bgcolor(differencePanel and highlightCrossings and crossedUp ? color.new(color.orange, 35) : na, title="Threshold crossing", force_overlay=true)
// Retain the latest complete matched pair in the table, with its explicit date.
// A developing or missing new session does not silently become a current reading.
var float lastMove = na
var float lastVix = na
var float lastSpread = na
var int lastMatchedDay = na
if matched
lastMove := moveRange
lastVix := vixRange
lastSpread := spread
lastMatchedDay := moveDay
percentText(float value) =>
na(value) ? "N/A" : str.tostring(value, "0.00") + "%"
spreadText(float value) =>
na(value) ? "N/A" : (value > 0 ? "+" : "") + str.tostring(value, "0.00") + " pp"
var table values = table.new(position.top_right, 2, 6, bgcolor=color.new(chart.bg_color, 8), frame_color=color.new(chart.fg_color, 75), frame_width=1, force_overlay=true)
if barstate.islast and differencePanel and showTable
string asOf = na(lastMatchedDay) ? "N/A" : str.format_time(lastMatchedDay, "yyyy-MM-dd", "UTC")
string status = matched ? "Daily closes" : na(lastMatchedDay) ? "Missing history / flat range" : "Last matched daily closes"
table.cell(values, 0, 0, "MOVE range", text_color=chart.fg_color, text_size=size.small)
table.cell(values, 1, 0, percentText(lastMove), text_color=chart.fg_color, text_size=size.small)
table.cell(values, 0, 1, "VIX range", text_color=chart.fg_color, text_size=size.small)
table.cell(values, 1, 1, percentText(lastVix), text_color=chart.fg_color, text_size=size.small)
table.cell(values, 0, 2, "MOVE - VIX", text_color=chart.fg_color, text_size=size.small)
table.cell(values, 1, 2, spreadText(lastSpread), text_color=na(lastSpread) ? chart.fg_color : lastSpread >= 0 ? positiveColor : negativeColor, text_size=size.small)
table.cell(values, 0, 3, "As of", text_color=chart.fg_color, text_size=size.small)
table.cell(values, 1, 3, asOf, text_color=chart.fg_color, text_size=size.small)
table.cell(values, 0, 4, "Window", text_color=chart.fg_color, text_size=size.small)
table.cell(values, 1, 4, str.tostring(length) + " daily closes", text_color=chart.fg_color, text_size=size.small)
table.cell(values, 0, 5, "Status", text_color=chart.fg_color, text_size=size.small)
table.cell(values, 1, 5, status, text_color=chart.fg_color, text_size=size.small)