You are on page 1of 2

//@version=5

strategy("Keltner Channels Strategy", overlay=true)

length = input(89, title="Length")


lenght2 = input(34, title="Lenght2")
mult = input(2, title="Multiplier")
mult2 = input(3, title="Multplier2")

basis = ta.sma(close, length)


basis2 = ta.sma(close,lenght2)
atr = ta.atr(length)

upper_band = basis + (mult * atr)


upper_band2 = basis + (mult2 * atr)
lower_band = basis - (mult * atr)
lower_band2 = basis - (mult2 * atr)

plot(basis, color=color.blue, title="Basis")


plot(basis2, color=color.white, title="Basis2")
plot(upper_band, color=color.red, title="Upper Band")
plot(lower_band, color=color.green, title="Lower Band")
plot(upper_band2, color=color.red, title="Upper Band Ext")
plot(lower_band2, color=color.green, title="Lower Band Ext")

enterLong = ta.crossunder(low, lower_band)


exitLong = ta.crossover(close, basis2)

enterShort = ta.crossover(high, upper_band)


exitShort = ta.crossunder(close, basis2)

LongCondition = ta.crossunder (basis2, basis)


if (LongCondition)
strategy.entry("Long", strategy.long)
strategy.close("CloseL", when=exitLong)

ShortCondition = ta.crossover (basis2, basis)


if (ShortCondition)
strategy.entry("Short", strategy.short)
strategy.close("CloseS", when=exitShort)

AtivaTSLong = strategy.position_avg_price * 1.02


AtivaTSShort = strategy.position_avg_price *0.98
strategy.exit("Exit Long", "Long", trail_price = AtivaTSLong, trail_offset = 1 )
strategy.exit("Exit Short", "Short", trail_price = AtivaTSShort, trail_offset = 1 )

You might also like