该策略是一个基于双指数移动平均线(EMA)的趋势跟踪交易系统。策略使用44周期和200周期两条EMA线,结合价格突破信号来确定交易方向。同时整合了风险管理机制,包括动态仓位计算和移动止损。
策略的核心逻辑基于价格与双EMA线的交互关系。使用44周期EMA分别应用于最高价和最低价形成上下通道,200周期EMA作为长期趋势过滤器。当收盘价突破上轨EMA且满足200EMA过滤条件时,系统生成做多信号;当收盘价跌破下轨EMA且满足200EMA过滤条件时,系统生成做空信号。策略采用基于账户权益的动态仓位管理,根据每笔交易的风险百分比自动计算开仓数量。止损设置为相应的EMA线位置。
这是一个结构完整、逻辑清晰的趋势跟踪策略。通过双EMA通道和长期趋势过滤提供交易信号,配合完善的风险管理机制,具有良好的实用性。策略的优化空间主要在于信号确认、动态参数调整和风险管理机制的完善。在实际应用中,建议充分测试参数敏感性,并结合具体交易品种的特性进行针对性优化。
/*backtest
start: 2024-02-25 00:00:00
end: 2024-03-17 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Binance","currency":"SOL_USDT"}]
*/
//@version=5
strategy("RENTABLE Dual EMA Breakout TSLA ", overlay=true)
// Inputs for EMA lengths and risk per trade
length = input(44, title="EMA Length")
longTermLength = input(200, title="Long-Term EMA Length")
riskPerTrade = input.float(1.0, title="Risk per Trade (%)", minval=0.1, maxval=10.0)
// Additional inputs for strategy customization
useFilter = input.bool(true, title="Use 200 EMA Filter")
tradeDirection = input.string("Both", title="Trade Direction", options=["Long", "Short", "Both"])
// EMAs based on the high and low prices and long-term EMA
emaHigh = ta.ema(high, length)
emaLow = ta.ema(low, length)
ema200 = ta.ema(close, longTermLength)
// Plotting EMAs on the chart
plot(emaHigh, color=color.green, title="High EMA")
plot(emaLow, color=color.red, title="Low EMA")
plot(ema200, color=color.blue, title="200 EMA")
// Entry conditions with optional EMA filter
longCondition = close > emaHigh and (useFilter ? close > ema200 : true)
shortCondition = close < emaLow and (useFilter ? close < ema200 : true)
// Calculating stop-loss and position size
longStop = emaLow
shortStop = emaHigh
riskPerShareLong = close - longStop
riskPerShareShort = shortStop - close
equity = strategy.equity
// Ensure risk per share is positive for calculations
riskPerShareLong := riskPerShareLong > 0 ? riskPerShareLong : 0.01
riskPerShareShort := riskPerShareShort > 0 ? riskPerShareShort : 0.01
positionSizeLong = (equity * riskPerTrade / 100) / riskPerShareLong
positionSizeShort = (equity * riskPerTrade / 100) / riskPerShareShort
// Ensure position sizes are positive before entering trades
if (longCondition and (tradeDirection == "Long" or tradeDirection == "Both") and positionSizeLong > 0)
strategy.entry("Long", strategy.long, qty= positionSizeLong)
if (shortCondition and (tradeDirection == "Short" or tradeDirection == "Both") and positionSizeShort > 0)
strategy.entry("Short", strategy.short, qty=positionSizeShort)
// Applying the stop-loss to strategy
strategy.exit("Exit Long", "Long", stop=longStop)
strategy.exit("Exit Short", "Short", stop=shortStop)
////Usar en 1,2 3 4 HRS TSLA