이 전략은 상대적으로 강하고 약한 지수 ((RSI) 지표에 따라 판단되며, RSI가 상한을 설정할 때 공백하고, RSI가 하한을 설정할 때 더 많이 할 때, 전형적인 RSI 역전 거래 전략에 속한다. 전략은 동시에 변수 최적화, 손해 중지 전략 등의 기능을 가지고 있으며, 변수를 조정하여 다른 시장 환경에 적응 할 수 있다.
이 전략의 핵심 논리는 다음과 같습니다.
RSI 지표는 시장이 과매매 또는 과매매 상태에 있음을 나타냅니다. RSI가 70보다 높으면 과매매로 간주되며, RSI가 30보다 낮으면 과매매로 간주됩니다. 거래 전략은 RSI의 과매매 과매매 상태에 따라 공시 상위 또는 다수 상위 지위를 설정하는 것입니다.
이 전략은 RSI 지표의 클래식 논리를 사용하여 RSI의 수와 기본 상하계와의 관계에 따라 포지션 방향을 판단한다. 또한, 전략은 조정 가능한 매개 변수를 가지고 있으며, RSI 상하계, 스톱 스톱 손실 폭 등을 최적화하여 시장의 변화에 적응 할 수 있다.
대책:
이 전략은 다음과 같은 부분에서 확장되고 최적화될 수 있습니다.
기계 학습을 사용하여 RSI 변수 범위를 자동으로 최적화합니다.
트랜잭션 확인을 늘리고 가짜 돌파구를 피하십시오.
이동 평균과 같은 지표와 결합하여 다중 인자 검증을 수행합니다.
시장의 변동에 따라 자기 적응적 인 중지 전략을 설정하여 중지량을 조정하십시오.
거래량 변화를 조사하고, 투자 유입과 유출을 판단합니다.
다른 비관계적 전략과 결합하여 전체적인 탈퇴를 감소시키는 방법
이 전략은 RSI 지표를 사용하여 과매매를 판단하는 간단한 실용적인 역전 전략이다. 전략은 시장 변화에 따라 매개 변수를 조정할 수 있으며, 또한 다차원 확장 및 최적화를 할 수 있다. 매개 변수 최적화, 다중 인자 검증, 자율적 인 손실을 방지하는 등의 개선으로 전략이 더 안정적이고 신뢰할 수 있습니다.
/*backtest
start: 2023-08-19 00:00:00
end: 2023-09-18 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=3
strategy("4All V3", shorttitle="Strategy", overlay=true)
/////////////// Component Code Start ///////////////
testStartYear = input(2011, "Backtest Start Year")
testStartMonth = input(8, "Backtest Start Month")
testStartDay = input(1, "Backtest Start Day")
testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)
testStopYear = input(2018, "Backtest Stop Year")
testStopMonth = input(9, "Backtest Stop Month")
testStopDay = input(29, "Backtest Stop Day")
// testStopDay = testStartDay + 1
testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)
// A switch to control background coloring of the test period
testPeriodBackground = input(title="Color Background?", type=bool, defval=true)
testPeriodBackgroundColor = testPeriodBackground and (time >= testPeriodStart) and (time <= testPeriodStop) ? #00FF00 : na
bgcolor(testPeriodBackgroundColor, transp=97)
testPeriod() => true
/////////////// Component Code Stop ///////////////
src = close
len = input(4, minval=1, title="Length")
up = rma(max(change(src), 0), len)
down = rma(-min(change(src), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
rsin = input(5)
sn = 100 - rsin
ln = 0 + rsin
/////////////// STRATEGY ///////////////
ts = input(99999, "Trailing Stop") / 10000
tp = input(15, "Take Profit") / 10000
sl = input(23, "Stop Loss") / 10000
pyr = input(1, "Pyramiding")
short = crossover(rsi, sn)
long = crossunder(rsi, ln)
totalLongs = 0
totalLongs := nz(totalLongs[1])
totalShorts = 0
totalShorts := nz(totalShorts[1])
totalLongsPrice = 0
totalLongsPrice := nz(totalLongsPrice[1])
totalShortsPrice = 0
totalShortsPrice := nz(totalShortsPrice[1])
sectionLongs = 0
sectionLongs := nz(sectionLongs[1])
sectionShorts = 0
sectionShorts := nz(sectionShorts[1])
if long
sectionLongs := sectionLongs + 1
sectionShorts := 0
if short
sectionLongs := 0
sectionShorts := sectionShorts + 1
longCondition = long and sectionLongs >= pyr
shortCondition = short and sectionShorts >= pyr
last_long = na
last_short = na
last_long := longCondition ? time : nz(last_long[1])
last_short := shortCondition ? time : nz(last_short[1])
long_signal = crossover(last_long, last_short)
short_signal = crossover(last_short, last_long)
last_open_long_signal = na
last_open_short_signal = na
last_open_long_signal := long_signal ? open : nz(last_open_long_signal[1])
last_open_short_signal := short_signal ? open : nz(last_open_short_signal[1])
last_long_signal = na
last_short_signal = na
last_long_signal := long_signal ? time : nz(last_long_signal[1])
last_short_signal := short_signal ? time : nz(last_short_signal[1])
in_long_signal = last_long_signal > last_short_signal
in_short_signal = last_short_signal > last_long_signal
last_high = na
last_low = na
last_high := not in_long_signal ? na : in_long_signal and (na(last_high[1]) or high > nz(last_high[1])) ? high : nz(last_high[1])
last_low := not in_short_signal ? na : in_short_signal and (na(last_low[1]) or low < nz(last_low[1])) ? low : nz(last_low[1])
long_ts = not na(last_high) and high <= (last_high - ts) //and high >= last_open_long_signal
short_ts = not na(last_low) and low >= (last_low + ts) //and low <= last_open_short_signal
long_tp = high >= (last_open_long_signal + tp)
short_tp = low <= (last_open_short_signal - tp)
long_sl = low <= (last_open_long_signal - sl)
short_sl = high >= (last_open_short_signal + sl)
leverage = input(1, "Leverage")
long_call = last_open_long_signal - (0.8 + 0.2 * (1/leverage)) / leverage * last_open_long_signal
short_call = last_open_short_signal + (0.78 + 0.2 * (1/leverage)) / leverage * last_open_short_signal
long_call_signal = low <= long_call
short_call_signal = high >= short_call
if testPeriod()
strategy.entry("Long", strategy.long, when=longCondition)
strategy.entry("Short", strategy.short, when=shortCondition)
strategy.close("Long", when=long_call_signal)
strategy.close("Short", when=short_call_signal)
strategy.close("Long", when=long_tp)
strategy.close("Short", when=short_tp)
strategy.close("Long", when=long_sl)
strategy.close("Short", when=short_sl)
strategy.close("Long", when=long_ts)
strategy.close("Short", when=short_ts)