
本策略通过结合双均线交叉和RSI指标来识别趋势方向和超买超卖情况,在符合买入条件时做多,在符合卖出条件时平仓。该策略旨在利用均线交叉来确定趋势方向,同时利用RSI指标来避免在市场顶部做多和市场底部做空,从而获得更好的收益。
当快速9周期均线上穿慢速50周期均线时,表示短期趋势上升叠加长期趋势上升,属于典型的多头信号。同时,如果RSI指标大于上一周期5个点且小于70时,则表明处于超买前的区域,这时做多则是比较合适的时机。
当快速9周期均线下穿慢速50周期均线时,表示处于空头市场,需要平仓。
本策略通过双均线交叉判断方向和RSI避免追高追低,能够有效利用中长线趋势获得稳定收益。但也需要警惕均线交叉信号的滞后性和RSI参数的调整,同时关注价格与成交量的关系。通过持续测试和优化,本策略有望取得更好的效果。
/*backtest
start: 2022-11-14 00:00:00
end: 2023-11-20 00:00:00
period: 1d
basePeriod: 1h
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/
// © joshuajcoop01
//@version=5
strategy("Bitpanda Coinrule Template",
overlay=true,
initial_capital=1000,
process_orders_on_close=true,
default_qty_type=strategy.percent_of_equity,
default_qty_value=30,
commission_type=strategy.commission.percent,
commission_value=0.1)
showDate = input(defval=true, title='Show Date Range')
timePeriod = time >= timestamp(syminfo.timezone, 2020, 1, 1, 0, 0)
notInTrade = strategy.position_size <= 0
// RSI
length = input(14)
vrsi = ta.rsi(close, length)
// Moving Averages for Buy Condition
buyFastEMA = ta.ema(close, 9)
buySlowEMA = ta.ema(close, 50)
buyCondition1 = ta.crossover(buyFastEMA, buySlowEMA)
increase = 5
if ((vrsi > vrsi[1]+increase) and buyCondition1 and vrsi < 70 and timePeriod)
strategy.entry("Long", strategy.long)
// Moving Averages for Sell Condition
sellFastEMA = ta.ema(close, 9)
sellSlowEMA = ta.ema(close, 50)
plot(request.security(syminfo.tickerid, "60", sellFastEMA), color = color.blue)
plot(request.security(syminfo.tickerid, "60", sellSlowEMA), color = color.green)
condition = ta.crossover(sellSlowEMA, sellFastEMA)
//sellCondition1 = request.security(syminfo.tickerid, "60", condition)
strategy.close('Long', when = condition and timePeriod)