Guest User

Untitled

a guest
Sep 18th, 2024
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1.  
  2. //@version=5
  3. strategy("GG", overlay=true)
  4.  
  5.  
  6. smalengt50 = 50
  7. emalengt12 = 12
  8. emalengt21 = 21
  9.  
  10.  
  11. sma50 = ta.sma(close, 50)
  12. ema12 = ta.ema(close, 12)
  13. ema21 = ta.ema(close, 21)
  14.  
  15.  
  16. // 1. Put these "na"s.
  17.  
  18. var line stopLossLine = na
  19. var line takeProfitLine = na
  20.  
  21.  
  22. // 2. Adding logic to manually reset or extend the lines based on if we are in a position or not.
  23.  
  24. if strategy.position_size == 0
  25. stopLossLine := na
  26. takeProfitLine := na
  27. else
  28. stopLossLine.set_x2(bar_index)
  29. takeProfitLine.set_x2(bar_index) //
  30.  
  31.  
  32. lc = ta.crossover(ema12, ema21)
  33. sc = ta.crossunder(ema12, ema21)
  34.  
  35.  
  36. if lc and strategy.position_size == 0
  37. stopLoss = close * (1 - 0.03)
  38.  
  39. takeProfit = close* (1 + 0.03)
  40.  
  41. // 3. Draw the start of the lines when we enter a position.
  42.  
  43. stopLossLine := line.new(bar_index, stopLoss, bar_index, stopLoss, color=color.red)
  44. takeProfitLine := line.new(bar_index, takeProfit, bar_index, takeProfit, color=color.green) //
  45.  
  46.  
  47. strategy.entry("Long", strategy.long, stop=stopLoss, limit=takeProfit)
  48. strategy.exit("SL/TP", "Long", stop=stopLoss, limit=takeProfit)
  49. if sc and strategy.position_size == 0
  50. stopLoss = close * (1 + 0.03)
  51.  
  52. takeProfit = close * (1 - 0.03)
  53.  
  54. // 3. Draw the start of the lines when we enter a position.
  55.  
  56. stopLossLine := line.new(bar_index, stopLoss, bar_index, stopLoss, color=color.red)
  57. takeProfitLine := line.new(bar_index, takeProfit, bar_index, takeProfit, color=color.green) //
  58.  
  59.  
  60. strategy.entry("Short", strategy.short, stop=stopLoss, limit=takeProfit)
  61. strategy.exit("SL/TP", "Short", stop=stopLoss, limit=takeProfit)
  62.  
  63.  
  64. bandColor50 = sma50 < sma50[1] ? #ffa73c : color.rgb(33, 184, 243)
  65. bandColor = ema12 > ema21 ? color.green : color.red
  66. plot(ema12, color=bandColor)
  67. plot(ema21, color=bandColor)
  68. plot(sma50, color=bandColor50)
Add Comment
Please, Sign In to add comment