RicardoSantos

[RS]Swing Charts V1 Darvas Box V0.1

3926 vizualizações
582
3926 6
UPDATE: had a minor bug on how to detect the range.
Remover dos scripts favoritos Adicionar aos scripts favoritos
//@version=2
study(title='[RS]Swing Charts V1 Darvas Box V0.1', shorttitle='SCDV', overlay=true)
SHOW_BARCOLOR = input(title='Overwrite Bar Colors?', type=bool, defval=false)
SHOW_ZIGZAG_LVL0 = input(title='Display ZigZag Level 0?', type=bool, defval=true)
SHOW_SWINGCHART_LVL0 = input(title='Display Swing Chart Stops Level 0?', type=bool, defval=false)
SHOW_SWINGSIGNAL_LVL0 = input(title='Display Swing Signals Level 0?', type=bool, defval=false)

f_up_bar(_previous_high, _current_high, _previous_low, _current_low)=>
    _return = _previous_high < _current_high and _previous_low < _current_low

f_down_bar(_previous_high, _current_high, _previous_low, _current_low)=>
    _return = _previous_high > _current_high and _previous_low > _current_low

f_inside_bar(_previous_high, _current_high, _previous_low, _current_low)=>
    _return = _previous_high >= _current_high and _previous_low <= _current_low

f_outside_bar(_previous_high, _current_high, _previous_low, _current_low)=>
    _return = _previous_high <= _current_high and _previous_low >= _current_low

//--
f_swing_high(_previous_high, _current_high, _previous_low, _current_low)=>
    _condition_00 = f_up_bar(_previous_high[1], _current_high[1], _previous_low[1], _current_low[1]) and f_down_bar(_previous_high, _current_high, _previous_low, _current_low)
    _condition_01 = f_outside_bar(_previous_high[1], _current_high[1], _previous_low[1], _current_low[1]) and f_down_bar(_previous_high, _current_high, _previous_low, _current_low)
    _condition_02 = f_inside_bar(_previous_high[1], _current_high[1], _previous_low[1], _current_low[1]) and f_down_bar(_previous_high, _current_high, _previous_low, _current_low)
    _condition_03 = f_up_bar(_previous_high[1], _current_high[1], _previous_low[1], _current_low[1]) and f_inside_bar(_previous_high, _current_high, _previous_low, _current_low) and close[0] < hl2[1]
    _condition_04 = f_outside_bar(_previous_high, _current_high, _previous_low, _current_low) 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(_previous_high, _current_high, _previous_low, _current_low)=>
    _condition_00 = f_down_bar(_previous_high[1], _current_high[1], _previous_low[1], _current_low[1])      and f_up_bar(_previous_high, _current_high, _previous_low, _current_low)
    _condition_01 = f_outside_bar(_previous_high[1], _current_high[1], _previous_low[1], _current_low[1])   and f_up_bar(_previous_high, _current_high, _previous_low, _current_low)
    _condition_02 = f_inside_bar(_previous_high[1], _current_high[1], _previous_low[1], _current_low[1])    and f_up_bar(_previous_high, _current_high, _previous_low, _current_low)
    _condition_03 = f_down_bar(_previous_high[1], _current_high[1], _previous_low[1], _current_low[1])      and f_inside_bar(_previous_high, _current_high, _previous_low, _current_low) and close[0] > hl2[1]
    _condition_04 = f_outside_bar(_previous_high, _current_high, _previous_low, _current_low)               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_lvl0 = f_swing_high(high[1], high, low[1], low) ? highest(3) : na
swings_low_lvl0 = f_swing_low(high[1], high, low[1], low) ? lowest(3) : na

swing_chart_lvl0 = f_swingchart(swings_high_lvl0, swings_low_lvl0)
zigzag_lvl0 = change(swing_chart_lvl0) != 0 ? swing_chart_lvl0 : na
zigzag_lvl0_trend = na(zigzag_lvl0_trend[1]) ? 1 : change(swing_chart_lvl0) > 0 ? 1 : change(swing_chart_lvl0) < 0 ? -1 : zigzag_lvl0_trend[1]

plotshape(title='Swing High 0'  , series=not SHOW_SWINGSIGNAL_LVL0 ? na : swings_high_lvl0  , style=shape.triangledown  , location=location.abovebar, color=red, transp=0, offset=-1)
plotshape(title='Swing Low 0'   , series=not SHOW_SWINGSIGNAL_LVL0 ? na : swings_low_lvl0   , style=shape.triangleup    , location=location.belowbar, color=lime, transp=0, offset=-1)
plot(title='Swing Chart 0'      , series=not SHOW_SWINGCHART_LVL0 ? na : swing_chart_lvl0   , color=change(swing_chart_lvl0) != 0 ? na : black  , transp=0, offset=-1)
plot(title='ZigZag 0'           , series=not SHOW_ZIGZAG_LVL0 ? na : zigzag_lvl0            , color=zigzag_lvl0_trend > 0 ? lime : red, transp=0, linewidth=1, offset=-1)

barcolor(title='Up Bar'         , color=not SHOW_BARCOLOR ? na : f_up_bar(high[1], high, low[1], low) ? lime : na        )
barcolor(title='Down Bar'       , color=not SHOW_BARCOLOR ? na : f_down_bar(high[1], high, low[1], low) ? red : na       )
barcolor(title='Inside Bar'     , color=not SHOW_BARCOLOR ? na : f_inside_bar(high[1], high, low[1], low) ? blue : na    )
barcolor(title='Outside Bar'    , color=not SHOW_BARCOLOR ? na : f_outside_bar(high[1], high, low[1], low) ? aqua : na   )

a = valuewhen(change(swing_chart_lvl0)!=0, swing_chart_lvl0, 3)
b = valuewhen(change(swing_chart_lvl0)!=0, swing_chart_lvl0, 2)
c = valuewhen(change(swing_chart_lvl0)!=0, swing_chart_lvl0, 1)
d = valuewhen(change(swing_chart_lvl0)!=0, swing_chart_lvl0, 0)

//darvas_upper = d < c and high > c ? max(a, max(b, max(c,d))) : d > c and low < c ? max(a, max(b, max(c,d))) : darvas_upper[1]
//darvas_lower = d < c and high > c ? min(a, min(b, min(c,d))) : d > c and low < c ? min(a, min(b, min(c,d))) : darvas_lower[1]
darvas_upper = d < c and high > c ? c : d > c and low < c ? max(a, max(b, max(c,d))) : darvas_upper[1]
darvas_lower = d < c and high > c ? min(a, min(b, min(c,d))) : d > c and low < c ? c : darvas_lower[1]

plot(darvas_upper, color=blue, transp=0, linewidth=2)
plot(darvas_lower, color=navy, transp=0, linewidth=2)
Thanks so much for making this! Do you have plans to add in breakout indicators or other features such as box formations?

example...
http://www.sethi.org/investments/darvas/sbp_non-java.phtml
Resposta
not at the moment
Resposta
Hi Ricardo,

It would be great if you can give some description how to use this indicator, when to enter and exit and what each color of the candles signifies. Thank you
+1 Resposta
SchopplMarcus RicardoSantos
@RicardoSantos, hello i found this code for the prorealtime plattform. can we use this in tradinview to?
i think they draw the darvas boxes very good. se here

k=50
once tth=undefined
once ttl=undefined
n=(k*2)-4
p=(n/2)-1
h1=dpo(high)
moyh=high-h1
hi=(moyh-moyh+(high)/n)*n
hi=(round(hi*100))/100
l1=dpo(low)
moyl=low-l1
lo=(moyl-moyl+(low)/n)*n
lo=(round(lo*100))/100
low1=(round(low*100))/100
high1=(round(high*100))/100
if barindex > 100 then
if box=1 and (high1>tth or low1<ttl) then
box=0
flag=0
endif
if box=0 and flag=0 and low1<=lo and low1<=lo and low1<=lo then
th=low1
flag=1
endif
if box=0 and flag=1 then
for zz=0 to 44
if lo<th or lo<th or lo<th then
flag=0
break
endif
if hi>hi and hi>hi and hi>hi then
box=1
ttl=th
tth=hi
break
endif
next
endif
else
tth=undefined
ttl=undefined
endif
if box=1 then
ba=ttl
else
ba=tth
endif
return ba coloured by box-1, tth coloured by box-1, ttl coloured by box-1
Resposta
Início Rastreador de Fundamentos Rastreador Forex Rastreador de criptomoedas Calendário econômico Shows Como Funciona Recursos gráficos Preços Regras da Casa Moderadores Soluções para sites e corretoras Widgets Soluções em Gráficos Biblioteca de Gráficos Lightweight Central de Ajuda Indique um amigo Solicitação de recurso Blog & Notícias Twitter
Perfil Configurações de perfil Conta e cobrança Indique um amigo Meus Tíquetes de Suporte Central de Ajuda Ideias Publicadas Seguidores Seguindo Mensagens Privadas Conversa Deslogar