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 に答える