RicardoSantos

[RS]Swing Charts V0

EXPERIMENTAL:
Swing Charts with a personal touch(has slight modifications) :p
Remove from Favorite Scripts Add to Favorite Scripts
//@version=2
study(title='[RS]Swing Charts V0', shorttitle='SC', overlay=true)

//  Swing charts as described here: http://www.investopedia.com/articles/technical/04/080404.asp
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)

barcolor(title='Up Bar', color=f_up_bar(0) ? lime : na)
barcolor(title='Down Bar', color=f_down_bar(0) ? red : na)
barcolor(title='Inside Bar', color=f_inside_bar(0) ? blue : na)
barcolor(title='Outside Bar', color=f_outside_bar(0) ? aqua : na)
Nice job! Surprised had not seen this sooner. Thanks for posting and keep smiling!
Reply
United States
United Kingdom
India
Deutschland
France
España
Italia
Polska
Türkiye
Россия
Brasil
Indonesia
Malaysia
Việt Nam
日本
한국
简体
繁體
Home Stock Screener Forex Signal Finder Cryptocurrency Signal Finder Economic Calendar How It Works Chart Features House Rules Moderators Website & Broker Solutions Widgets Stock Charting Library Feature Request Blog & News FAQ Help & Wiki Twitter
Profile Profile Settings Account and Billing My Support Tickets Priority Support Contact Support Ideas Published Followers Following Private Messages Chat Sign Out