Advertisement
andypartridge47

GG

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