根据strategy.entry顺序发出警报

时间:2020-05-15 05:39:28

标签: pine-script alerts

我在交易视图中有一个可行的策略,我想向其添加警报。

我只需要对strategy.entry(多头)发出“购买”警报,并在strategy.entry(短)上产生“卖出”警报。

条件不能相同。长期使用的条件之一是有两个连续的绿色条。因此,一旦长警报触发且下一个栏也变为绿色,长警报将在第三个栏上再次触发。每当有两个连续的绿色条时触发。我需要的是使其触发一次(变长),然后必须等待卖出警报才能再次触发。

这是有关此问题的示例代码,感谢您的帮助。

    onGridReady(params) {
        this.gridApi = params.api;
        this.gridColumnApi = params.columnApi;

        // initialFilter prop is set here
        if (this.props.initialFilter) {
          this.props.initialFilter(params);
        }
        params.api.setServerSideDatasource(this.dataSource(params));
    }

1 个答案:

答案 0 :(得分:1)

您只需要弄清楚自己是否已经很长,然后再继续。因此,您可以为此使用变量并在触发买入或卖出信号之前检查其值。

幸运的是,当我开始使用pinescript时,我正在使用相同的脚本:)它是v3,但能解决问题。

//@version=3
study("Consecutive Up/Down with Alerts", overlay=true)

consecutiveBarsUp = input(3)
consecutiveBarsDown = input(3)

price = close
isLong = false
isLong := nz(isLong[1], false)

ups = 0.0
ups := price > price[1] ? nz(ups[1]) + 1 : 0

dns = 0.0
dns := price < price[1] ? nz(dns[1]) + 1 : 0

buySignal = (ups >= consecutiveBarsUp) and not nz(isLong[1])
sellSignal = (dns >= consecutiveBarsDown) and nz(isLong[1])

if (buySignal)
    isLong := true

if (sellSignal)
    isLong := false

alertcondition(condition=buySignal, title="BUY", message="BUY Signal.")
alertcondition(condition=sellSignal, title="SELL", message="SELL Signal.")

plotshape(buySignal, style=shape.triangleup, color=green, transp=40, text="BUY", editable=false, location=location.belowbar, size=size.small)
plotshape(sellSignal, style=shape.triangledown, color=red, transp=40, text="SELL", editable=false, location=location.abovebar, size=size.small)