Advertisement
andypartridge47

POPCAT EMA Crossover Strategy

Oct 21st, 2024
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. //@version=5
  2. strategy("POPCAT EMA Crossover Strategy", overlay=true, calc_on_every_tick=true)
  3.  
  4. // EMA settings
  5. emaFastPeriod = 12
  6. emaSlowPeriod = 21
  7. emaFast = ta.ema(close, emaFastPeriod)
  8. emaSlow = ta.ema(close, emaSlowPeriod)
  9.  
  10. // Entry amount input
  11. entryAmount = input.float(10, title="Entry Amount", minval=10)
  12.  
  13. // Buy and sell conditions
  14. buyCondition = ta.crossover(emaFast, emaSlow)
  15. sellCondition = ta.crossunder(emaFast, emaSlow)
  16.  
  17. // Close position on EMA cross (live)
  18. if (buyCondition and strategy.position_size <= 0) // If buy condition and no long position
  19. stopLoss = close * (1 - 0.03) // Calculate stop loss
  20. takeProfit = close * (1 + 0.03) // Calculate take profit
  21. strategy.entry("Long", strategy.long, qty=entryAmount)
  22. strategy.exit("SL / TP", "Long", stop=stopLoss, limit=takeProfit)
  23.  
  24. if (sellCondition and strategy.position_size >= 0) // If sell condition and no short position
  25. stopLoss = close * (1 + 0.03) // Calculate stop loss
  26. takeProfit = close * (1 - 0.03) // Calculate take profit
  27. strategy.entry("Short", strategy.short, qty=entryAmount)
  28. strategy.exit("SL / TP", "Short", stop=stopLoss, limit=takeProfit)
  29.  
  30. // Plot EMAs on chart
  31. bandColor = emaFast > emaSlow ? color.green : color.red
  32. plotFast = plot(emaFast, color=bandColor, linewidth=1, title="EMA 12")
  33. plotSlow = plot(emaSlow, color=bandColor, linewidth=3, title="EMA 21")
  34.  
  35. // Fill the area between the EMAs with 25% opacity
  36. fill(plotFast, plotSlow, color=emaFast > emaSlow ? color.new(color.green, 75) : color.new(color.red, 75))
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement