0

我试图过滤掉条形条件并仅显示每个选项条件系列的第一个条形。查看我的图像 ,我被卡住了,无法找到解决方法。很高兴得到帮助。谢谢

    //inputs
    srcClose = close
    resCustom = input(title="Timeframe in Minutes", type=string, defval="343")
    len1 = input(7, title="MA7")
    len2 = input(77, title="MA77")
    len3 = input(231, title="MA231")
    useCurrentRes = input(false, title="Use Current Chart Resolution?")
    res = useCurrentRes ? period : resCustom
    colbar = input(true, title="Color Bars")
    signals = input(true, title="Buy and Sell Signals")
    colgaps = input(true, title="Colored Gaps")

    //EMA calculation
    ema7Calc = ema(srcClose, len1)
    ema77Calc = ema(srcClose, len2)
    ema231Calc = ema(srcClose, len3)

    output1 = security(tickerid, res, ema7Calc)
    output2 = security(tickerid, res, ema77Calc)
    output3 = security(tickerid, res, ema231Calc)

    //Conditions
    emacrossbuy = (close > output2 and crossover(close,output1))
    emacrosssell = (close < output2 and crossunder(close,output1))
    emacrsstrng = (crossover(close,output3) and output1 >= output2) or (crossover(close,output2) and output1 >= output3)
    emacrsstrngsl = (crossunder(close,output2) and output1 <= output2)
    underwater = (close < output3 and output1 < output2 or output3)
    overwater = (close > output3 and output1 > output3)

    //Ploting Barcolors
    barcolor((signals and emacrossbuy or emacrsstrng) ? lime : na, title="Long Signal Bars ", editable=true)
    barcolor((signals and emacrosssell or emacrsstrngsl) ? red : na, title="Short Signal Bars ", editable=true)
    barcolor((colbar and overwater) ? white : na, title="Overwater", editable=true)
    barcolor((colbar and underwater) ? #444444 : na, title="Underwater", editable=true)`enter code here`
4

1 回答 1

0

这并不难,但需要一些试验和错误。我像这样解决了它,但它可能可以进行更多优化。

使用这样的东西:

buy = false // defines variable, mandatory in v3
sell = false // defines variable, mandatory in v3
buy := buy[1] // sets last bar value as current
sell := sell[1] // sets last bar value as current

if (cond 1) or (cond 2) or (cond 3) and (buy = false) // if it meets conditions and buy value is false, then set "buy" flag and close "sell" flag
buy := true
sell := false

if (cond 4) or (cond 5) or (cond 6) and (sell = false) // if it meets conditions and sell value is false, then set "sell" flag and close "buy" flag
sell := true
buy := false

希望能帮助到你。

于 2018-10-30T16:57:21.120 回答