SHARE
TWEET

MACD Offset

PineCoders Jan 25th, 2020 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //@version=4
  2. study(title="MACD", shorttitle="MACD")
  3.  
  4. // Getting inputs
  5. fast_length = input(title="Fast Length", type=input.integer, defval=12)
  6. slow_length = input(title="Slow Length", type=input.integer, defval=26)
  7. src = input(title="Source", type=input.source, defval=close)
  8. signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9)
  9. sma_source = input(title="Simple MA(Oscillator)", type=input.bool, defval=false)
  10. sma_signal = input(title="Simple MA(Signal Line)", type=input.bool, defval=false)
  11. // *** Added line.
  12. histoOffset = input(0, "Histogram line offset")
  13.  
  14. // Plot colors
  15. col_grow_above = #26A69A
  16. col_grow_below = #FFCDD2
  17. col_fall_above = #B2DFDB
  18. col_fall_below = #EF5350
  19. col_macd = #0094ff
  20. col_signal = #ff6a00
  21.  
  22. // Calculating
  23. fast_ma = sma_source ? sma(src, fast_length) : ema(src, fast_length)
  24. slow_ma = sma_source ? sma(src, slow_length) : ema(src, slow_length)
  25. macd = fast_ma - slow_ma
  26. signal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length)
  27. hist = macd - signal
  28.  
  29. plot(hist, title="Histogram", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below) ), transp=0 )
  30. plot(macd, title="MACD", color=col_macd, transp=0)
  31. plot(signal, title="Signal", color=col_signal, transp=0)
  32. // *** Added line.
  33. plot(hist, "Histo line", color.purple, offset = histoOffset)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top