Thanhanh9/Test / Sonic.pine
download
raw
3.17 kB
//@version=6
strategy("Sonic R System Pro", overlay=true, initial_capital=200000, default_qty_type=strategy.percent_of_equity, default_qty_value=1.0, currency=currency.USD)
// --- 1. CÀI ĐẶT THÔNG SỐ (INPUTS) ---
lenDragon = 34
lenTrend = 89
lenFilter = 200
// --- 2. TÍNH TOÁN CHỈ BÁO ---
// Dải Rồng (The Dragon)
ema34High = ta.ema(high, lenDragon)
ema34Low = ta.ema(low, lenDragon)
ema34Close = ta.ema(close, lenDragon)
// Các đường xu hướng chủ đạo
ema89 = ta.ema(close, lenTrend)
ema200 = ta.ema(close, lenFilter)
// --- 4. HIỂN THỊ TRỰC QUAN (VISUALS) ---
// Vẽ dải Rồng
p_high = plot(ema34High, "Rồng Trên (High)", color=color.new(#2962FF, 60))
p_low = plot(ema34Low, "Rồng Dưới (Low)", color=color.new(#2962FF, 60))
fill(p_high, p_low, color=color.new(color.gray, 90))
plot(ema89, "EMA 89 Trend", color=color.orange, linewidth=2)
plot(ema200, "EMA 200 Filter", color=color.new(color.white, 30), linewidth=3)
// --- 5. CHIẾN THUẬT VÀO LỆNH (STRATEGY ENTRY) ---
// Tín hiệu Mua: Giá mở cửa trong dải Rồng + Giá đóng cửa trên dải Rồng
bool longCondition = (open >= ema34Low and open <= ema34High) and (close > ema34High)
// Tín hiệu Bán: Giá mở cửa trong dải Rồng + Giá đóng cửa dưới dải Rồng
bool shortCondition = (open >= ema34Low and open <= ema34High) and (close < ema34Low)
// Biến lưu trữ điểm dừng lỗ và giá vào lệnh
atrLength = input.int(14, "ATR Period")
atrValue = ta.atr(atrLength)
var float slPrice = na
var float entryPrice = na
var bool beActivated = false
// --- QUẢN LÝ LỆNH LONG ---
if longCondition and strategy.position_size == 0
entryPrice := close
slPrice := close - atrValue
beActivated := false
strategy.entry("Sonic_Long", strategy.long, comment="Dragon Buy")
strategy.exit("Exit_Long", "Sonic_Long", stop=slPrice, comment_loss="SL")
// Quản lý lệnh LONG đang mở
if strategy.position_size > 0
// Thoát sớm nếu đóng cửa dưới EMA 89
if close < ema89
strategy.close("Sonic_Long", comment="Exit MA89")
// Dời SL về BE khi giá đi được 1 ATR
if not beActivated and (close >= entryPrice + atrValue)
slPrice := entryPrice
beActivated := true
strategy.exit("Exit_Long", "Sonic_Long", stop=slPrice, comment_loss="BE")
// --- QUẢN LÝ LỆNH SHORT ---
if shortCondition and strategy.position_size == 0
entryPrice := close
slPrice := close + atrValue
beActivated := false
strategy.entry("Sonic_Short", strategy.short, comment="Dragon Sell")
strategy.exit("Exit_Short", "Sonic_Short", stop=slPrice, comment_loss="SL")
// Quản lý lệnh SHORT đang mở
if strategy.position_size < 0
// Thoát sớm nếu đóng cửa trên EMA 89
if close > ema89
strategy.close("Sonic_Short", comment="Exit MA89")
// Dời SL về BE khi giá đi được 1 ATR
if not beActivated and (close <= entryPrice - atrValue)
slPrice := entryPrice
beActivated := true
strategy.exit("Exit_Short", "Sonic_Short", stop=slPrice, comment_loss="BE")

Xet Storage Details

Size:
3.17 kB
·
Xet hash:
c66bd745825288827581c2df7e0ce73b825ad79a3d8c8fd7bcc012acbf22dc67

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.