Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=6
- strategy('BTC EMA 12, 22, 200', overlay = true)
- ema12 = ta.ema(close, 12)
- ema22 = ta.ema(close, 22)
- ema200 = ta.ema(close, 200)
- // Declare bandColor variable
- var color bandColor = na
- // Entry conditions
- longCondition = ema12 > ema22 and ema22 > ema200
- shortCondition = ema12 < ema22 and ema22 < ema200
- // Impulsive candle detection parameters
- length = input(10, title="Length for Average Calculation")
- sizeMultiplier = input(0.5, title="Size Multiplier")
- volumeMultiplier = input(1.5, title="Volume Multiplier")
- bodyRatio = input(0.7, title="Body-to-Wick Ratio")
- // Averages
- avgRange = ta.sma(ta.tr, length)
- avgVolume = ta.sma(volume, length)
- // Candle characteristics
- candleRange = high - low
- candleBody = math.abs(close - open)
- // Conditions for impulsive candle
- isImpulsiveSize = candleRange > avgRange * sizeMultiplier
- isImpulsiveVolume = volume > avgVolume * volumeMultiplier
- isImpulsiveBody = candleBody > candleRange * bodyRatio
- // Impulsive candle condition
- isImpulsiveCandle = isImpulsiveSize and isImpulsiveVolume and isImpulsiveBody
- // Entry
- if longCondition
- bandColor := color.green
- strategy.entry('Long', strategy.long)
- if shortCondition
- bandColor := color.red
- strategy.entry('Short', strategy.short)
- // Long position, bullish impulsive candle, and in profit Re-enter immediately.
- if (strategy.position_size > 0 and isImpulsiveCandle and close > open and strategy.position_avg_price < close)
- strategy.close('Long')
- strategy.entry('Long', strategy.long)
- // Short position, bearish impulsive candle, and in profit Re-enter immediately.
- if (strategy.position_size < 0 and isImpulsiveCandle and close < open and strategy.position_avg_price > close)
- strategy.close('Short')
- strategy.entry('Short', strategy.short)
- // Plots
- plot(ema12, color = bandColor, linewidth = 1)
- plot(ema22, color = bandColor, linewidth = 3)
- plot(ema200, color = color.blue, linewidth = 3, title = '200 EMA')
- barcolor(color=isImpulsiveCandle ? color.orange : na)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement