【问题标题】:how to filter out duplicate buy or sell signal in pinescript?如何在pinescript中过滤掉重复的买入或卖出信号?
【发布时间】:2021-08-13 12:48:00
【问题描述】:

帮我过滤掉两个相同的信号。

这意味着如果之前的信号是卖出信号,我只想要买入信号,反之亦然。

问题: 无法摆脱两个相同的信号

代码:

z1 和 z2 是不同时期的 2 个简单移动平均线..

     L_buy =  ( (z1 > z2)  and  crossover(rsi,50)  ) or ( crossover(z1,z2)  and rsi > 50 ) 
     L_sell = ( (z1< z2)   and  crossunder(rsi,50) ) or ( crossunder(z1,z2) and rsi < 50 )

【问题讨论】:

    标签: pine-script tradingview-api


    【解决方案1】:

    为了避免重复信号,我们将创建一个在每个信号后关闭/打开的开关。

    // S_ = switch
    // F_ = final
    // Defines Variables for Avoiding Duplicate Signals (Kind of switch)
    var S_sell = false
    var S_buy = false
    
    // Defines Trade Signals
    F_buySignal = not S_sell and bxx
    F_sellSignal = not S_buy and sxx
    
    // turning switches off/on after signal is generated 
    if F_buySignal
        S_sell := true
        S_buy := false
    
    if F_sellSignal
        S_sell := false
        S_buy := true
    
    plotshape(F_buySignal , color=green , style=shape.triangleup, location=location.belowbar , size=size.small)
    plotshape(F_sellSignal , color=red , style=shape.triangledown, location=location.abovebar , size=size.small)
    
    
    

    【讨论】:

      猜你喜欢
      • 2022-01-09
      • 1970-01-01
      • 2022-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-28
      • 1970-01-01
      相关资源
      最近更新 更多