该策略结合了EMA、MACD、VWAP和RSI等多个指标,旨在捕捉高概率的交易机会。策略使用EMA来判断趋势方向,MACD来判断动量,VWAP来判断成交量,RSI来判断超买超卖情况。策略根据这些指标的组合来产生买入和卖出信号,同时使用移动止损来保护利润。
该策略通过结合多个指标来判断市场状态,产生交易信号,同时使用移动止损来保护利润。策略参数可以根据用户偏好进行调整,提高策略的灵活性。但是,策略在震荡市场中可能表现不佳,在趋势反转时可能面临较大回撤,因此需要根据不同市场和品种进行优化和改进。未来可以考虑加入更多的过滤条件、动态止损方式、参数优化和仓位管理等方面的优化,以提高策略的稳定性和盈利能力。
/*backtest start: 2024-04-01 00:00:00 end: 2024-04-30 23:59:59 period: 4h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("Intraday Strategy", overlay=true) // Input parameters emaLength = input.int(50, title="EMA Length") macdShort = input.int(12, title="MACD Short Period") macdLong = input.int(26, title="MACD Long Period") macdSignal = input.int(9, title="MACD Signal Period") rsiLength = input.int(14, title="RSI Length") rsiOverbought = input.int(70, title="RSI Overbought Level") rsiOversold = input.int(30, title="RSI Oversold Level") risk = input.float(1, title="Risk Percentage", minval=0.1, step=0.1) trailOffset = input.float(0.5, title="Trailing Stop Offset", minval=0.1, step=0.1) // Calculating indicators ema = ta.ema(close, emaLength) [macdLine, signalLine, _] = ta.macd(close, macdShort, macdLong, macdSignal) rsi = ta.rsi(close, rsiLength) vwap = ta.vwap(close) // Entry conditions longCondition = ta.crossover(macdLine, signalLine) and close > ema and rsi < rsiOverbought and close > vwap shortCondition = ta.crossunder(macdLine, signalLine) and close < ema and rsi > rsiOversold and close < vwap // Exit conditions longExitCondition = ta.crossunder(macdLine, signalLine) or close < ema shortExitCondition = ta.crossover(macdLine, signalLine) or close > ema // Position sizing based on risk percentage capital = strategy.equity positionSize = (capital * (risk / 100)) / close // Executing trades if (longCondition) strategy.entry("Long", strategy.long, qty=1) if (shortCondition) strategy.entry("Short", strategy.short, qty=1) if (longExitCondition) strategy.close("Long") if (shortExitCondition) strategy.close("Short") // Trailing stop loss if (strategy.position_size > 0) strategy.exit("Trailing Stop Long", from_entry="Long", trail_price=close, trail_offset=trailOffset) if (strategy.position_size < 0) strategy.exit("Trailing Stop Short", from_entry="Short", trail_price=close, trail_offset=trailOffset) // Plotting indicators plot(ema, title="EMA", color=color.blue) hline(rsiOverbought, "Overbought", color=color.red) hline(rsiOversold, "Oversold", color=color.green) plot(rsi, title="RSI", color=color.purple) plot(vwap, title="VWAP", color=color.orange)