atnX_2
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © melihtuna
// This strategy has been prepared with what investercoin taught us. Endless thanks to him.

//@version=5
indicator("atnX_2", overlay=true)

Ema5=ta.ema(close,5)
Ema10=ta.ema(close,10)
Rsi14=ta.rsi(close,14)
Rsi50=ta.rsi(close,21)

condition = input.string(title="Ichimoku Fiyat Davranışı", defval="Fiyat kapanışı bulut üstünde ise al", options=["Fiyat en yüksek değeri bulut içine girdiyse al", "Fiyat kapanışı bulut içinde ya da üstünde ise al", "Fiyat kapanışı bulut üstünde ise al"], group="Ichimoku Ayarlar")
conversionPeriods = input.int(9, minval=1, title="Conversion Line Length", group="Ichimoku Ayarlar")
basePeriods = input.int(26, minval=1, title="Base Line Length", group="Ichimoku Ayarlar")
laggingSpan2Periods = input.int(52, minval=1, title="Leading Span B Length", group="Ichimoku Ayarlar")
displacement = input.int(26, minval=1, title="Displacement", group="Ichimoku Ayarlar")

donchian(len) => math.avg(ta.lowest(len), ta.highest(len))
conversionLine = donchian(conversionPeriods)
baseLine = donchian(basePeriods)
leadLine1 = math.avg(conversionLine, baseLine)
leadLine2 = donchian(laggingSpan2Periods)

status=0

ichimokuConfirm = condition == "Fiyat kapanışı bulut üstünde ise al" ? close > leadLine1[displacement - 1] and close > leadLine2[displacement - 1] : condition == "Fiyat en yüksek değeri bulut içine girdiyse al" ? leadLine1[displacement - 1] > leadLine2[displacement - 1] ? ((high < leadLine1[displacement - 1] and high > leadLine2[displacement - 1]) or (close > leadLine2[displacement - 1])) : ((high > leadLine1[displacement - 1] and high < leadLine2[displacement - 1]) or (close > leadLine1[displacement - 1])) : leadLine1[displacement - 1] > leadLine2[displacement - 1] ? close > leadLine2[displacement - 1] : close > leadLine1[displacement - 1]

Stg_BuyCondition = ta.crossover(Ema5,Ema10) and ichimokuConfirm
Stg_SellCondition = ta.crossover(Ema10,Ema5)


intBuyCond = Stg_BuyCondition ? 1 : 0
intSellCond = Stg_SellCondition ? 1 : 0

chngBuy = ta.change(intBuyCond)
chngSell = ta.change(intSellCond)

status:= chngBuy and intBuyCond == 1 ? 1 : chngSell and intSellCond == 1 ? 0 : status[1]

p1 = plot(leadLine1, offset = displacement - 1, color=#A5D6A7, title="Leading Span A")
p2 = plot(leadLine2, offset = displacement - 1, color=#EF9A9A, title="Leading Span B")
fill(p1, p2, color = leadLine1 > leadLine2 ? color.rgb(67, 160, 71, 90) : color.rgb(244, 67, 54, 90))

plotshape(ta.change(status) and intBuyCond == 1, title="Buy", text="Buy", location=location.belowbar, style=shape.labelup, size=size.tiny, color=color.blue, textcolor=color.white)
plotshape(ta.change(status) and intSellCond == 1, title="Sell", text="Sell", location=location.abovebar, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white)


alertcondition(ta.change(status) and intBuyCond == 1, title="Buy Alert")
alertcondition(ta.change(status) and intSellCond == 1, title="Sell Alert")