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)
Is there any possible way I can add more percentage to the zig zag?
Reply
RicardoSantos deluchoargain
@deluchoargain, swing charts are not based on percentage, its based on bar patterns.
Reply
cool
Reply
...... Great, Unique & Sublime !!! FOR ME!
I used to draw the lines in mind 5-6 years...
Now my template is of flugent utility !!!

Where is your personal touch? /?\
Where you catch the theory — I thought it's mostly mine ... -;-j
+1 Reply
Routcheau Routcheau
@Routcheau :
Which language you used to code
+1 Reply
Nice job! Surprised had not seen this sooner. Thanks for posting and keep smiling!
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