0

我该如何重新编码?如何修复错误?


var float close_lock    = na
var float open_lock     = na
var float high_lock     = na
var float low_lock      = na

var bool normal_ticker_check    = na
normal_ticker_check := syminfo.type != 'spread'

if (normal_ticker_check)
    close_lock   := security(syminfo.prefix+":"+syminfo.ticker , timeframe.period , close ,barmerge.gaps_off, barmerge.lookahead_on) 
    open_lock    := security(syminfo.prefix+":"+syminfo.ticker , timeframe.period , open  ,barmerge.gaps_off, barmerge.lookahead_on) 
    high_lock    := security(syminfo.prefix+":"+syminfo.ticker , timeframe.period , high  ,barmerge.gaps_off, barmerge.lookahead_on) 
    low_lock     := security(syminfo.prefix+":"+syminfo.ticker , timeframe.period , low   ,barmerge.gaps_off, barmerge.lookahead_on) 
else
    close_lock   := close 
    open_lock    := open 
    high_lock    := high 
    low_lock     := low 



错误:不能在“if”或“for”中调用“security”或“financial”

4

1 回答 1

0

如何在全局范围内呈现您的安全调用,然后按您的方式分配?我在这里使用了一个元组来将安全调用的出现次数也减少到 1(尽可能少使用的最佳实践)

var float close_lock    = na
var float open_lock     = na
var float high_lock     = na
var float low_lock      = na

var bool normal_ticker_check    = na
normal_ticker_check := syminfo.type != 'spread'

[o, h, l, c] = security(syminfo.prefix+":"+syminfo.ticker , timeframe.period , [open, high, low, close] ,barmerge.gaps_off, barmerge.lookahead_on) 

if (normal_ticker_check)
    close_lock   := c
    open_lock    := o
    high_lock    := h
    low_lock     := l
else
    close_lock   := close 
    open_lock    := open 
    high_lock    := high 
    low_lock     := low 
于 2021-09-20T19:42:00.420 回答