在 For 循环中使用 request.security 函数的替代方法
我编写了一些代码来确定 FTSE 相对于 DAX 和 CAC 的相对强弱。
//Define the lookback period
lookback=10
//Determine if there is strength in the FTSE relative to the DAX and the CAC over the specified lookback period
relativestrengthindicator=0
relativeweaknessindicator=0
float FTSEreturn=0
float DAXreturn=0
float CACreturn=0
float relativereturntoDAX=0
float relativereturntoCAC=0
for i=0 to (lookback-1)
FTSElastclose=request.security("UK100","5",close[i+1])
FTSEsecondlastclose=request.security("UK100","5",close[i+2])
FTSEreturn:=((FTSElastclose-FTSEsecondlastclose)/FTSEsecondlastclose)*100
DAXlastclose=request.security("DE40","5",close[i+1])
DAXsecondlastclose=request.security("DE40","5",close[i+2])
DAXreturn:=((DAXlastclose-DAXsecondlastclose)/DAXsecondlastclose)*100
CAClastclose=request.security("FR40","5",close[i+1])
CACsecondlastclose=request.security("FR40","5",close[i+2])
CACreturn:=((CAClastclose-CACsecondlastclose)/CACsecondlastclose)*100
relativereturntoDAX:=FTSEreturn-DAXreturn
relativereturntoCAC:=FTSEreturn-CACreturn
if relativereturntoDAX>0 and relativereturntoCAC>0
relativestrengthindicator:=relativestrengthindicator+1
else if relativereturntoDAX<0 and relativereturntoCAC<0
relativeweaknessindicator:=relativeweaknessindicator+1
plot(relativestrengthindicator)
plot(relativeweaknessindicator)
然而,产生的错误消息是“无法在‘if’、‘switch’或‘for’内调用‘request.*()’函数”。
如果我无法在 For 循环中使用 request.security 函数,我应该如何提取价格并将其包含在 For 循环中?
谢谢。
I've written some code to determine the relative strength and weakness of the FTSE relative to the DAX and the CAC.
//Define the lookback period
lookback=10
//Determine if there is strength in the FTSE relative to the DAX and the CAC over the specified lookback period
relativestrengthindicator=0
relativeweaknessindicator=0
float FTSEreturn=0
float DAXreturn=0
float CACreturn=0
float relativereturntoDAX=0
float relativereturntoCAC=0
for i=0 to (lookback-1)
FTSElastclose=request.security("UK100","5",close[i+1])
FTSEsecondlastclose=request.security("UK100","5",close[i+2])
FTSEreturn:=((FTSElastclose-FTSEsecondlastclose)/FTSEsecondlastclose)*100
DAXlastclose=request.security("DE40","5",close[i+1])
DAXsecondlastclose=request.security("DE40","5",close[i+2])
DAXreturn:=((DAXlastclose-DAXsecondlastclose)/DAXsecondlastclose)*100
CAClastclose=request.security("FR40","5",close[i+1])
CACsecondlastclose=request.security("FR40","5",close[i+2])
CACreturn:=((CAClastclose-CACsecondlastclose)/CACsecondlastclose)*100
relativereturntoDAX:=FTSEreturn-DAXreturn
relativereturntoCAC:=FTSEreturn-CACreturn
if relativereturntoDAX>0 and relativereturntoCAC>0
relativestrengthindicator:=relativestrengthindicator+1
else if relativereturntoDAX<0 and relativereturntoCAC<0
relativeweaknessindicator:=relativeweaknessindicator+1
plot(relativestrengthindicator)
plot(relativeweaknessindicator)
However, the error message produced is "Cannot call 'request.*()' function inside 'if', 'switch' or 'for'".
If I am unable to use the request.security function inside a For loop, how should I go about extracting the prices and including it in the For loop?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如前所述,
request.security()
函数会创建一个与当前图表并行的图表。您可以通过创建此并行图表来解决您的问题,然后在
for
循环中调用它。代码如下所示:
As mentioned, the
request.security()
function creates a parallel chart to the current one.You can solve your issue by creating this parallel chart, and then call it inside the
for
loop.The code will look like this:
您不能执行此操作,因为安全性需要保持不变并在运行时已知,因为它会创建与当前图表平行的图表。
You cannot do this as security needs to be constant and known at runtime as it creates a parallel chart to the current one.