Advertisement
Guest User

Untitled

a guest
Oct 25th, 2024
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. //@version=5
  2.  
  3. strategy("PEPE REAL SIZING TEST", overlay=true, initial_capital=100)
  4.  
  5. //// Inputs
  6. stopLossPercentage = input.float(0.2, title="Stop Loss Percentage") * 0.01
  7. takeProfitPercentage = input.float(0.2, title="Take Profit Percentage") * 0.01
  8.  
  9. //// Position SIze
  10. getBetSize(stop) =>
  11. onePercentCapital = strategy.equity * 0.02
  12. betSize = onePercentCapital / math.abs(close - stop)
  13.  
  14. //// Bands
  15. ema12 = ta.ema(close, 12)
  16. ema21 = ta.ema(close, 21)
  17.  
  18. //// Exit lines
  19. var line stopLossLine = na
  20. var line takeProfitLine = na
  21.  
  22. if strategy.position_size == 0
  23. stopLossLine := na
  24. takeProfitLine := na
  25. else
  26. stopLossLine.set_x2(bar_index)
  27. takeProfitLine.set_x2(bar_index)
  28.  
  29. // Logic
  30. //// Longs
  31. if ta.crossover(ema12, ema21) and strategy.position_size == 0
  32. stopLoss = close * (1 - stopLossPercentage)
  33. takeProfit = close * (1 + takeProfitPercentage)
  34.  
  35. stopLossLine := line.new(bar_index, stopLoss, bar_index, stopLoss, color=color.red)
  36. takeProfitLine := line.new(bar_index, takeProfit, bar_index, takeProfit, color=color.green)
  37.  
  38. strategy.entry("Long", strategy.long, getBetSize(stopLoss))
  39. strategy.exit("SL / TP", "Long", stop=stopLoss, limit=takeProfit)
  40.  
  41. //// Shorts
  42. if ta.crossunder(ema12, ema21) and strategy.position_size == 0
  43. stopLoss = close * (1 + stopLossPercentage)
  44. takeProfit = close * (1 - takeProfitPercentage)
  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. strategy.entry("Short", strategy.short, getBetSize(stopLoss))
  50. strategy.exit("SL / TP", "Short", stop=stopLoss, limit=takeProfit)
  51.  
  52. // Plots
  53. bandColor = ema12 > ema21 ? color.green : color.red
  54. plot(ema12, color=bandColor, linewidth=1)
  55. plot(ema21, color=bandColor, linewidth=3)
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement