//@version=5
indicator("استراتيجية الشراء عند الهبوط (أي عملة)", overlay=true)
// === المدخلات ===
stochKLen = input.int(14, "طول %K الاستوكاستيكي")
stochDLen = input.int(3, "طول %D الاستوكاستيكي")
stochSmooth = input.int(3, "تنعيم الاستوكاستيكي")
buyZone = input.float(0.98, "منطقة الشراء % (مثال: 0.98 = 2% أقل)", step=0.01)
tpMultiplier = input.float(1.05, "نسبة جني الأرباح % (مثال: 1.05 = 5% أعلى)", step=0.01)
slMultiplier = input.float(0.97, "نسبة وقف الخسارة % (مثال: 0.97 = 3% أقل)", step=0.01)
// === المؤشر الاستوكاستيكي ===
k = ta.sma(ta.stoch(close, high, low, stochKLen), stochSmooth)
d = ta.sma(k, stochDLen)
// === المستويات الديناميكية ===
var float entryPrice = na
var bool inTrade = false
// === شروط الشراء ===
buyCondition = ta.crossover(k, d) and k < 80
if (buyCondition and not inTrade)
entryPrice := close
inTrade := true
// === مستويات TP و SL ===
takeProfitPrice = entryPrice * tpMultiplier
stopLossPrice = entryPrice * slMultiplier
// === شروط الخروج ===
exitConditionTP = inTrade and close >= takeProfitPrice
exitConditionSL = inTrade and close <= stopLossPrice
if (exitConditionTP or exitConditionSL)
inTrade := false
entryPrice := na
// === الرسوم البيانية ===
plotshape(buyCondition and not inTrade, title="إشارة شراء", location=location.belowbar, color=color.green, style=shape.labelup, text="اشترِ")
plotshape(exitConditionTP, title="جني الأرباح", location=location.abovebar, color=color.red, style=shape.labeldown, text="TP")
plotshape(exitConditionSL, title="وقف الخسارة", location=location.abovebar, color=color.orange, style=shape.labeldown, text="SL")
plot(entryPrice, title="سعر الدخول", color=color.new(color.green, 60))
plot(inTrade ? takeProfitPrice : na, title="مستوى جني الأرباح", color=color.new(color.red, 60), style=plot.style_line)
plot(inTrade ? stopLossPrice : na, title="مستوى وقف الخسارة", color=color.new(color.orange, 60), style=plot.style_line)
#pinescript #Write2Earn