本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This work is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
// https://creativecommons.org/licenses/by-nc-sa/4.0/
// © BigBeluga
//@version=6
indicator("Momentum Index [BigBeluga]", max_labels_count = 500)
// INPUTS ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{
int len = input.int(20, "Length", minval=1)
int len1 = input.int(100, "Sentiment Length", minval=1)
float src = hlc3
// }
// CALCULATIONS――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{
emaEma(source, length) => ta.ema(ta.ema(source, length), length)
tmi(len) =>
sum = 0.0
sum1 = 0.0
above = 0.0
below = 0.0
src_ = src - src[len]
for i = 0 to len
sum := sum + (src_ > nz(src_[i]) ? 1 : -1)
sum1 := sum1 + (sum[i] > 0 ? 1 : -1)
sum1 := emaEma(sum1, 10)
for i = 1 to len1
above := above + (sum1[i] > 0 ? 1 : 0)
below := below + (sum1[i] > 0 ? 0 : 1)
[sum1, above, below]
[tmi, above, below] = tmi(len)
color tmi_col = tmi > tmi[3] ? color.aqua : tmi < tmi[3] ? color.red : tmi == tmi[3] ? color.orange : na
// }
// PLOT ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{
tmiPlot = plot(tmi, "TMI", color = tmi_col, linewidth = 2)
upper = plot(len, editable = false, display = display.none)
midLinePlot = plot(0, color = color.new(chart.fg_color, 50), editable = false)
lower = plot(-len, editable = false, display = display.none)
fill(tmiPlot, midLinePlot, len, 0, top_color = color.new(color.aqua, 60), bottom_color = color.new(color.aqua, 100), title = "Overbought Gradient Fill")
fill(tmiPlot, midLinePlot, 0, -len, top_color = color.new(color.red, 100), bottom_color = color.new(color.red, 60), title = "Oversold Gradient Fill")
fill(upper, midLinePlot, len, 0, top_color = color.new(chart.fg_color, 80), bottom_color = color(na), title = "Overbought Gradient Fill")
fill(lower, midLinePlot, 0, -len, top_color = color(na), bottom_color = color.new(chart.fg_color, 80), title = "Oversold Gradient Fill")
if ta.crossover(tmi, tmi[3]) and tmi < 0
label.new(bar_index[1], tmi[1], "△", color = color(na), style = label.style_label_up, textcolor = color.aqua)
label.new(bar_index[1], low[1], "△", color = color(na), style = label.style_label_up, textcolor = color.aqua, force_overlay = true)
if ta.crossunder(tmi, tmi[3]) and tmi > 0
label.new(bar_index[1], tmi[1], "▽", color = color(na), style = label.style_label_down, textcolor = color.red)
label.new(bar_index[1], high[1],"▽", color = color(na), style = label.style_label_down, textcolor = color.red, force_overlay = true)
if barstate.islast
var dash = table.new(position.top_right, 10, 10, color.new(chart.fg_color, 70))
dash.cell(0, 0, "Values for Past " + str.tostring(len) + " Bars", text_color = chart.fg_color)
dash.merge_cells(0, 0, 1,0)
dash.cell(0, 1, "Above > 0", text_color = color.aqua)
dash.cell(1, 1, str.tostring(above), text_color = color.aqua)
dash.cell(0, 2, "Below < 0", text_color = color.red)
dash.cell(1, 2, str.tostring(below), text_color = color.red)
// }