Advertisement
andypartridge47

BTC EMA 12, 22, 200

Dec 30th, 2024
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. //@version=6
  2. strategy('BTC EMA 12, 22, 200', overlay = true)
  3.  
  4. ema12 = ta.ema(close, 12)
  5. ema22 = ta.ema(close, 22)
  6. ema200 = ta.ema(close, 200)
  7.  
  8. // Declare bandColor variable
  9. var color bandColor = na
  10.  
  11. // Entry conditions
  12. longCondition = ema12 > ema22 and ema22 > ema200
  13. shortCondition = ema12 < ema22 and ema22 < ema200
  14.  
  15. // Impulsive candle detection parameters
  16. length = input(10, title="Length for Average Calculation")
  17. sizeMultiplier = input(0.5, title="Size Multiplier")
  18. volumeMultiplier = input(1.5, title="Volume Multiplier")
  19. bodyRatio = input(0.7, title="Body-to-Wick Ratio")
  20.  
  21. // Averages
  22. avgRange = ta.sma(ta.tr, length)
  23. avgVolume = ta.sma(volume, length)
  24.  
  25. // Candle characteristics
  26. candleRange = high - low
  27. candleBody = math.abs(close - open)
  28.  
  29. // Conditions for impulsive candle
  30. isImpulsiveSize = candleRange > avgRange * sizeMultiplier
  31. isImpulsiveVolume = volume > avgVolume * volumeMultiplier
  32. isImpulsiveBody = candleBody > candleRange * bodyRatio
  33.  
  34. // Impulsive candle condition
  35. isImpulsiveCandle = isImpulsiveSize and isImpulsiveVolume and isImpulsiveBody
  36.  
  37. // Entry
  38. if longCondition
  39. bandColor := color.green
  40. strategy.entry('Long', strategy.long)
  41.  
  42. if shortCondition
  43. bandColor := color.red
  44. strategy.entry('Short', strategy.short)
  45.  
  46. // Long position, bullish impulsive candle, and in profit Re-enter immediately.
  47. if (strategy.position_size > 0 and isImpulsiveCandle and close > open and strategy.position_avg_price < close)
  48.  
  49. strategy.close('Long')
  50. strategy.entry('Long', strategy.long)
  51.  
  52. // Short position, bearish impulsive candle, and in profit Re-enter immediately.
  53. if (strategy.position_size < 0 and isImpulsiveCandle and close < open and strategy.position_avg_price > close)
  54.  
  55. strategy.close('Short')
  56. strategy.entry('Short', strategy.short)
  57.  
  58. // Plots
  59. plot(ema12, color = bandColor, linewidth = 1)
  60. plot(ema22, color = bandColor, linewidth = 3)
  61. plot(ema200, color = color.blue, linewidth = 3, title = '200 EMA')
  62. barcolor(color=isImpulsiveCandle ? color.orange : na)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement