Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- strategy("POPCAT EMA Crossover Strategy", overlay=true, calc_on_every_tick=true)
- // EMA settings
- emaFastPeriod = 12
- emaSlowPeriod = 21
- emaFast = ta.ema(close, emaFastPeriod)
- emaSlow = ta.ema(close, emaSlowPeriod)
- // Entry amount input
- entryAmount = input.float(10, title="Entry Amount", minval=10)
- // Buy and sell conditions
- buyCondition = ta.crossover(emaFast, emaSlow)
- sellCondition = ta.crossunder(emaFast, emaSlow)
- // Close position on EMA cross (live)
- if (buyCondition and strategy.position_size <= 0) // If buy condition and no long position
- stopLoss = close * (1 - 0.03) // Calculate stop loss
- takeProfit = close * (1 + 0.03) // Calculate take profit
- strategy.entry("Long", strategy.long, qty=entryAmount)
- strategy.exit("SL / TP", "Long", stop=stopLoss, limit=takeProfit)
- if (sellCondition and strategy.position_size >= 0) // If sell condition and no short position
- stopLoss = close * (1 + 0.03) // Calculate stop loss
- takeProfit = close * (1 - 0.03) // Calculate take profit
- strategy.entry("Short", strategy.short, qty=entryAmount)
- strategy.exit("SL / TP", "Short", stop=stopLoss, limit=takeProfit)
- // Plot EMAs on chart
- bandColor = emaFast > emaSlow ? color.green : color.red
- plotFast = plot(emaFast, color=bandColor, linewidth=1, title="EMA 12")
- plotSlow = plot(emaSlow, color=bandColor, linewidth=3, title="EMA 21")
- // Fill the area between the EMAs with 25% opacity
- fill(plotFast, plotSlow, color=emaFast > emaSlow ? color.new(color.green, 75) : color.new(color.red, 75))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement