admin管理员组文章数量:1405904
I'm not sure why but when I display a different ticker's value on chart the values don't seem to be correct. To test this I have displayed the input ticker over the current chart but that input ticker is just the same chart. It has the same behaviour if you display it over a different chart.
here is the code, but for some reason its grabbing a weird number for the close. The open seems to be correct.
I'm only really interested in getting ES (CME_MINI:ES!) and NQ (CME_MINI:NQ!) values. Even if you specify the contract it also doesn't seem to give the correct value.
indicator("Daily Open and Previous Close Levels with Custom Ticker", overlay=true)
// Input for custom ticker
custom_ticker = input.symbol("", "Custom Ticker (leave blank for current symbol)", group="Symbol")
// Use the specified ticker or the current symbol if blank
ticker_to_use = custom_ticker == "" ? syminfo.tickerid : custom_ticker
// Get the daily timeframe values
[daily_open, daily_high, daily_low, daily_close] = request.security(ticker_to_use, "D", [open, high, low, close], lookahead=barmerge.lookahead_on)
// Get the previous day's close
prev_day_close = request.security(ticker_to_use, "D", close[1], lookahead=barmerge.lookahead_on)
// Colors
daily_open_color = input.color(color.blue, "Daily Open Color", group="Colors")
prev_close_color = input.color(color.red, "Previous Day Close Color", group="Colors")
// Line width
line_width = input.int(1, "Line Width", minval=1, maxval=4, group="Settings")
// Display options
show_daily_open = input.bool(true, "Show Daily Open", group="Display")
show_prev_close = input.bool(true, "Show Previous Day Close", group="Display")
show_labels = input.bool(true, "Show Labels", group="Display")
// Show indicator info
show_ticker_info = input.bool(true, "Show Ticker Name on Labels", group="Display")
// Reset lines on new day
var daily_open_line = line.new(na, na, na, na, width=line_width, color=daily_open_color, extend=extend.right)
var prev_close_line = line.new(na, na, na, na, width=line_width, color=prev_close_color, extend=extend.right)
// Reset labels on new day
var daily_open_label = label.new(na, na, "", style=label.style_label_left, color=color.new(color.white, 100), textcolor=daily_open_color)
var prev_close_label = label.new(na, na, "", style=label.style_label_left, color=color.new(color.white, 100), textcolor=prev_close_color)
// Check if it's a new day
is_new_day = ta.change(time("D"))
if is_new_day
// Update the daily open line
if show_daily_open
line.set_xy1(daily_open_line, bar_index, daily_open)
line.set_xy2(daily_open_line, bar_index + 1, daily_open)
if show_labels
label.set_xy(daily_open_label, bar_index, daily_open)
ticker_prefix = show_ticker_info and custom_ticker != "" ? custom_ticker + " " : ""
label.set_text(daily_open_label, ticker_prefix + "Daily Open: " + str.tostring(daily_open, format.price))
// Update the previous day close line
if show_prev_close
line.set_xy1(prev_close_line, bar_index, prev_day_close)
line.set_xy2(prev_close_line, bar_index + 1, prev_day_close)
if show_labels
label.set_xy(prev_close_label, bar_index, prev_day_close)
ticker_prefix = show_ticker_info and custom_ticker != "" ? custom_ticker + " " : ""
label.set_text(prev_close_label, ticker_prefix + "Prev Close: " + str.tostring(prev_day_close, format.price))
// Plot the levels for debugging (can be hidden)
plot(show_daily_open ? daily_open : na, "Daily Open", color=daily_open_color, style=plot.style_circles, display=display.none)
plot(show_prev_close ? prev_day_close : na, "Previous Day Close", color=prev_close_color, style=plot.style_circles, display=display.none)``
本文标签:
版权声明:本文标题:pine script v5 - Displaying a different ticker's value on current chart - values not matching or error - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744942482a2633574.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论