Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. study(title='[RS]Accumulation and Distribution Divergence V0')
  2.  
  3. smooth = input(1)
  4.  
  5. f_top_fractal(_src)=>_src[4] < _src[2] and _src[3] < _src[2] and _src[2] > _src[1] and _src[2] > _src[0]
  6. f_bot_fractal(_src)=>_src[4] > _src[2] and _src[3] > _src[2] and _src[2] < _src[1] and _src[2] < _src[0]
  7. f_fractalize(_src)=>f_top_fractal(_src) ? 1 : f_bot_fractal(_src) ? -1 : 0
  8.  
  9. hist = sma(cum(close==high and close==low or high==low ? 0 : ((2*close-low-high)/(high-low))*volume), smooth)
  10.  
  11. fractal_top = f_fractalize(hist) > 0 ? hist[2] : na
  12. fractal_bot = f_fractalize(hist) < 0 ? hist[2] : na
  13.  
  14. high_prev = valuewhen(fractal_top, hist[2], 1)
  15. high_price = valuewhen(fractal_top, high[2], 1)
  16. low_prev = valuewhen(fractal_bot, hist[2], 1)
  17. low_price = valuewhen(fractal_bot, low[2], 1)
  18.  
  19. regular_bearish_div = fractal_top and high[2] > high_price and hist[2] < high_prev
  20. hidden_bearish_div = fractal_top and high[2] < high_price and hist[2] > high_prev
  21. regular_bullish_div = fractal_bot and low[2] < low_price and hist[2] > low_prev
  22. hidden_bullish_div = fractal_bot and low[2] > low_price and hist[2] < low_prev
  23.  
  24. plot(title='HIST', series=hist, color=black)
  25. plot(title='H F', series=fractal_top, color=regular_bearish_div or hidden_bearish_div ? black : silver, offset=-2)
  26. plot(title='L F', series=fractal_bot, color=regular_bullish_div or hidden_bullish_div ? black : silver, offset=-2)
  27. plot(title='H D', series=fractal_top, style=circles, color=regular_bearish_div or hidden_bearish_div ? maroon : gray, linewidth=3, offset=-2)
  28. plot(title='L D', series=fractal_bot, style=circles, color=regular_bullish_div or hidden_bullish_div ? green : gray, linewidth=3, offset=-2)
  29.  
  30. plotshape(title='+RBD', series=regular_bearish_div ? hist[2] : na, text='R', style=shape.labeldown, location=location.absolute, color=maroon, textcolor=white, offset=-2)
  31. plotshape(title='+HBD', series=hidden_bearish_div ? hist[2] : na, text='H', style=shape.labeldown, location=location.absolute, color=maroon, textcolor=white, offset=-2)
  32. plotshape(title='-RBD', series=regular_bullish_div ? hist[2] : na, text='R', style=shape.labelup, location=location.absolute, color=green, textcolor=white, offset=-2)
  33. plotshape(title='-HBD', series=hidden_bullish_div ? hist[2] : na, text='H', style=shape.labelup, location=location.absolute, color=green, textcolor=white, offset=-2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement