本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © SMC-Lab
//@version=6
// Volatility in Pips Dashboard
indicator('Volatility Pips', overlay=true)
// --- Settings ---
pipsTablePosition = input.string(defval='bottom_left', title='Table Position', options=['bottom_left', 'bottom_right', 'top_left', 'top_right'], group="General")
avgPipsPeriod = input.int(defval=5, title='Avg Pips Period (N days)', minval=1, group="General")
avgPipsPeriod2 = input.int(defval=10, title='Avg Pips Period (N days) 2', minval=1, group="General")
avgPipsPeriod3 = input.int(defval=20, title='Avg Pips Period (N days) 3', minval=1, group="General")
// --- Pip Calculation Settings ---
pipCalcMethod = input.string("Auto (Forex)", title="Pip Calculation Method", options=["Auto (Forex)", "Manual Multiplier"], group="Pip Settings")
manualMultiplier = input.float(10.0, title="Manual Multiplier (If Manual)", tooltip="If pips are 10x larger, set to 10. If 10x smaller, set to 0.1", group="Pip Settings")
// --- Color Customization ---
tableBgColor = input.color(defval=color.rgb(240, 240, 240, 10), title='Table Background Color', group="Colors")
textColor = input.color(color.black, title='Base Text Color', group="Colors") // カラーピッカーに修正(デフォルト: 黒)
highVolColor = input.color(color.red, title="High Volatility Color", group="Colors")
lowVolColor = input.color(color.blue, title="Low Volatility Color", group="Colors")
// --- Pip Size Logic ---
float pipSize = syminfo.mintick
if pipCalcMethod == "Auto (Forex)"
if syminfo.type == "forex"
pipSize := str.contains(syminfo.ticker, "JPY") ? 0.01 : 0.0001
else
pipSize := syminfo.mintick
else
pipSize := syminfo.mintick * manualMultiplier
// --- Pips Calculation ---
todayPips = request.security(syminfo.tickerid, "D", (high - low) / pipSize)
prevDayPips = request.security(syminfo.tickerid, "D", (high[1] - low[1]) / pipSize)
avgNPips = request.security(syminfo.tickerid, "D", ta.sma(high - low, avgPipsPeriod) / pipSize)
avgNPips2 = request.security(syminfo.tickerid, "D", ta.sma(high - low, avgPipsPeriod2) / pipSize)
avgNPips3 = request.security(syminfo.tickerid, "D", ta.sma(high - low, avgPipsPeriod3) / pipSize)
thisWeekPips = request.security(syminfo.tickerid, "W", (high - low) / pipSize)
lastWeekPips = request.security(syminfo.tickerid, "W", (high[1] - low[1]) / pipSize)
avgWeeklyPips = request.security(syminfo.tickerid, "W", ta.sma(high - low, avgPipsPeriod) / pipSize)
thisMonthPips = request.security(syminfo.tickerid, "M", (high - low) / pipSize)
lastMonthPips = request.security(syminfo.tickerid, "M", (high[1] - low[1]) / pipSize)
avgMonthlyPips = request.security(syminfo.tickerid, "M", ta.sma(high - low, avgPipsPeriod) / pipSize)
// --- Determine Dynamic Colors (直近の期間と比較) ---
colorToday = todayPips > prevDayPips ? highVolColor : lowVolColor
colorThisWeek = thisWeekPips > lastWeekPips ? highVolColor : lowVolColor
colorThisMonth = thisMonthPips > lastMonthPips ? highVolColor : lowVolColor
// --- Table Creation and Update ---
var table pipsTable = table.new(pipsTablePosition, 2, 9, border_width = 1, border_color=color.gray)
if bar_index == 0
table.cell(pipsTable, 0, 0, 'Today', bgcolor=tableBgColor, text_color=textColor)
table.cell(pipsTable, 0, 1, 'Prev Day', bgcolor=tableBgColor, text_color=textColor)
table.cell(pipsTable, 0, 2, 'Avg ' + str.tostring(avgPipsPeriod) + ' Day', bgcolor=tableBgColor, text_color=textColor)
table.cell(pipsTable, 0, 3, 'Avg ' + str.tostring(avgPipsPeriod2) + ' Day', bgcolor=tableBgColor, text_color=textColor)
table.cell(pipsTable, 0, 4, 'Avg ' + str.tostring(avgPipsPeriod3) + ' Day', bgcolor=tableBgColor, text_color=textColor)
table.cell(pipsTable, 0, 5, 'This Week', bgcolor=tableBgColor, text_color=textColor)
table.cell(pipsTable, 0, 6, 'Last Week', bgcolor=tableBgColor, text_color=textColor)
table.cell(pipsTable, 0, 7, 'This Month', bgcolor=tableBgColor, text_color=textColor)
table.cell(pipsTable, 0, 8, 'Last Month', bgcolor=tableBgColor, text_color=textColor)
table.cell(pipsTable, 1, 0, str.tostring(todayPips, '#.##'), text_color=colorToday, bgcolor=tableBgColor)
table.cell(pipsTable, 1, 1, str.tostring(prevDayPips, '#.##'), text_color=textColor, bgcolor=tableBgColor)
table.cell(pipsTable, 1, 2, str.tostring(avgNPips, '#.##'), text_color=textColor, bgcolor=tableBgColor)
table.cell(pipsTable, 1, 3, str.tostring(avgNPips2, '#.##'), text_color=textColor, bgcolor=tableBgColor)
table.cell(pipsTable, 1, 4, str.tostring(avgNPips3, '#.##'), text_color=textColor, bgcolor=tableBgColor)
table.cell(pipsTable, 1, 5, str.tostring(thisWeekPips, '#.##'), text_color=colorThisWeek, bgcolor=tableBgColor)
table.cell(pipsTable, 1, 6, str.tostring(lastWeekPips, '#.##'), text_color=textColor, bgcolor=tableBgColor)
table.cell(pipsTable, 1, 7, str.tostring(thisMonthPips, '#.##'), text_color=colorThisMonth, bgcolor=tableBgColor)
table.cell(pipsTable, 1, 8, str.tostring(lastMonthPips, '#.##'), text_color=textColor, bgcolor=tableBgColor)