RicardoSantos

[RS]Function Volatility Stop V0

Function for Volatility Stop:
added some tweeks so it can be used on any series as in example a rsi .
Remove from Favorite Scripts Add to Favorite Scripts
//@version=2
study(title='[RS]Function Volatility Stop V0', shorttitle='fVS', overlay=false)
rsi_src = input(title='Source for RSI:', type=source, defval=close)
rsi_length = input(title='RSI Length:', type=integer, defval=8, minval=1)
multiplier = input(title='Fast True Range Multiplier', type=float, defval=2.5)
length = input(title='Average Range Length:', type=integer, defval=12, minval=1)

//  ||---------------------------------------------------------------------------------------------------------||
//  ||---------------------------------------------------------------------------------------------------------||
//  ||---------------------------------------------------------------------------------------------------------||
f_vstop(_high_src, _low_src, _exit_src, _range, _multiplier)=>
    _trend = na(_trend[1]) ? +1 : _high_src > _vstop[1] ? +1 : _low_src < _vstop[1] ? -1 : _trend[1]
    _max_close = change(_trend) != 0 ? _low_src : _low_src >= _max_close[1] ? _low_src : _max_close[1]
    _min_close = change(_trend) != 0 ? _high_src : _high_src <= _min_close[1] ? _high_src : _min_close[1]
    _vstop = na(_vstop[1]) ? _exit_src :
         change(_trend) > 0 ? _exit_src - (_multiplier * _range) : 
         _trend > 0 ? max(_vstop[1], _max_close - (_multiplier * _range)) :
         change(_trend) < 0 ? _exit_src + (_multiplier * _range) : 
         _trend < 0 ? min(_vstop[1], _min_close + (_multiplier * _range)) : 
         _vstop[1]
    _width = change(_trend) != 0 ? abs(change(_vstop)) : _width[1]
    _extended_width = _trend > 0 ? _vstop + _width : _vstop - _width
    [_vstop, _extended_width]
//  ||---------------------------------------------------------------------------------------------------------||
//  ||---------------------------------------------------------------------------------------------------------||
//  ||---------------------------------------------------------------------------------------------------------||

rsi = rsi(rsi_src, rsi_length)
range = ema(abs(change(rsi)), length) 
high_src = rsi
low_src = rsi
exit_src = rsi
[vstop, width] = f_vstop(high_src, low_src, exit_src, range, multiplier)

plot(title='RSI', series=rsi, color=black, transp=0)
plot(title='VS', series=vstop, style=circles, color=exit_src >= vstop ? green : maroon, transp=0, linewidth=1, join=true)
plot(title='W', series=width, style=circles, color=black, transp=0)
hline(100, color=black)
hline(070, color=black)
hline(030, color=black)
hline(000, color=black)
Could you explain this indicator a bit?
Reply
Home Stock Screener Forex Screener Crypto Screener Economic Calendar Shows How It Works Chart Features Pricing House Rules Moderators Website & Broker Solutions Widgets Charting Solutions Lightweight Charting Library Help Center Refer a friend Feature Request Blog & News FAQ Wiki Twitter
Profile Profile Settings Account and Billing Refer a friend My Support Tickets Help Center Ideas Published Followers Following Private Messages Chat Sign Out