本策略通过组合使用双均线、相对强弱指标(RSI)以及抛物线指标(PSAR),实现对价格反转点的判断,在反转点发生时进行买入和卖出操作,属于反转交易策略。
本策略主要通过以下技术指标判断价格反转点:
双均线: 计算快速移动均线(MA快线)和慢速移动均线(MA慢线)。当快线上穿慢线时,判断为多头市场,做多;当快线下穿慢线时,判断为空头市场,做空。
RSI指标:RSI通过计算一段时间内的平均收盘涨幅和平均收盘跌幅,来判断超买超卖状况。RSI大于70时为超买区,小于30时为超卖区。
PSAR指标:抛物线SAR指标判断趋势的方向。SAR点下方为多头市场,上方为空头市场。
ADX指标:ADX通过计算价格变动的方向性强度,判断趋势的力度。ADX值大于20表示趋势行情,小于20表示盘整。
根据以上指标判断买入和卖出信号的逻辑如下:
买入信号:快线上穿慢线,RSI小于30(超卖区),SAR点在价格上方,ADX大于20,发出买入信号。
卖出信号:快线下穿慢线,RSI大于70(超买区),SAR点在价格下方,ADX大于20,发出卖出信号。
当发生买入和卖出信号时,分别以10%的仓位建立多仓和空仓。当反转信号失效时,及时止损平仓。
使用双均线判断大趋势方向,又加入RSI和SAR等指标滤除错误信号,可以比较准确地判断反转点。
采用多种指标组合判断,避免单一技术指标造成的错误信号。
设置止损条件,可以有效控制风险。
策略操作简单清晰,容易实施。
该策略对市场涨跌都有应对方案,可适用于不同行情。
双均线生成空头信号时,行情可能出现假破,需要结合其他指标进行判断。可适当拉长均线周期,或加入布林带指标判断突破的真伪。
RSI指标因参数设置不当可能产生错误信号。应适当调整RSI参数,同时加入其他指标确认RSI信号。
ADX值低于20时,应暂停交易,避免无方向性市场的反转交易。或适当降低ADX的周期参数。
SetStringry止损点设置过小,可能造成无谓止损。应根据市场波动程度合理设置止损点。
交易频率可能过高,可适当调整双均线周期,降低交易频率。
测试不同长度周期的均线组合,寻找最佳参数。
测试RSI的不同参数设置,优化超买超卖判断。
尝试加入其他指标,如布林带、KDJ等,丰富买卖信号的判断逻辑。
根据不同品种和市场情况设置动态止损机制。
添加仓位管理策略,让盈利能更好地跟踪趋势。
测试不同ADX参数,找到最佳判定趋势力度的数值。
加入自动止损模块,让策略可以自动止损。
本策略通过双均线判断大方向,结合RSI、SAR等指标进行反转信号过滤,在优化参数设定后,可以有效判断价格反转点,从而在反转前后捕捉趋势。在实盘中应注意控制风险,合理设置止损条件,并继续优化参数,使策略更稳定和利润更高。总体来说,该策略交叉指标结合使用,思路清晰易操作,属于一种可靠的反转交易策略。
/*backtest
start: 2023-10-10 00:00:00
end: 2023-11-09 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=2
//Based on Senpai BO 3
strategy(title="Senpai_Strat_3", shorttitle="Senpai_Strat_3", overlay=false, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
src = close
//psar
start = input(0.02)
increment = input(0.02)
maximum = input(0.2)
psar = sar(start, increment, maximum)
//ADX Init
adxlen = input(30, title="ADX Smoothing")
dilen = input(30, title="DI Length")
dirmov(len) =>
up = change(high)
down = -change(low)
truerange = rma(tr, len)
plus = fixnan(100 * rma(up > down and up > 0 ? up : 0, len) / truerange)
minus = fixnan(100 * rma(down > up and down > 0 ? down : 0, len) / truerange)
[plus, minus]
adx(dilen, adxlen) =>
[plus, minus] = dirmov(dilen)
sum = plus + minus
adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
[adx, plus, minus]
[sig, up, down] = adx(dilen, adxlen)
// BB Init
source = close
length = input(50, minval=1)
mult = input(0.5, title="Mult Factor", minval=0.001, maxval=50)
alertLevel=input(0.1)
impulseLevel=input(0.75)
showRange = input(false, type=bool)
//RSI CODE
up1 = rma(max(change(src), 0), 14)
down1 = rma(-min(change(src), 0), 14)
rsi = down1 == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up1 / down1))
//BB CODE
basis = sma(source, length)
dev = mult * stdev(source, length)
upper = basis + dev
lower = basis - dev
bbr = source>upper?(((source-upper)/(upper-lower))/10): source<lower?(((source-lower)/(upper-lower))/10) : 0.05
bbi = bbr - nz(bbr[1])
//////////////////// Algo
//if (rsi>50 and n1>n2)
//strategy.exit("Close", "Short")
// strategy.entry("Long", strategy.long)
//if (rsi<50 and n2>n1)
//strategy.exit("Close", "Long")
// strategy.entry("Short", strategy.short)
//col = ma30 > ma50 > ma200 and rsi <=53?lime: ma50 < ma200 and rsi >= 60?red : silver
//short1 = sig<18.5 and high>=upper and rsi>=70 and psar<close = 100%
//long1 = sig<18.5 and low<=lower and rsi<=30 and psar>close = 100%
short1 = sig<18.5 and high>=upper and rsi>=70 and psar<close
long1 = sig<18.5 and low<=lower and rsi<=30 and psar>close
//Entry
long = long1[1] == 0 and long1 == 1
short = short1[1] == 0 and short1 == 1
longclose = long[3] == 1
shortclose = short[3] == 1
strategy.entry("short", strategy.short,qty = 10, when=short)
strategy.entry("long", strategy.long,qty=10, when=long)
strategy.close("long",when=longclose)
strategy.close("short",when=shortclose)
/////////////////////
///PLOT
plot(long,"long",color=green,linewidth=1)
plot(short,"short",color=red,linewidth=1)
plot(longclose,"close",color=blue,linewidth=1)
plot(shortclose,"close",color=orange,linewidth=1)
//plot(short,"short",color=red,linewidth=1)
//
//strategy.exit(id="long",qty = 100000,when=longclose)
//strategy.exit(id="short",qty = 100000,when=shortclose)
//strategy.exit(id="Stop", profit = 20, loss = 100)