rajath_pai

MACD Strategy With Histogram drew102

May 30th, 2025
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. //@version=3
  2. strategy("MACD", calc_on_order_fills=true, currency=currency.USD, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_value=0.0675)
  3.  
  4. // Getting inputs
  5. fastLength = input(title="Fast Length", type=integer, defval=12)
  6. slowlength = input(title="Slow Length", type=integer, defval=26)
  7. signalLength = input(title="Signal Smoothing", type=integer, minval = 1, maxval = 50, defval = 9)
  8.  
  9. // Calculating
  10. macd = ema(close, fastLength) - ema(close, slowlength)
  11. signal = ema(macd, signalLength)
  12. delta = macd - signal
  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. // Plot histogram
  23. plot(delta, title="Histogram", style=columns, color=(delta>=0 ? (delta[1] < delta ? col_grow_above : col_fall_above) : (delta[1] < delta ? col_grow_below : col_fall_below) ), transp=0 )
  24. plot(macd, title="MACD", color=col_macd, transp=0)
  25. plot(signal, title="Signal", color=col_signal, transp=0)
  26.  
  27. // Plot orders
  28. if (crossover(delta, 0))
  29. strategy.entry("buy", strategy.long)
  30. if (crossunder(delta, 0))
  31. strategy.entry("sell", strategy.short)
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
Advertisement
Add Comment
Please, Sign In to add comment