这是一种基于双均线的简单日内交易策略。它使用两个不同周期的简单移动均线,在均线交叉时进行买入或卖出。在信号改变时,使用双倍数量平仓再反向开仓。当日内交易时段结束时,如果仓位还未平仓,则全部平仓。
该策略使用10日和40日两条简单移动均线。当短期均线上穿长期均线时,做多;当短期均线下穿长期均线时,做空。当信号发生变化时,使用双倍手数平仓再反向开仓。在定义的日内交易时段内,跟随均线信号进行交易。当日内交易时段结束,如果还有未平仓位,则全部平仓。
该策略主要利用了短期均线能更快捕捉价格变化的特点。当短期均线上穿长期均线时,表示短期价格开始上涨,做多能捕捉这一趋势;当短期均线下穿长期均线时,表示短期价格开始下跌,做空能捕捉这一趋势。双倍手数反向开仓的设计,则能够加大仓位,扩大获利空间。
对应风险的解决方法:
优化均线参数。可以测试更多组合,寻找最佳参数。
增加其他技术指标过滤。例如加上MACD指标确认,可以降低错误信号率。
优化反向开仓倍数。测试不同的倍数大小,找到最优参数。
测试不同的日内交易时段。适当延长时段可能获得更好回报。
该策略整体思路简单,通过捕捉双均线交叉形成的短期趋势,配合双倍手数反向开仓扩大获利空间,最后配合日内时段交易规避过夜风险。是一种适合日内短线交易的有效策略。有进一步优化空间,通过调整参数以及增添其他技术指标过滤,可以获得更好的策略效果。
/*backtest start: 2024-02-19 00:00:00 end: 2024-02-26 00:00:00 period: 1m basePeriod: 1m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © Pritesh-StocksDeveloper //@version=4 strategy("Moving Average - Intraday", shorttitle = "MA - Intraday", overlay=true, calc_on_every_tick = true) // Used for intraday handling // Session value should be from market start to the time you want to square-off // your intraday strategy var i_marketSession = input(title="Market session", type=input.session, defval="0915-1455", confirm=true) // Short & Long moving avg. period var int i_shortPeriod = input(title = "Short MA Period", type = input.integer, defval = 10, minval = 2, maxval = 20, confirm=true) var int i_longPeriod = input(title = "Long MA Period", type = input.integer, defval = 40, minval = 3, maxval = 120, confirm=true) // A function to check whether the bar is in intraday session barInSession(sess) => time(timeframe.period, sess) != 0 // Calculate moving averages shortAvg = sma(close, i_shortPeriod) longAvg = sma(close, i_longPeriod) // Plot moving averages plot(series = shortAvg, color = color.red, title = "Short MA", linewidth = 2) plot(series = longAvg, color = color.blue, title = "Long MA", linewidth = 2) // Long/short condition longCondition = crossover(shortAvg, longAvg) shortCondition = crossunder(shortAvg, longAvg) // See if intraday session is active bool intradaySession = barInSession(i_marketSession) // Trade only if intraday session is active // Long position strategy.entry(id = "Long", long = strategy.long, when = longCondition and intradaySession) // Short position strategy.entry(id = "Short", long = strategy.short, when = shortCondition and intradaySession) // Square-off position (when session is over and position is open) squareOff = (not intradaySession) and (strategy.position_size != 0) strategy.close_all(when = squareOff, comment = "Square-off")