本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("Put/Call Share", overlay = true)
// ===== Inputs =====
serie = input.string("PCC - Total (equity + index)", "Put/Call series", options = ["PCC - Total (equity + index)", "PCCE - Equity options", "PCCI - Index options"])
useLast = input.bool(false, "Use last closed day (stable value)")
pos = input.string("Top right", "Position", options = ["Top right", "Bottom right", "Top left", "Bottom left"])
txtSz = input.string("Large", "Text size", options = ["Normal", "Large", "Huge"])
totalW = input.float(28.0, "Bar width (% of chart)", minval = 15.0, maxval = 60.0)
totHi = input.float(1.0, "PCC: puts dominant above", group = "Thresholds (approximate, editable)")
totLo = input.float(0.7, "PCC: calls dominant below", group = "Thresholds (approximate, editable)")
eqHi = input.float(0.8, "PCCE: puts dominant above", group = "Thresholds (approximate, editable)")
eqLo = input.float(0.55, "PCCE: calls dominant below", group = "Thresholds (approximate, editable)")
ixHi = input.float(1.2, "PCCI: puts dominant above", group = "Thresholds (approximate, editable)")
ixLo = input.float(0.9, "PCCI: calls dominant below", group = "Thresholds (approximate, editable)")
// ===== Verified tickers only =====
sym = switch serie
"PCC - Total (equity + index)" => "USI:PCC"
"PCCE - Equity options" => "USI:PCCE"
=> "USI:PCCI"
hiLvl = switch serie
"PCC - Total (equity + index)" => totHi
"PCCE - Equity options" => eqHi
=> ixHi
loLvl = switch serie
"PCC - Total (equity + index)" => totLo
"PCCE - Equity options" => eqLo
=> ixLo
// ===== Data =====
[pc, dataTime] = request.security(sym, "D", [useLast ? close[1] : close, time], ignore_invalid_symbol = true)
// ===== Style =====
tblPos = switch pos
"Top right" => position.top_right
"Bottom right" => position.bottom_right
"Top left" => position.top_left
=> position.bottom_left
sz = switch txtSz
"Normal" => size.normal
"Huge" => size.huge
=> size.large
putCol = color.new(color.red, 10)
callCol = color.new(color.teal, 10)
darkBg = color.new(color.black, 15)
var t = table.new(tblPos, 2, 4, frame_color = color.white, frame_width = 2)
if barstate.islast
if na(pc) or pc <= 0 or pc > 5
table.cell(t, 0, 0, "No valid data for " + sym, text_color = color.white, text_size = sz, bgcolor = darkBg)
table.merge_cells(t, 0, 0, 1, 0)
else
putShare = pc / (1 + pc)
callShare = 1 / (1 + pc)
// minimum 20% width per segment so the text is never cut off
putW = totalW * math.max(0.2, math.min(0.8, putShare))
callW = totalW - putW
// Header
table.cell(t, 0, 0, "PUT", text_color = color.white, text_size = sz, text_formatting = text.format_bold, bgcolor = darkBg, width = putW)
table.cell(t, 1, 0, "CALL", text_color = color.white, text_size = sz, text_formatting = text.format_bold, bgcolor = darkBg, width = callW)
// Proportional bar
table.cell(t, 0, 1, str.tostring(putShare * 100, "0.0") + "%", text_color = color.white, text_size = sz, text_formatting = text.format_bold, bgcolor = putCol, width = putW, height = 5)
table.cell(t, 1, 1, str.tostring(callShare * 100, "0.0") + "%", text_color = color.white, text_size = sz, text_formatting = text.format_bold, bgcolor = callCol, width = callW, height = 5)
// Ratio and sentiment
mood = pc > hiLvl ? "Puts dominant" : pc < loLvl ? "Calls dominant" : "Balanced"
moodCol = pc > hiLvl ? color.red : pc < loLvl ? color.teal : color.yellow
table.cell(t, 0, 2, "Ratio " + str.tostring(pc, "0.00") + " | " + mood, text_color = moodCol, text_size = sz, text_formatting = text.format_bold, bgcolor = darkBg)
table.merge_cells(t, 0, 2, 1, 2)
// Source and data date
table.cell(t, 0, 3, "Source: " + sym + " | Date: " + str.format_time(dataTime, "yyyy-MM-dd", "UTC"), text_color = color.silver, text_size = size.small, bgcolor = darkBg)
table.merge_cells(t, 0, 3, 1, 3)