1
fokus pada
0
Pengikut

Saya sedang mempelajari kode PINE. Apa saja masalah dengan pengaturan stop loss? Stop loss tidak dieksekusi selama backtesting, tetapi dieksekusi selama trading riil. Namun, order berikutnya tidak dit...

Dibuat di: 2024-10-22 05:50:32, diperbarui pada: 2024-10-22 05:51:23
comments   0
hits   509

//@version=5 strategy(“RSI(6) Buy at 30, EMA(34) Sell with Stop Loss”, overlay=true)

// Pengaturan parameter rsiPeriod = 6 emaPeriod = 54 buyLevel = 30 positionSize = 0.02

// Menghitung RSI dan EMA rsiValue = ta.rsi(close, rsiPeriod) emaValue = ta.ema(close, emaPeriod)

/ Kondisi Pembelian: RSI di bawah 30 buySignal = ta.crossunder(rsiValue, buyLevel)

// Kondisi jual: harga lebih tinggi dari EMA 54 sellSignal = close > emaValue

// Mencatat harga bukaan var float entryPrice = na

// Membeli logika: hanya melakukan lebih banyak if (buySignal and strategy.position_size == 0) strategy.entry(“Buy”, strategy.long, qty=positionSize) entryPrice: = close // Mencatat harga buka posisi saat membeli

// Stop Loss Logic: Set Stop Loss menjadi 0.5% if (strategy.position_size > 0) stopLossPrice = entryPrice * 0.995 // 0.5% Stop Loss if (close <= stopLossPrice) strategy.close (((“Buy”, comment=“Stop Loss”) // Hentikan kerugian posisi setara

// Logika posisi terjal: harga lebih tinggi dari EMA 54 saat posisi terjal if (strategy.position_size > 0 and sellSignal) strategy.close ((“Buy”, comment=“Take Profit”) // mencapai posisi terendah