首页 > 解决方案 > 多准则多空信号

问题描述

两个不同的指标有两个不同的买入信号。当这两个指标都给出买入信号时,我想将其视为一个信号。我怎样才能做到这一点。这些指标是 supertrend 和 mavilimw。如下图所示,如果超级趋势给出买入信号,并且如果 mavilimw 给出买入信号,我想将其视为单个信号,并且我想设置警报条件警报。supertrend 和 mavilimw 代码如下。

    Periods = input(title="ATR Period", type=input.integer, defval=10)
    src = input(hl2, title="Source")
    Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0)
    changeATR= input(title="Change ATR Calculation Method ?", type=input.bool, defval=true)
    showsignals = input(title="Show Buy/Sell Signals ?", type=input.bool, defval=true)
    highlighting = input(title="Highlighter On/Off ?", type=input.bool, defval=true)
    atr2 = sma(tr, Periods)
    atr= changeATR ? atr(Periods) : atr2
    up=src-(Multiplier*atr)
    up1 = nz(up[1],up)
    up := close[1] > up1 ? max(up,up1) : up
    dn=src+(Multiplier*atr)
    dn1 = nz(dn[1], dn)
    dn := close[1] < dn1 ? min(dn, dn1) : dn
    trend = 1
    trend := nz(trend[1], trend)
    trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend
    upPlot = plot(trend == 1 ? up : na, title="Up Trend", style=plot.style_linebr, linewidth=2, color=color.green)
    buySignal = trend == 1 and trend[1] == -1
    plotshape(buySignal ? up : na, title="UpTrend Begins", location=location.absolute, 
    style=shape.circle, size=size.tiny, color=color.green, transp=0)
    plotshape(buySignal and showsignals ? up : na, title="Buy", text="Buy", 
    location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green, 
    textcolor=color.white, transp=0)
    dnPlot = plot(trend == 1 ? na : dn, title="Down Trend", style=plot.style_linebr, 
    linewidth=2, color=color.red)
    sellSignal = trend == -1 and trend[1] == 1
    plotshape(sellSignal ? dn : na, title="DownTrend Begins", location=location.absolute, 
    style=shape.circle, size=size.tiny, color=color.red, transp=0)
    plotshape(sellSignal and showsignals ? dn : na, title="Sell", text="Sell", 
    location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, 
    textcolor=color.white, transp=0)
    mPlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0)
    longFillColor = highlighting ? (trend == 1 ? color.green : color.white) : color.white
    shortFillColor = highlighting ? (trend == -1 ? color.red : color.white) : color.white
    fill(mPlot, upPlot, title="UpTrend Highligter", color=longFillColor)
    fill(mPlot, dnPlot, title="DownTrend Highligter", color=shortFillColor)
    alertcondition(buySignal, title="SuperTrend Buy", message="SuperTrend Buy!")
    alertcondition(sellSignal, title="SuperTrend Sell", message="SuperTrend Sell!")
    changeCond = trend != trend[1]
    alertcondition(changeCond, title="SuperTrend Direction Change", message="SuperTrend has changed direction!")

    mavilimold = input(false, title="Show Previous Version of MavilimW?")
    fmal=input(3,"First Moving Average length")
    smal=input(5,"Second Moving Average length")
    tmal=fmal+smal
    Fmal=smal+tmal
    Ftmal=tmal+Fmal
    Smal=Fmal+Ftmal

    M1= wma(close, fmal)
    M2= wma(M1, smal)
    M3= wma(M2, tmal)
    M4= wma(M3, Fmal)
    M5= wma(M4, Ftmal)
    MAVW= wma(M5, Smal)
    col1= MAVW>MAVW[1]
    col3= MAVW<MAVW[1]
    colorM = col1 ? color.blue : col3 ? color.red : color.yellow

    plot(MAVW, color=colorM, linewidth=2, title="MAVW")

    M12= wma(close, 3)
    M22= wma(M12, 5)
    M32= wma(M22, 8)
    M42= wma(M32, 13)
    M52= wma(M42, 21)
    MAVW2= wma(M52, 34)

    plot(mavilimold and MAVW2 ? MAVW2 : na, color=color.blue, linewidth=2, title="MavWOld")

    alertcondition(crossover(MAVW,MAVW[1]), title="MAVW BUY", message="MAVW BUY!")
    alertcondition(crossunder(MAVW,MAVW[1]), title="MAVW SELL", message="MAVW SELL!")

在此处输入图像描述

标签: pine-scriptalgorithmic-tradingtrading

解决方案


推荐阅读