OPEN-SOURCE SCRIPT
Telah dikemas kini

Optimized Neural Network Strategy

//version=5
strategy("Optimized Neural Network Strategy", overlay=true, initial_capital=1000, default_qty_type=strategy.percent_of_equity, default_qty_value=15)

// تعریف ورودی‌ها
emaLength = input(200, title="EMA Length")
supertrendFactor = input(3, title="SuperTrend Factor")
supertrendATR = input(10, title="SuperTrend ATR Period")
rsiLength = input(14, title="RSI Length")
atrMultiplier = input(2, title="ATR Multiplier for Stop Loss")

// ورودی‌های ایچیموکو
tenkanLength = input(9, title="Tenkan Length")
kijunLength = input(26, title="Kijun Length")
senkouSpanBLength = input(52, title="Senkou Span B Length")

// تعریف بازه زمانی بک‌تست
startTime = timestamp(2022, 1, 1)
endTime = timestamp(2025, 1, 1)

// محاسبه اندیکاتورها
ema200 = ta.ema(close, emaLength)
[supertrend, supertrendDir] = ta.supertrend(supertrendFactor, supertrendATR)
rsi = ta.rsi(close, rsiLength)
atr = ta.atr(14)

// محاسبه ایچیموکو
tenkan = ta.sma(high + low, tenkanLength)
kijun = ta.sma(high + low, kijunLength)
senkouSpanA = (tenkan + kijun) / 2
senkouSpanB = ta.sma(high + low, senkouSpanBLength)

// تعیین شرایط خرید و فروش
longCondition = ta.crossover(close, ema200) and ta.crossover(supertrendDir, 0) and rsi > 50 and close > senkouSpanA and time >= startTime and time <= endTime
shortCondition = ta.crossunder(close, ema200) and ta.crossunder(supertrendDir, 0) and rsi < 50 and close < senkouSpanA and time >= startTime and time <= endTime

// حد ضرر و حد سود
longStopLoss = close - (atr * atrMultiplier)
shortStopLoss = close + (atr * atrMultiplier)
longTakeProfit = close + (atr * atrMultiplier * 2)
shortTakeProfit = close - (atr * atrMultiplier * 2)

// اجرای معاملات
if longCondition
strategy.entry("Long", strategy.long)
strategy.exit("Take Profit", from_entry="Long", limit=longTakeProfit, stop=longStopLoss)
label.new(x=time, y=low, text="🔵 خرید", color=color.blue, textcolor=color.white, size=size.small, style=label.style_label_down)

if shortCondition
strategy.entry("Short", strategy.short)
strategy.exit("Take Profit", from_entry="Short", limit=shortTakeProfit, stop=shortStopLoss)
label.new(x=time, y=high, text="🔴 فروش", color=color.red, textcolor=color.white, size=size.small, style=label.style_label_up)

// نمایش اندیکاتورها
plot(ema200, title="EMA 200", color=color.blue)
plot(supertrend, title="SuperTrend", color=color.green)
plot(tenkan, title="Tenkan-sen", color=color.red)
plot(kijun, title="Kijun-sen", color=color.orange)
plot(senkouSpanA, title="Senkou Span A", color=color.green, style=plot.style_stepline)
plot(senkouSpanB, title="Senkou Span B", color=color.red, style=plot.style_stepline)
Nota Keluaran
//version=5
strategy("Optimized Neural Network Strategy v2", overlay=true, initial_capital=1000, default_qty_type=strategy.percent_of_equity, default_qty_value=15)

// ورودی‌های اندیکاتورها
emaLength = input(200, title="EMA Length")
supertrendFactor = input(3, title="SuperTrend Factor")
supertrendATR = input(10, title="SuperTrend ATR Period")
rsiLength = input(14, title="RSI Length")
atrMultiplier = input(2, title="ATR Multiplier for Stop Loss")

// ایچیموکو
tenkanLength = input(9, title="Tenkan Length")
kijunLength = input(26, title="Kijun Length")
senkouSpanBLength = input(52, title="Senkou Span B Length")

// بک‌تست تایم‌فریم
startTime = timestamp(2022, 1, 1)
endTime = timestamp(2025, 1, 1)

// محاسبه اندیکاتورها
ema200 = ta.ema(close, emaLength)
[supertrend, supertrendDir] = ta.supertrend(supertrendFactor, supertrendATR)
rsi = ta.rsi(close, rsiLength)
atr = ta.atr(14)

// ایچیموکو - محاسبه‌ی تنکان، کیجون و سنکو اسپن‌ها
tenkan = ta.sma(high + low, tenkanLength)
kijun = ta.sma(high + low, kijunLength)
senkouSpanA = (tenkan + kijun) / 2
senkouSpanB = ta.sma(high + low, senkouSpanBLength)
chikouSpan = close[26] // چیکو اسپن

// شرایط ورود و خروج معامله
longCondition = ta.crossover(close, ema200) and ta.crossover(supertrendDir, 0) and rsi > 50 and close > senkouSpanA and time >= startTime and time <= endTime
shortCondition = ta.crossunder(close, ema200) and ta.crossunder(supertrendDir, 0) and rsi < 50 and close < senkouSpanA and time >= startTime and time <= endTime

// حد ضرر و حد سود بر اساس ATR
longStopLoss = close - (atr * atrMultiplier)
shortStopLoss = close + (atr * atrMultiplier)
longTakeProfit = close + (atr * atrMultiplier * 2)
shortTakeProfit = close - (atr * atrMultiplier * 2)

// اجرای معاملات
if longCondition
strategy.entry("Long", strategy.long)
strategy.exit("Take Profit", from_entry="Long", limit=longTakeProfit, stop=longStopLoss)
label.new(x=time, y=low, text="🔵 خرید", color=color.blue, textcolor=color.white, size=size.small, style=label.style_label_down)
alert("سیگنال خرید! قیمت: " + str.tostring(close), alert.freq_once_per_bar)

if shortCondition
strategy.entry("Short", strategy.short)
strategy.exit("Take Profit", from_entry="Short", limit=shortTakeProfit, stop=shortStopLoss)
label.new(x=time, y=high, text="🔴 فروش", color=color.red, textcolor=color.white, size=size.small, style=label.style_label_up)
alert("سیگنال فروش! قیمت: " + str.tostring(close), alert.freq_once_per_bar)

// نمایش اندیکاتورها
plot(ema200, title="EMA 200", color=color.blue)
plot(supertrend, title="SuperTrend", color=color.green)
plot(tenkan, title="Tenkan-sen", color=color.red)
plot(kijun, title="Kijun-sen", color=color.orange)
plot(senkouSpanA, title="Senkou Span A", color=color.green, style=plot.style_stepline)
plot(senkouSpanB, title="Senkou Span B", color=color.red, style=plot.style_stepline)
plot(chikouSpan, title="Chikou Span", color=color.purple, style=plot.style_dotted)

Penafian