Pine 脚本表适用于某些符号,但不适用于其他符号
我有一个工作脚本可以正确显示表。但是,当我选择另一个符号或库存时,桌子没有显示任何计算并返回NAN,
因此在“ Nifty”上可以正常工作,但是如果我选择“ Nifty1!”,则无效例如,符号仅在结果中显示NAN。周围的任何指示都将非常明显
================================================================ ===
以下是可重复的脚本
//@version=4
study(title="test", shorttitle="test",overlay=true,format=format.price)
i_startTime = input(defval = timestamp("01 Jan 2021 09:00 +0530"), title = "Start Time", type = input.time)
i_endTime = input(defval = timestamp("31 Mar 2022 15:30 +0530"), title = "End Time", type = input.time)
inDateRange = time >= i_startTime and time <= i_endTime
StrategyLongCond = crossover(ema(close, 8), ema(open, 9) )
StrategyShortCond = crossunder(ema(close, 8), ema(open, 9))
plotshape(StrategyLongCond ,title="Buy Signal", style=shape.triangleup, location=location.belowbar,color=color.blue, display=display.all)
plotshape(StrategyShortCond,title="Sell Signal", style=shape.triangledown, location=location.abovebar,color=color.red, display=display.all)
StrategyLongCondCount= sum((StrategyLongCond and inDateRange? 1 : 0), 4999)
StrategyShortCondCount= sum((StrategyShortCond and inDateRange? 1 : 0), 4999)
TradeSignalCount = StrategyLongCondCount + StrategyShortCondCount
var table Display = table.new(position.bottom_right, 5, 50)
if barstate.islast
table.cell(Display, 1, 4, "Sgnl", bgcolor = color.new(color.blue, 90), text_size=size.small)
table.cell(Display, 1, 5, tostring(TradeSignalCount), bgcolor = color.new(color.gray,90), text_size=size.small)
I have a working script that display tables correctly. However when i chose another symbol or stock the table do not show any calculations and return NaN
So this works fine on "Nifty" but doesnt work if I choose "NIFTY1!" symbol for example, only shows NaN in the results. Any directions around this will be greatly appreciable
=============================================
Below is the reproducible script
//@version=4
study(title="test", shorttitle="test",overlay=true,format=format.price)
i_startTime = input(defval = timestamp("01 Jan 2021 09:00 +0530"), title = "Start Time", type = input.time)
i_endTime = input(defval = timestamp("31 Mar 2022 15:30 +0530"), title = "End Time", type = input.time)
inDateRange = time >= i_startTime and time <= i_endTime
StrategyLongCond = crossover(ema(close, 8), ema(open, 9) )
StrategyShortCond = crossunder(ema(close, 8), ema(open, 9))
plotshape(StrategyLongCond ,title="Buy Signal", style=shape.triangleup, location=location.belowbar,color=color.blue, display=display.all)
plotshape(StrategyShortCond,title="Sell Signal", style=shape.triangledown, location=location.abovebar,color=color.red, display=display.all)
StrategyLongCondCount= sum((StrategyLongCond and inDateRange? 1 : 0), 4999)
StrategyShortCondCount= sum((StrategyShortCond and inDateRange? 1 : 0), 4999)
TradeSignalCount = StrategyLongCondCount + StrategyShortCondCount
var table Display = table.new(position.bottom_right, 5, 50)
if barstate.islast
table.cell(Display, 1, 4, "Sgnl", bgcolor = color.new(color.blue, 90), text_size=size.small)
table.cell(Display, 1, 5, tostring(TradeSignalCount), bgcolor = color.new(color.gray,90), text_size=size.small)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,这是因为您在
sum()
函数中使用了4999
。这意味着您需要检查 4999 个柱来进行计算。但是,如果您的图表上的柱形图少于 4999 个,您将会遇到您所描述的问题。它不是特定于图表的。如果您前往 Nifty 的时间范围为 1 周或更长,您也会遇到同样的问题。
实际上,您可以使用一个简单的计数器来完成您想做的事情。
Well, it is because you are using
4999
in yoursum()
function. That means you want to check 4999 bars for your calculation.However, if there are less than 4999 bars on your chart, you will have the issue you described. It is not chart specific. You will have the same issue if you go to Nifty with a timeframe 1 week or higher.
You can actually use a simple counter for what you want to do.