繁体   English   中英

如何为我在 strategy.entry 中的变量 BUY 编写代码我将使用此代码编写变量 BUY 代码

[英]How do I write the code for the variable BUY that I have in strategy.entry I will use this code to write the Variable BUY code

我有这些变量,我希望能够在 Line1 和 Line2 选项下的下拉输入中进行选择。 这些应该可以使用另一个下拉输入来选择, options = ['none', '==', '<', '>', '<=', '>=', ',=', 'crossover', 'crossunder'])名为 Operator1。

sm1res = input.timeframe(title='Time for open', defval='30')
sm1 = request.security(syminfo.tickerid, sm1res, open, lookahead=barmerge.lookahead_on)
sm2res = input.timeframe(title='Time for open', defval='60')
sm2 = request.security(syminfo.tickerid, sm2res, open, lookahead=barmerge.lookahead_on)
sm3res = input.timeframe(title='Time for open', defval='240')
sm3 = request.security(syminfo.tickerid, sm3res, open, lookahead=barmerge.lookahead_on)

to1res = input.timeframe(title='Time for previous open 1', defval='30')  
to1 = request.security(syminfo.tickerid, to1res, open[1], lookahead=barmerge.lookahead_on) 
to2res = input.timeframe(title='Time for previous open 2', defval='60')  
to2 = request.security(syminfo.tickerid, to2res, open[1], lookahead=barmerge.lookahead_on)
to3res = input.timeframe(title='Time for previous open 3', defval='240') 
to3 = request.security(syminfo.tickerid, to3res, open[1], lookahead=barmerge.lookahead_on)  

th1res = input.timeframe(title='Time for previous high 1', defval='30') 
th1 = request.security(syminfo.tickerid, th1res, high[1], lookahead=barmerge.lookahead_on)  
th2res = input.timeframe(title='Time for previous high 2', defval='60') 
th2 = request.security(syminfo.tickerid, th2res, high[1], lookahead=barmerge.lookahead_on) 
th3res = input.timeframe(title='Time for previous high 3', defval='240')  
th3 = request.security(syminfo.tickerid, th3res, high[1], lookahead=barmerge.lookahead_on) 

tl1res = input.timeframe(title='Time for previous low 1', defval='30')
tl1 = request.security(syminfo.tickerid, tl1res, low[1], lookahead=barmerge.lookahead_on)
tl2res = input.timeframe(title='Time for previous low 2', defval='60')
tl2 = request.security(syminfo.tickerid, tl2res, low[1], lookahead=barmerge.lookahead_on)
tl3res = input.timeframe(title='Time for previous low 3', defval='240')
tl3 = request.security(syminfo.tickerid, tl3res, low[1], lookahead=barmerge.lookahead_on)


Line1 = input.string(defval = "sm1", title = 'Line1', inline = 'Operator1', group = 'Strategy1', options=["sm1", "sm2", "sm3", "to1", "to2", "to3", "th1", "th2", "th3", "tl1", "tl2", "tl3"])
Operator1 = input.string(defval = 'none', title = 'Operator1', inline = 'Operator1', group = 'Strategy1', options = ['none', '==', '<', '>', '<=', '>=', '!=', 'crossover', 'crossunder'])
Line2 = input.string(defval = none, title = 'Line2', inline = 'Operator1', group = 'Strategy1', options=["sm1", "sm2", "sm3", "to1", "to2", "to3", "th1", "th2", "th3", "tl1", "tl2", "tl3"])

然后我有一个 buy 变量,但无法让它与不同的代码尝试一起工作,有时它说它应该是系列字符串、bool、const 字符串、输入 ':' 处的语法错误和许多其他错误。

BUY = line1 : Operator1 : line2 ? : na

然后是我的订单安排:

if BUY
    if Type == _S_
        strategy.close('S')
    else
        strategy.entry('K', strategy.long)

if SELL
    if Type == _L_
        strategy.close('K')
    else
        strategy.entry('S', strategy.short)

感谢您的帮助,以便部分错误使用正确的代码代替,欢迎提出改进建议。 我不太擅长编程,所以如果你有时间,请用简单的方式解释。

我试过阅读手册并寻找 go 在一起的不同允许类型。 我也尝试过 Pinecoders 和聊天。 恐怕 request.security 不允许选项。

请编辑您的问题,使其一次只包含一个问题。

关于你的第一个问题,你可以使用一个switch

Line1_input = input.string(defval = "sm1", title = 'Line1', inline = 'Operator1', group = 'Strategy1', options=["sm1", "sm2", "sm3", "to1", "to2", "to3", "th1", "th2", "th3", "tl1", "tl2", "tl3"])
Line2_input = input.string(defval = "sm1", title = 'Line2', inline = 'Operator1', group = 'Strategy1', options=["sm1", "sm2", "sm3", "to1", "to2", "to3", "th1", "th2", "th3", "tl1", "tl2", "tl3"])

Operator1 = input.string(defval = 'none', title = 'Operator1', inline = 'Operator1', group = 'Strategy1', options = ['none', '==', '<', '>', '<=', '>=', '!=', 'crossover', 'crossunder'])

line1 = switch Line1_input
    "sm1" => ta.sma(close, 10)
    "sm2" => ta.ema(close, 10)
    => ta.hma(close, 10)

line2 = switch Line2_input
    "sm1" => ta.sma(close, 20)
    "sm2" => ta.ema(close, 20)
    => ta.hma(close, 20)

BUY = switch Operator1
    '==' => line1 == line2
    '<' => line1 < line2
    '>' => line1 > line2
    '<=' => line1 <= line2
    '>=' => line1 >= line2
    '!=' => line1 != line2
    'crossover' => ta.crossover(line1, line2)
    'crossunder' => ta.crossunder(line1, line2)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM