Type/to search
1
Follow
0
Followers
Tôi đang học mã PINE. Có vấn đề gì với việc thiết lập lệnh dừng lỗ không? Lệnh dừng lỗ không được thực hiện trong quá trình kiểm tra ngược, nhưng được thực hiện trong quá trình giao dịch thực tế. Tuy ...
Help
Created 2024-10-22 05:50:32  Updated 2024-10-22 05:51:23
 0
 765

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

// Cài đặt tham số
rsiPeriod = 6
emaPeriod = 54
buyLevel = 30
positionSize = 0.02

// Xác định RSI và EMA
rsiValue = ta.rsi(close, rsiPeriod)
emaValue = ta.ema(close, emaPeriod)

Điều kiện mua: RSI dưới 30
buySignal = ta.crossunder(rsiValue, buyLevel)

// Điều kiện bán: Giá cao hơn EMA 54
sellSignal = close > emaValue

// Ghi lại giá mở kho
var float entryPrice = na

// Buy logic: chỉ làm nhiều hơn
if (buySignal and strategy.position_size == 0)
strategy.entry("Buy", strategy.long, qty=positionSize)
entryPrice: = close // Ghi lại giá mở khi mua

// Stop Loss Logic: thiết lập Stop Loss là 0.5%
if (strategy.position_size > 0)
stopLossPrice = entryPrice * 0.995 // 0.5% dừng lỗ
if (close <= stopLossPrice)
strategy.close (("Buy", comment="Stop Loss") // Giảm lỗ

// Logic giao dịch: giá giao dịch khi giao dịch cao hơn EMA 54
if (strategy.position_size > 0 and sellSignal)
strategy.close (("Buy", comment="Take Profit") // Đạt mức cân bằng

Related Recommendations
Comment
All comments (0)
No data
No data
  • 1
Forums
PINE Language
Get the app
iPhone Download
© 2015 - ∞ INVENTOR PTE LTD (SG)