代码之家  ›  专栏  ›  技术社区  ›  makat

在X数量的酒吧后销售的策略

  •  0
  • makat  · 技术社区  · 3 年前

    我正试图添加一种策略,一种非常简单的策略——在达到触发点时,在X数量的酒吧后出售。我尝试了在线推荐的代码,但似乎不起作用:

    if sellFb == true and buyFb == false
        strategy.entry("BreakDown", strategy.short, comment="Short")  
    
    if buyFb == true and sellFb == false
        strategy.entry("BreakUp", strategy.long, comment="Buy")
    
    
    
    if sellFb or buyFb
        alert(txt, alert.freq_once_per_bar_close)
        n = 4
        open_idx = strategy.opentrades.entry_bar_index(strategy.opentrades-1)
        diff_idx = bar_index - open_idx
    
        if (diff_idx >= n)
            strategy.close("BreakUp")
            strategy.close("BreakDown")
    

    它不会在酒吧后关闭策略,只会在下一个相反方向的交易到来时关闭(做空/买入)

    1 回复  |  直到 3 年前
        1
  •  1
  •   vitruvius    3 年前

    这是因为只有在 sellFb buyFb true

    相反,您应该在全局范围内进行检查。

    if sellFb == true and buyFb == false
        strategy.entry("BreakDown", strategy.short, comment="Short")  
    
    if buyFb == true and sellFb == false
        strategy.entry("BreakUp", strategy.long, comment="Buy")  
    
    if sellFb or buyFb
        alert(txt, alert.freq_once_per_bar_close)
    
    n = 4
    open_idx = strategy.opentrades.entry_bar_index(strategy.opentrades-1)
    diff_idx = bar_index - open_idx
    
    if (diff_idx >= n)
        strategy.close("BreakUp")
        strategy.close("BreakDown")