RicardoSantos

[RS]Trade Volume Index V1

As described here:

update: added divergence detection.
オープンソーススクリプト

TradingViewの精神に則り、このスクリプトの作者は、トレーダーが理解し検証できるようにオープンソースで公開しています。作者に敬意を表します!無料で使用することができますが、このコードを投稿で再利用するには、ハウスルールに準拠する必要があります。 お気に入りに登録してチャート上でご利用頂けます。

免責事項

これらの情報および投稿は、TradingViewが提供または保証する金融、投資、取引、またはその他の種類のアドバイスや推奨を意図したものではなく、またそのようなものでもありません。詳しくは利用規約をご覧ください。

チャートでこのスクリプトを利用したいですか?
//@version=2
study(title='[RS]Trade Volume Index V1', overlay=false)
smooth = input(title='tvi Smoothness, (1 to have no smoothing):', type=integer, defval=1)
smooth2 = input(title='Signal Smoothness, (<0 to hide):', type=integer, defval=0)
f_tvi()=>
    _min_tick = syminfo.mintick
    _price_change = close-open // can be change(close) if want to include gaps
    _direction = _price_change > _min_tick ? 1 : _price_change < -_min_tick ? -1 : _direction[1] //1=accumulation, -1=distribution
    _return_tvi = na(_return_tvi[1]) ? volume : _direction > 0 ? _return_tvi[1] + volume : _direction < 0 ? _return_tvi[1] - volume : _return_tvi[1]

f_top_fractal(_src)=>_src[4] < _src[2] and _src[3] < _src[2] and _src[2] > _src[1] and _src[2] > _src[0]
f_bot_fractal(_src)=>_src[4] > _src[2] and _src[3] > _src[2] and _src[2] < _src[1] and _src[2] < _src[0]
f_fractalize(_src)=>f_top_fractal(_src) ? 1 : f_bot_fractal(_src) ? -1 : 0

hist = sma(f_tvi(), smooth)

fractal_top = f_fractalize(hist) > 0 ? hist[2] : na
fractal_bot = f_fractalize(hist) < 0 ? hist[2] : na

high_prev = valuewhen(fractal_top, hist[2], 1) 
high_price = valuewhen(fractal_top, high[2], 1)
low_prev = valuewhen(fractal_bot, hist[2], 1) 
low_price = valuewhen(fractal_bot, low[2], 1)

regular_bearish_div = fractal_top and high[2] > high_price and hist[2] < high_prev
hidden_bearish_div = fractal_top and high[2] < high_price and hist[2] > high_prev
regular_bullish_div = fractal_bot and low[2] < low_price and hist[2] > low_prev
hidden_bullish_div = fractal_bot and low[2] > low_price and hist[2] < low_prev

plot(title='TVI', series=hist, color=black)
plot(title='Signal', series=smooth2 <= 0 ? na : sma(hist, smooth2), color=red)
//hline(title='0', price=0, color=black)
plot(title='H F', series=fractal_top, color=black, offset=-2)
plot(title='L F', series=fractal_bot, color=black, offset=-2)
plot(title='H D', series=fractal_top, style=circles, color=regular_bearish_div or hidden_bearish_div ? maroon : gray, linewidth=3, offset=-2)
plot(title='L D', series=fractal_bot, style=circles, color=regular_bullish_div or hidden_bullish_div ? green : gray, linewidth=3, offset=-2)

plotshape(title='+RBD', series=regular_bearish_div ? hist[2] : na, text='Regular', style=shape.labeldown, location=location.absolute, color=maroon, textcolor=white, offset=-2)
plotshape(title='+HBD', series=hidden_bearish_div ? hist[2] : na, text='hidden', style=shape.labeldown, location=location.absolute, color=maroon, textcolor=white, offset=-2)
plotshape(title='-RBD', series=regular_bullish_div ? hist[2] : na, text='Regular', style=shape.labelup, location=location.absolute, color=green, textcolor=white, offset=-2)
plotshape(title='-HBD', series=hidden_bullish_div ? hist[2] : na, text='hidden', style=shape.labelup, location=location.absolute, color=green, textcolor=white, offset=-2)