OPEN-SOURCE SCRIPT

KANG NUR

Theo zrtreder
//version=5
strategy("BB Breakout with MA 100 Strategy", overlay=true)

// Parameter Bollinger Bands
length = input(20, title="BB Length")
stdDev = input(2.0, title="BB Standard Deviation")

// Hitung Bollinger Bands
basis = ta.sma(close, length)
dev = stdDev * ta.stdev(close, length)
upperBB = basis + dev
lowerBB = basis - dev

// Hitung Moving Average 100
ma100 = ta.sma(close, 100)

// Logika untuk sinyal beli dan jual
longCondition = close > upperBB and close[1] <= upperBB[1]
shortCondition = close < lowerBB and close[1] >= lowerBB[1]

// Menentukan ukuran posisi (jumlah lot)
size = strategy.equity / close // Menentukan ukuran posisi berdasarkan ekuitas saat ini

// Eksekusi order
if (longCondition)
strategy.entry("Long", strategy.long, qty=size)

if (shortCondition)
strategy.entry("Short", strategy.short, qty=size)

// Menutup posisi ketika kondisi terbalik
if (longCondition and strategy.position_size < 0)
strategy.close("Short")

if (shortCondition and strategy.position_size > 0)
strategy.close("Long")

// Plotting
plot(upperBB, color=color.red, title="Upper BB")
plot(lowerBB, color=color.green, title="Lower BB")
plot(basis, color=color.blue, title="Basis BB")
plot(ma100, color=color.orange, title="MA 100")

// Menambahkan informasi ke grafik
bgcolor(longCondition ? color.new(color.green, 90) : na, title="Buy Signal Background")
bgcolor(shortCondition ? color.new(color.red, 90) : na, title="Sell Signal Background")
Bands and Channels

Mã nguồn mở

Theo tinh thần TradingView thực sự, tác giả của tập lệnh này đã xuất bản dưới dạng nguồn mở để các nhà giao dịch có thể hiểu và xác minh. Chúc mừng tác giả! Bạn có thể sử dụng miễn phí. Tuy nhiên, bạn cần sử dụng lại mã này theo Quy tắc nội bộ. Bạn có thể yêu thích nó để sử dụng nó trên biểu đồ.

Bạn muốn sử dụng tập lệnh này trên biểu đồ?

Thông báo miễn trừ trách nhiệm