
이 전략은 9주기 및 21주기 지수 이동 평균 ((EMA) 을 핵심 지표로 사용하는 쌍평선 교차에 기반한 지능형 거래 시스템입니다. 이 전략은 동적 손해 중지 장치를 통합하여 EMA 지표의 교차 신호를 실시간으로 모니터링하여 거래 지시를 자동으로 실행합니다. 시스템은 백분율 추적 손해 중지 및 고정 비율 중지 프로그램을 채택하여 거래의 안전성을 보장하고 수익 가능성을 보장합니다.
전략 운영의 핵심 논리는 빠른 EMA ((9주기) 와 느린 EMA ((21주기) 의 교차 관계를 기반으로 합니다. 빠른 선이 위쪽으로 느린 선을 통과하면, 시스템은 상점 신호로 인식하고, 자동으로 공백을 설정하고 다채로운 위치를 열습니다. 빠른 선이 아래쪽으로 느린 선을 통과하면, 시스템은 상점 신호로 인식하고, 자동으로 공백을 설정하고 다채로운 위치를 열습니다. 동시에, 시스템은 동적인 중지 손실 막기 장치를 설정합니다. 다채로운 위치를 유지하는 동안, 중지 손실 가격은 개시 가격의 5% 아래에 설정되어 있으며, 중지 손실 가격은 개시 가격의 10% 위에 설정되어 있습니다.
이 전략은 구조가 완전하고, 논리가 명확한 자동화 거래 시스템이다. EMA 교차 신호를 통해 거래 결정을 하고, 동적 인 중지 손해 중지 메커니즘과 함께, 트렌드 시장에서 좋은 성능을 얻을 수 있다. 그러나 사용 과정에서 시장 환경의 변화에 주의를 기울이고, 적절하게 파라미터 설정을 조정하고, 위험을 잘 제어해야합니다. 계속적으로 최적화 및 개선함으로써, 이 전략은 안정적이고 신뢰할 수있는 거래 도구가 될 전망이다.
/*backtest
start: 2019-12-23 08:00:00
end: 2024-11-28 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
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, "显示标签")
var stopLossPercent = input.float(5.0, "止损百分比", minval=0.1, maxval=20.0, step=0.1)
var takeProfitPercent = input.float(10.0, "止盈百分比", minval=0.1, maxval=50.0, step=0.1)
// 计算EMA
ema9 = ta.ema(close, 9)
ema21 = ta.ema(close, 21)
// 绘制EMA线
plot(ema9, "EMA9", color=color.blue, linewidth=2)
plot(ema21, "EMA21", color=color.red, linewidth=2)
// 检测交叉
crossOver = ta.crossover(ema9, ema21)
crossUnder = ta.crossunder(ema9, ema21)
// 格式化时间显示 (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, 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, 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)