
Chiến lược này là một chiến lược robot giao dịch dựa trên khu vực hoạt động của CDC. Nó sử dụng trung bình di chuyển chỉ số 12 chu kỳ và 26 chu kỳ (EMA) để xác định xu hướng thị trường khi EMA ngắn hạn làm nhiều hơn EMA dài hạn, thay vào đó là tháo lỗ. Chiến lược này sử dụng chiều rộng sóng thực trung bình (ATR) để thiết lập mức dừng và dừng động.
Chiến lược này là một chiến lược robot giao dịch dừng lỗ ATR dựa trên khu vực hoạt động CDC, sử dụng EMA để nắm bắt xu hướng thị trường, ATR để thiết lập mức dừng động và sử dụng phần trăm dừng lỗ cố định để kiểm soát rủi ro. Mặc dù chiến lược này có một số ưu điểm, nhưng vẫn có một số rủi ro và không gian cải tiến.
/*backtest
start: 2024-05-01 00:00:00
end: 2024-05-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("CDC Action Zone Trading Bot with ATR for Take Profit and 5% Stop Loss", overlay=true)
// ดึงข้อมูลราคาปิด
close_price = close
// คำนวณเส้น EMA 12 และ EMA 26
ema12 = ta.ema(close_price, 12)
ema26 = ta.ema(close_price, 26)
// คำนวณ ATR
atr_length = input.int(14, title="ATR Length")
atr = ta.atr(atr_length)
// กำหนด Multiplier สำหรับ ATR Trailing Stoploss
mult_atr_stoploss = input.float(2.5, title="ATR Stoploss Multiplier")
// คำนวณ ATR Trailing Stoploss
prev_stoploss = close_price
for i = 1 to 10
prev_stoploss := math.max(prev_stoploss, high[i] - mult_atr_stoploss * atr)
// กำหนด Take Profit เป็น ATR Trailing Stoploss
takeProfitPercent = input.float(10, title="Take Profit (%)") / 100
takeProfit = close_price + (close_price - prev_stoploss) * takeProfitPercent
// กำหนด Stop Loss เป็น 5% ของราคาปิดปัจจุบัน
stopLossPercent = input.float(5, title="Stop Loss (%)") / 100
stopLoss = close_price * stopLossPercent
// กำหนดสีแท่งกราฟ
buyColor = input.color(color.green, title="Buy Color")
sellColor = input.color(color.red, title="Sell Color")
neutralColor = input.color(color.gray, title="Neutral Color")
color = if (ema12 > ema26)
buyColor
else if (ema12 < ema26)
sellColor
else
neutralColor
// สัญญาณ Buy
buySignal = (color == buyColor) and (color[1] != buyColor)
// สัญญาณ Sell
sellSignal = (color == sellColor) and (color[1] != sellColor)
// เปิด Position Long
if (buySignal)
strategy.entry("Long", strategy.long)
// เปิด Position Short
if (sellSignal)
strategy.entry("Short", strategy.short)
// ปิด Position เมื่อถึง Take profit
if (strategy.position_size > 0 and close_price > takeProfit)
strategy.exit("Long", profit=takeProfit)
// ปิด Position เมื่อถึง Stop loss
if (strategy.position_size > 0 and close_price < stopLoss)
strategy.exit("Long", loss=stopLoss)
// ปิด Position เมื่อถึง Take profit
if (strategy.position_size < 0 and close_price < takeProfit)
strategy.exit("Short", profit=takeProfit)
// ปิด Position เมื่อถึง Stop loss
if (strategy.position_size < 0 and close_price > stopLoss)
strategy.exit("Short", loss=stopLoss)