xmd79

MACD+Indicato

Oct 15th, 2021
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © sonnyparlin
  3.  
  4. //@version=5
  5. indicator(shorttitle='MACD+Indicator', title='MACD Indicator', overlay=true)
  6.  
  7. [macdLine, signalLine, histLine] = ta.macd(close, 12, 26, 9)
  8. macdLineBottom = input.float(-180, title="Enter when MACD line is > than (x)")
  9. enterLong = ta.crossover(macdLine,signalLine) and macdLine < macdLineBottom
  10.  
  11. // Enter long
  12. var float entryPrice = na
  13. if enterLong
  14. entryPrice := close
  15. label.new(bar_index,
  16. low,
  17. "Go Long ▲",
  18. color=color.lime,
  19. size = size.normal,
  20. style=label.style_label_up)
  21.  
  22. exitWithProfit = input.float(2, title='Signal with at least (x%) profit')/100
  23. macdLineTop = input.float(180, title="Exit when MACD line is > than (x)")
  24. exitCond1 = ta.crossunder(macdLine,signalLine) and macdLine > macdLineTop
  25. exitCond2 = (close - entryPrice) / close > exitWithProfit
  26. exitLong = exitCond1 and exitCond2
  27.  
  28. if exitLong
  29. label.new(bar_index,
  30. high,
  31. "Exit Long ▼",
  32. color=color.red,
  33. size = size.normal,
  34. style=label.style_label_down)
Advertisement
Add Comment
Please, Sign In to add comment