OPEN-SOURCE SCRIPT

SMA10 & SMA50 Crossover Strategy

104
//version=5
strategy("SMA10 & SMA50 Crossover Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)

// Calculate the SMAs
sma10 = ta.sma(close, 10)
sma50 = ta.sma(close, 50)

// Plot the SMAs on the chart
plot(sma10, color=color.blue, title="SMA10")
plot(sma50, color=color.red, title="SMA50")

// Define the crossover conditions
// Buy when SMA10 becomes >= SMA50 and the previous bar had SMA10 < SMA50
buySignal = (sma10 >= sma50) and (sma10[1] < sma50[1])
// Sell when SMA10 becomes <= SMA50 and the previous bar had SMA10 > sma50[1]
sellSignal = (sma10 <= sma50) and (sma10[1] > sma50[1])

// Generate entries based on the conditions
if buySignal
strategy.entry("Long", strategy.long)

if sellSignal
strategy.entry("Short", strategy.short)

إخلاء المسؤولية

لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.