移动平均线结合的高效量化交易策略

Author: ChaoZhang, Date: 2024-02-01 15:09:06
Tags:

移动平均线结合的高效量化交易策略

概述

本策略主要利用5日RSI指标与200日移动平均线的结合,形成交易决策信号,属于技术指标组合策略。其主要交易原理是:当价格运行到超买超卖区域时,信号卖出;当价格跌至超卖区域时,信号买入。该策略最大优势是策略信号比较明确,回撤风险较小。但也存在只利用单一技术指标组合形成交易决策的局限性,可通过多因子模型与机器学习算法等进行优化。

策略原理

本策略主要利用5日RSI指标与200日移动平均线的结合,判断价格运行的超买超卖区域,形成交易决策:

  1. 5日RSI指标判断价格运行的超买超卖区域。设置超买线为72,超卖区域为30。当RSI指标由下向上突破30时产生买入信号;当RSI指标由上向下跌破72时,产生卖出信号。

  2. 200日移动平均线判断价格中长线趋势方向。当价格低于200日均线时,为价格下行阶段;当价格高于200日均线时,为价格上行阶段。

  3. 结合1、2判断,本策略iault时5日RSI指标超买并下破72时卖出,5日RSI下破30时并且价格低于200日均线时买入。

策略优势

  1. 策略信号比较明确,利用RSI指标 Judgment区域判定超买超卖信号。

  2. 200日均线判断大趋势方向,避免逆势操作。

  3. 可设置最大持仓数,有利于控制风险。

  4. 策略参数优化空间大,可调整RSI参数与均线参数。

  5. 回撤风险较小,可效控制策略最大回撤。

策略风险

  1. 仅利用RSI指标与均线指标,策略信号可能不稳定,存在多头空头震荡市买卖亏损风险。

  2. 需优化和测试RSI参数与均线参数,以取得更好策略效果。

  3. 可引入别的指标或模型判断,优化策略信号。如引入波动率指标、机器学习判断等。

策略优化方向

  1. 利用更多指标组合判断。如MACD,KD,波动率指标等。

  2. 增加机器学习模型判断。如LSTM判断交易信号稳定性。

  3. 增加量化因子。如交易量变化、资金流向等判断资金面因子。

  4. 优化策略参数。如RSI参数、均线参数等。

  5. 优化止损机制。如移动止损、时间止损等。

总结

本策略主要运用5日RSI指标与200日均线指标组合判断价格超买超卖区域,形成交易信号,属于技术指标组合策略。策略信号比较明确,最大回撤风险较小。但可通过多指标组合与机器学习判断等进一步优化,以提高策略效果。


/*backtest
start: 2024-01-24 00:00:00
end: 2024-01-31 00:00:00
period: 3m
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/
// ©chewyScripts.

//@version=5
strategy("96er RSI+200EMA Strategy + Alerts", overlay=true)
// This works best on a small account $100, with 50% of equity and up to 10 max open trades. 
// 96% Profitable, turns $100 into $350 in 1 month. very few losses. super happy with it.
// So far it triples the account on a 1m chart in 1 month back testing on the SEI-USD pair.
// I did not test on FX pairs or other instruments.
// had some issues with the inputs not working so had to hard code some, also the lastClose var sometimes breaks and starts following every candle, not sure why.

in_r1 = input.int(5,"5 day input or RSI1")
in_openOrders = input.int(3,"max open orders")

in_lowerRSI = input.int(30,"RSI Lower")
in_upperRSI = input.int(72,"RSI Upper ")

in_emaperiod = input.int(200,"EMA Period")

in_buybreakout = input.int(50,"Buy breakout range")

in_buyTP = input.float(1.05,"Buy TP: 1+TP %, .05 seems to work well.")
in_sellTP = input.float(0.9850, "Sell TP: 1-TP%. .025 seems to work well. ")

simple int rsi5 = in_r1

// 3 rsi strategy , when all of them are overbought we sell, and vice versa
rsi7 = ta.rsi(close,rsi5)
lastClose = request.security(syminfo.tickerid, "D", close, lookahead = barmerge.lookahead_on)
rsi3 = ta.rsi(close[5],rsi5)

ma = ta.ema(close,in_emaperiod)

plot(rsi7,"5 Day RSI",color.red)
plot(lastClose,"Yesterdays Close",color.green)
plot(rsi3,"Previous 5th candles RSI",color.purple)


// sell condition
//sell = ta.crossunder(rsi7,70) and ta.crossunder(rsi14,70) and ta.crossunder(rsi21,70)

//buy condition
//buy = ta.crossover(rsi7,in_lowerRSI) and close < ma and rsi3 <= in_upperRSI and strategy.opentrades < in_openOrders
//sell = ta.crossunder(rsi7,in_upperRSI) and close > ma and rsi3 >= in_lowerRSI3 and strategy.opentrades < in_openOrders

buy = ta.crossover(rsi7,in_lowerRSI) and close < ma and close < lastClose and strategy.opentrades < in_openOrders
sell = ta.crossunder(rsi7,in_upperRSI) and close > ma and close > lastClose and strategy.opentrades < in_openOrders


var lastBuy = close 
var lastSell = close 

if (buy)
    strategy.entry("BUY", strategy.long)
    lastBuy := close 
    alert("Buy")

if ((close >= lastBuy*in_buyTP ) or rsi7 > in_buybreakout and close >= lastClose and (close >= lastClose*in_buyTP or close >= lastBuy*in_buyTP ) )
    strategy.close("BUY", "BUY Exit")
    alert("Buy Exit")
    
if (sell)
    strategy.entry("SELL", strategy.short)
    lastSell := close 
    alert("Sell")

if ( close < ma and (close <= lastSell*in_sellTP ) or (close < lastClose*in_sellTP) )
    strategy.close("SELL", "Sell Exit")
    alert("Sell Exit")


更多内容