
Đây là một hệ thống chiến lược giao dịch tự động dựa trên giao dịch hai đường cong. Hệ thống sử dụng đường trung bình di chuyển chỉ số 9 chu kỳ và 21 chu kỳ (EMA) làm chỉ số cốt lõi để giao dịch bằng cách nắm bắt tín hiệu giao nhau của hai đường cong. Hệ thống tích hợp quản lý dừng lỗ, đồng thời cung cấp hỗ trợ giao diện trực quan, có thể hiển thị trực quan tín hiệu giao dịch và mức giá quan trọng.
Chiến lược sử dụng EMA nhanh ((thời gian 9) và EMA chậm ((thời gian 21) để xây dựng hệ thống giao dịch. Khi EMA nhanh đi lên vượt qua EMA chậm, hệ thống tạo ra tín hiệu nhiều; Khi EMA nhanh đi xuống vượt qua EMA chậm, hệ thống tạo ra tín hiệu trống.
Đây là một hệ thống chiến lược giao chéo đồng tuyến được thiết kế hợp lý, logic rõ ràng. Bằng cách sử dụng tổng hợp các tín hiệu giao chéo EMA và cơ chế quản lý rủi ro, chiến lược này có thể thu được lợi nhuận trong thị trường xu hướng. Mặc dù có một số rủi ro vốn có, nhưng hướng tối ưu hóa được đề xuất có thể nâng cao hơn nữa sự ổn định và độ tin cậy của chiến lược.
/*backtest
start: 2019-12-23 08:00:00
end: 2024-12-04 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
//
// ██╗ █████╗ ██████╗ ██████╗ ██╗ ██╗ ██╗
// ██║ ██╔══██╗ ██╔═══██╗ ██╔══██╗ ██║ ██║ ██║
// ██║ ███████║ ██║ ██║ ██║ ██║ ██║ ██║ ██║
// ██║ ██╔══██║ ██║ ██║ ██║ ██║ ██║ ██║ ██║
// ███████╗ ██║ ██║ ╚██████╔╝ ██████╔╝ ╚██████╔╝ ██║
// ╚══════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═╝
//
// BTC-EMA做多策略(5分钟确认版) - 作者:LAODUI
// 版本:2.0
// 最后更新:2024
// ═══════════════════════════════════════════════════════════════════════════
strategy("EMA Cross Strategy", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
// 添加策略参数设置
var showLabels = input.bool(true, "显示标签", group="显示设置")
var stopLossPercent = input.float(5.0, "止损百分比", minval=0.1, maxval=20.0, step=0.1, group="风险管理")
var takeProfitPercent = input.float(10.0, "止盈百分比", step=0.1, group="风险管理")
// EMA参数设置
var emaFastLength = input.int(9, "快速EMA周期", minval=1, maxval=200, group="EMA设置")
var emaSlowLength = input.int(21, "慢速EMA周期", minval=1, maxval=200, group="EMA设置")
// 计算EMA
ema_fast = ta.ema(close, emaFastLength)
ema_slow = ta.ema(close, emaSlowLength)
// 绘制EMA线
plot(ema_fast, "快速EMA", color=color.blue, linewidth=2)
plot(ema_slow, "慢速EMA", color=color.red, linewidth=2)
// 检测交叉
crossOver = ta.crossover(ema_fast, ema_slow)
crossUnder = ta.crossunder(ema_fast, ema_slow)
// 格式化时间显示 (UTC+8)
utc8Time = time + 8 * 60 * 60 * 1000
timeStr = str.format("{0,date,MM-dd HH:mm}", utc8Time)
// 计算止损止盈价格
longStopLoss = strategy.position_avg_price * (1 - stopLossPercent / 100)
longTakeProfit = strategy.position_avg_price * (1 + takeProfitPercent / 100)
shortStopLoss = strategy.position_avg_price * (1 + stopLossPercent / 100)
shortTakeProfit = strategy.position_avg_price * (1 - takeProfitPercent / 100)
// 交易逻辑
if crossOver
if strategy.position_size < 0
strategy.close("做空")
strategy.entry("做多", strategy.long)
if showLabels
label.new(bar_index, high, text="做多入场\n" + timeStr + "\n入场价: " + str.tostring(close) + "\n止损价: " + str.tostring(longStopLoss) + "\n止盈价: " + str.tostring(longTakeProfit), color=color.green, textcolor=color.white, style=label.style_label_down, yloc=yloc.abovebar)
if crossUnder
if strategy.position_size > 0
strategy.close("做多")
strategy.entry("做空", strategy.short)
if showLabels
label.new(bar_index, low, text="做空入场\n" + timeStr + "\n入场价: " + str.tostring(close) + "\n止损价: " + str.tostring(shortStopLoss) + "\n止盈价: " + str.tostring(shortTakeProfit), color=color.red, textcolor=color.white, style=label.style_label_up, yloc=yloc.belowbar)
// 设置止损止盈
if strategy.position_size > 0 // 多仓止损止盈
strategy.exit("多仓止损止盈", "做多", stop=longStopLoss, limit=longTakeProfit)
if strategy.position_size < 0 // 空仓止损止盈
strategy.exit("空仓止损止盈", "做空", stop=shortStopLoss, limit=shortTakeProfit)