TradingView pine脚本,我在request.security()函数中发现了一个错误吗?

huangapple go评论60阅读模式
英文:

TradingView pine script, did I find a bug in request.security()?

问题

EDIT: 这是我第一次“发布”脚本。刚刚收到通知说这违反了TOS,脚本不再可访问。

以下是我的脚本:

//@version=5 
indicator("为什么不同")

factor = 3
atrPeriod = 10

// 内置绘图

atr = ta.rma(ta.tr, atrPeriod)
plot(atr, "ATR", color = color.green, style=plot.style_linebr)

// 计算绘图

[s_tr] = request.security(symbol = "SPY", timeframe = timeframe.period, expression = [ta.tr])
s_atr = ta.rma(s_tr, atrPeriod)
plot(s_atr, "ATR", color = color.purple, style=plot.style_line)

EDIT 2: 我一直没有成功地让我的计算工作,所以我想简单地绘制高/低数据。猜猜?它们不同!!为什么?它据说是相同的数据。

以下是我的脚本:

//@version=5
indicator("为什么不同")

plot(high, "高", color = color.blue, style=plot.style_linebr)
plot(low, "低", color = color.blue, style=plot.style_linebr)

[s_hi,s_lo] = request.security(symbol = "SPY", timeframe = timeframe.period, expression = [high, low])
plot(s_hi, "高", color = color.purple, style=plot.style_linebr)
plot(s_lo, "低", color = color.purple, style=plot.style_linebr)

TradingView pine脚本,我在request.security()函数中发现了一个错误吗?

英文:

EDIT: This was the first time I "published" a script. I just got notified that this violated the TOS and the script is no longer accessible.

Here is my script:

//@version=5 
indicator("Why Different")

factor = 3
atrPeriod = 10

// built in plot

atr = ta.rma(ta.tr,atrPeriod)
plot(atr, "ATR", color = color.green, style=plot.style_linebr)

//calculated plot

[s_tr] = request.security(symbol = "SPY", timeframe = timeframe.period, expression = [ta.tr])
s_atr = ta.rma(s_tr, atrPeriod)
plot(s_atr, "ATR", color = color.purple, style=plot.style_line)

EDIT 2: I was having no luck trying to get my CALCULATIONS to work so I thought I would simply plot the high/low data. Guess what? They are different!!! Why? It is supposedly the same data.

//@version=5
indicator("Why Different")

plot(high, "hi", color = color.blue, style=plot.style_linebr)
plot(low, "lo", color = color.blue, style=plot.style_linebr)

[s_hi,s_lo] = request.security(symbol = "SPY", timeframe = timeframe.period, expression = [high, low])
plot(s_hi, "hi", color = color.purple, style=plot.style_linebr)
plot(s_lo, "lo", color = color.purple, style=plot.style_linebr)

TradingView pine脚本,我在request.security()函数中发现了一个错误吗?

答案1

得分: 1

expression 中,你可以使用类似 ta.rma(ta.tr, atrPeriod) 的变量。

类似这样的代码:

s_atr = request.security(symbol = "SPY", timeframe = timeframe.period, expression = ta.rma(ta.tr, atrPeriod))
plot(s_atr, "ATR", color = color.purple, style=plot.style_line)
英文:

In expression you can use a variable like ta.rma(ta.tr,atrPeriod)

Something like that:

s_atr = request.security(symbol = "SPY", timeframe = timeframe.period, expression = ta.rma(ta.tr,atrPeriod))
plot(s_atr, "ATR", color = color.purple, style=plot.style_line)

答案2

得分: 0

Opened a ticket with TradingView. @Gu5tavo71, you were almost right. Upvoted your answer because your comment to your own answer led me to the correct solution. If you tweak your answer to mention the solution I mention here, I will "accept" it.

The "native" chart uses BATS:SPY. When I change request.security() to use BATS:SPY it is now 100% in sync. That is non-intuitive to me. One would think that request.security() would DEFAULT to the same data source as the charts but allow one to choose a different source if needed.

英文:

Opened a ticket with TradingView. @Gu5tavo71, you were almost right. Upvoted your answer because your comment to your own answer led me to the correct solution. If you tweak your answer to mention the solution I mention here, I will "accept" it.

The "native" chart uses BATS:SPY. When I change request.security() to use BATS:SPY it is now 100% in sync. That is non-intuitive to me. One would think that request.security() would DEFAULT to the same data source as the charts but allow one to choose a different source if needed.

huangapple
  • 本文由 发表于 2023年2月14日 02:04:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/75439646.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定