该策略使用两条不同周期的指数移动平均线(EMA)的交叉作为交易信号,同时设置固定点数的止盈和止损。当短期EMA从下向上穿过长期EMA时,开仓做多;当短期EMA从上向下穿过长期EMA时,开仓做空。交易时设置固定点数的止盈和止损,以控制风险和锁定利润。
双均线交叉止盈止损策略是一个简单易用的交易策略,通过EMA交叉产生交易信号,同时设置固定点数止盈止损来控制风险。该策略的优势在于逻辑清晰,易于实现,能够较好地捕捉市场趋势。但同时也存在假信号、趋势延迟、盘整市场和固定止损等风险。优化方向包括引入更多指标、优化参数、动态止损、仓位管理和增加过滤器等。交易者可根据自己的风险偏好和市场特点,对该策略进行适当优化和调整,以提高策略的稳健性和盈利能力。
/*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("EMA5 Cross EAM200 && SL/TP 50 and 200 Point Target", overlay=true)
// Define input parameters for EMA lengths
ema_5 = input.int(5, title="Fast EMA Length")
ema_200 = input.int(200, title="Slow EMA Length")
// Define input parameters for stop loss and profit target in points
stopLossPoints = input.float(50, title="Stop Loss (Points)")
profitTargetPoints = input.float(200, title="Profit Target (Points)")
// Calculate EMAs
price = close
emafast = ta.ema(price, ema_5)
emaslow = ta.ema(price, ema_200)
// Plot EMAs on chart
plot(emafast, title="5-period EMA", color=color.black)
plot(emaslow, title="200-period EMA", color=color.blue)
// Extra lines if needed
ema_13 = input.int(13, title="13 EMA")
ema_13_line = ta.ema(price, ema_13)
plot(ema_13_line, title="13-period EMA", color=color.rgb(156, 39, 176, 90))
ema_20 = input.int(20, title="20 EMA")
ema_20_line = ta.ema(price, ema_20)
plot(ema_20_line, title="20-period EMA", color=color.red)
// Define entry conditions
longCondition = ta.crossover(emafast, emaslow)
shortCondition = ta.crossunder(emafast, emaslow)
// Counter to keep track of the number of bars since the entry
var int barCount = na
// Reset counter and enter long trade
if (longCondition)
strategy.entry("Long", strategy.long, comment="Long")
barCount := 0
// Reset counter and enter short trade
if (shortCondition)
strategy.entry("Short", strategy.short, comment="Short")
barCount := 0
// Increment counter if in trade
if (strategy.opentrades > 0)
barCount += 1
// Calculate entry price
entryPrice = strategy.position_avg_price
// Exit long trade if stop loss, profit target hit, or 200 points have been reached
if (strategy.position_size > 0)
strategy.exit("Take Profit/Stop Loss", "Long", stop=entryPrice - stopLossPoints, limit=entryPrice + profitTargetPoints)
// Exit short trade if stop loss, profit target hit, or 200 points have been reached
if (strategy.position_size < 0)
strategy.exit("Take Profit/Stop Loss", "Short", stop=entryPrice + stopLossPoints, limit=entryPrice - profitTargetPoints)