连接现有脚本以累积音量和锯齿形

时间:2019-08-05 13:56:41

标签: tradingview-api

我在合并两个脚本时遇到问题。如果我一个接一个地添加,则会在输入或其他位置出现错误,而两个单独的脚本可以正常工作

我试图合并下面的代码,但是在这种特定情况下,我在_trend和_return中有错误

原始代码在这里: 1)https://www.tradingview.com/script/QrCFs0K2-Weis-Wave-Volume/ 2)https://www.tradingview.com/script/t30usIlv-Weis-Wave-Chart/


//@version=3
study("Weis Wave Volume", shorttitle="WWV", overlay=true)
method = input(defval="ATR", options=["ATR", "Traditional", "Part of Price"], title="Renko Assignment Method")
methodvalue = input(defval=14.0, type=float, minval=0, title="Value")
pricesource = input(defval="Close", options=["Close", "Open / Close", "High / Low"], title="Price Source")
useClose = pricesource == "Close"
useOpenClose = pricesource == "Open / Close" or useClose
useTrueRange = input(defval="Auto", options=["Always", "Auto", "Never"], title="Use True Range instead of Volume")
isOscillating=input(defval=false, type=bool, title="Oscillating")
normalize=input(defval=false, type=bool, title="Normalize")
vol = useTrueRange == "Always" or (useTrueRange == "Auto" and na(volume))? tr : volume
op = useClose ? close : open
hi = useOpenClose ? close >= op ? close : op : high
lo = useOpenClose ? close <= op ? close : op : low

if method == "ATR"
    methodvalue := atr(round(methodvalue))
if method == "Part of Price"
    methodvalue := close/methodvalue

currclose = na
prevclose = nz(currclose[1])
prevhigh = prevclose + methodvalue
prevlow = prevclose - methodvalue
currclose := hi > prevhigh ? hi : lo < prevlow ? lo : prevclose

direction = na
direction := currclose > prevclose ? 1 : currclose < prevclose ? -1 : nz(direction[1])
directionHasChanged = change(direction) != 0
directionIsUp = direction > 0
directionIsDown = direction < 0

barcount = 1
barcount := not directionHasChanged and normalize ? barcount[1] + barcount : barcount
vol := not directionHasChanged ? vol[1] + vol : vol
res = barcount > 1 ? vol/barcount : vol

f_up_bar(_n_bars_back)=>
    _return = high[_n_bars_back] > high[_n_bars_back + 1] and low[_n_bars_back] > low[_n_bars_back + 1]

f_down_bar(_n_bars_back)=>
    _return = low[_n_bars_back] < low[_n_bars_back + 1] and high[_n_bars_back] < high[_n_bars_back + 1]

f_inside_bar(_n_bars_back)=>
    _return = high[_n_bars_back] <= high[_n_bars_back + 1] and low[_n_bars_back] >= low[_n_bars_back + 1]

f_outside_bar(_n_bars_back)=>
    _return = high[_n_bars_back] >= high[_n_bars_back + 1] and low[_n_bars_back] <= low[_n_bars_back + 1]

f_swing_high(_n_bars_back)=>
    _condition_00 = f_up_bar(_n_bars_back + 1) and f_down_bar(_n_bars_back)
    _condition_01 = f_outside_bar(_n_bars_back + 1) and f_down_bar(_n_bars_back)
    _condition_02 = f_inside_bar(_n_bars_back + 1) and f_down_bar(_n_bars_back)
    _condition_03 = f_up_bar(_n_bars_back + 1) and f_inside_bar(_n_bars_back) and close[_n_bars_back] < hl2[_n_bars_back + 1]
    _condition_04 = f_outside_bar(_n_bars_back) and close < hl2
    _condition_05 = false
    _return = _condition_00 or _condition_01 or _condition_02 or _condition_03 or _condition_04 or _condition_05

f_swing_low(_n_bars_back)=>
    _condition_00 = f_down_bar(_n_bars_back + 1) and f_up_bar(_n_bars_back)
    _condition_01 = f_outside_bar(_n_bars_back + 1) and f_up_bar(_n_bars_back)
    _condition_02 = f_inside_bar(_n_bars_back + 1) and f_up_bar(_n_bars_back)
    _condition_03 = f_down_bar(_n_bars_back + 1) and f_inside_bar(_n_bars_back) and close[_n_bars_back] > hl2[_n_bars_back + 1]
    _condition_04 = f_outside_bar(_n_bars_back) and close > hl2
    _condition_05 = false
    _return = _condition_00 or _condition_01 or _condition_02 or _condition_03 or _condition_04 or _condition_05


f_swingchart(_swings_high, _swings_low)=>
    _trend = na(_trend[1]) ? 1 : _trend[1] > 0 and _swings_low ? -1 : _trend[1] < 0 and _swings_high ? 1 : _trend[1]
    _return = na(_return[1]) ? 0 : change(_trend) > 0 ? nz(_swings_high, high[1]) : change(_trend) < 0 ? nz(_swings_low, low[1]) : _return[1]

swings_high = f_swing_high(0) ? highest(3) : na
swings_low = f_swing_low(0) ? lowest(3) : na

swing_chart = f_swingchart(swings_high, swings_low)
zigzag = change(swing_chart) != 0 ? swing_chart : na

plot(title='Swing High', series=swings_high, style=circles, color=red, transp=0, linewidth=4, offset=-1)
plot(title='Swing Low', series=swings_low, style=circles, color=lime, transp=0, linewidth=4, offset=-1)
//plot(title='Swing Chart', series=swing_chart, color=change(swing_chart) != 0 ? na : black, transp=0, offset=-1)
plot(title='ZigZag', series=zigzag, color=black, transp=0, linewidth=2, offset=-1)


plotshape(currclose/1000, style=shape.labelup)


//plot(isOscillating and directionIsDown ? -res : res, style = columns, color = directionIsUp ? green : red, transp = 75, linewidth=3, title = "Wave Volume")

我想获取此网站中的图表,首先是顶部图片https://smarttrader.pl/2-jak-dziala-wolumen-skumulowany/

0 个答案:

没有答案