
Es un sistema de estrategias de trading automatizado basado en la intersección de dos líneas de equilibrio. El sistema utiliza una media móvil indexada de 9 y 21 períodos (EMA) como indicador central, para realizar operaciones mediante la captura de señales de cruce de dos líneas de equilibrio. El sistema integra la gestión de stop loss, al tiempo que proporciona soporte para una interfaz visual que permite mostrar visualmente las señales de negociación y los niveles de precios clave.
La estrategia utiliza EMA rápido ((9 ciclos) y EMA lento ((21 ciclos) para construir el sistema de negociación. Cuando el EMA rápido sube y atraviesa el EMA lento, el sistema genera una señal múltiple; cuando el EMA rápido desciende y atraviesa el EMA lento, el sistema genera una señal de vacío.
Es un sistema de estrategias de cruce lineal equilibrado diseñado de manera racional y lógica. La estrategia obtiene ganancias en un mercado de tendencia mediante el uso integrado de señales de cruce de EMA y mecanismos de gestión de riesgos. Aunque existen algunos riesgos inherentes, la estrategia puede mejorar aún más su estabilidad y fiabilidad mediante la orientación de optimización sugerida.
/*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)