트렌드 역전 시스템

저자:차오장, 날짜: 2023-10-23 17:18:28
태그:

img

전반적인 설명

트렌드 역전 시스템 (Trend Reversal System) 은 트렌드를 파악하고 인기를 부여하기 위해 이동 평균, CCI 지표 및 슈퍼 트렌드 지표를 활용하는 트렌드 다음 전략이다. 트렌드 방향을 확인하고 리트레이싱 중에 입점 신호를 제공할 수 있습니다.

전략 논리

이 전략은 단기 이동 평균으로 21주기 EMA와 장기 이동 평균으로 55주기 EMA를 사용합니다. 55 EMA 이상의 21 EMA는 상승 추세를 나타내고, 55 EMA 이하의 21 EMA는 하락 추세를 나타냅니다.

CCI 지표는 가격이 극단적 수준에 도달했을 때 표시됩니다. 레벨 1 신호는 CCI가 기본으로 100/-100에 도달하고 레벨 2는 140/-140이며 레벨 3는 180/-180. 이것은 과소매 또는 과소매 조건을 시사합니다.

슈퍼트렌드 지표는 특정 트렌드 방향을 결정합니다. ATR을 통합하여 상승과 하락 트렌드의 스톱 로스 및 엔트리 레벨을 식별합니다.

21 EMA가 55 EMA보다 높고 CCI가 낮은 수준 (가장 팔린 영역) 에 도달하면 긴 진입을 신호할 수 있습니다. 21 EMA가 55 EMA보다 낮고 CCI가 높은 수준 (가장 팔린 영역) 에 도달하면 짧은 진입을 신호할 수 있습니다. 스톱 손실은 슈퍼트렌드의 스톱 수준에 설정되며 이익은 400 피프로 고정됩니다.

이점 분석

이 전략은 트렌드와 과잉 구매/ 과잉 판매 상황을 식별하기 위해 여러 지표를 결합하여 잘못된 브레이크오웃을 필터링하는 데 도움이됩니다. 고정된 취득은 안정적인 리스크 리워드 비율을 허용합니다. 트렌드와 거래하면 더 높은 승률을 제공합니다. CCI 과잉 구매/ 과잉 판매 신호는 트렌드 리트레이싱 중에 좋은 입시 타이밍을 제공합니다.

위험 분석

현재 설정이 이상적이지 않을 수 있기 때문에 매개 변수는 다른 기호에 최적화되어야합니다. 스톱 로스 방법은 원시이며 다른 시장 조건에 적응할 수 없습니다. 고정 취익은 시장 변동성에 따라 조정되지 않습니다. CCI는 때때로 잘못된 신호를 생성 할 수 있습니다. 휘프사이를 피하기 위해 트렌드의 추진력에 대한 추가 판단이 필요합니다.

최적화 방향

다양한 기호에 대한 매개 변수 설정을 테스트하고 MA 기간, ATR 기간, ATR 곱셈자 등을 최적화하십시오. 적응적 인 스톱 손실을 위해 트레일링 스톱 또는 ATR 스톱을 고려하십시오. 동적 인 이윤 목표를 위해 ATR 기반의 수익을 테스트하십시오. 흔들리는 시장을 피하기 위해 CCI 신호를 취할 때 트렌드 모멘텀을 확인하는 필터를 추가하십시오. 더 나은 트렌드 검증을 위해 수치화 가능한 트렌드 강도 지표를 추가하십시오.

요약

트렌드 역전 시스템은 트렌드를 식별하기 위해 이동 평균, CCI 및 슈퍼트렌드를 결합하여 트렌드와 과잉 구매 / 과잉 판매를 리트레이싱 엔트리에 사용합니다. 비교적 높은 안정성과 승률을 가지고 있지만 스톱 로스, 수익 취득 및 트렌드 검증 메커니즘은 기호 및 시장 조건 전반에 걸쳐 안정성을 위해 추가 최적화가 필요합니다. 전반적으로 트렌드 기회를 잡기 위해 지표를 결합하는 간단하고 직접적인 접근 방식을 사용하고 있으며 더 많은 연구와 적용이 필요합니다.


/*backtest
start: 2022-10-16 00:00:00
end: 2023-01-08 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/
// © greenmask9

//@version=4
strategy("Oath", overlay=true)

// 21 EMA
emalength = input(21, title="Short EMA")
emashort = ema(close, emalength)

// 55 EMA
emalength2 = input(55, title="Long EMA")
ema = ema(close, emalength2)

//CCI calculation and inputs
lengthcci = input(20, minval=1, title="Overbought/sold detector period")
src = input(close, title="Overbought/sold detector source")
ma = sma(src, lengthcci)
ccivalue = (src - ma) / (0.015 * dev(src, lengthcci))


//CCI plotting
ccioverbought = input(defval=100, title="Overbought level 1")
ccioverbought2 = input(defval=140, title="Overbought level 2")
ccioverbought3 = input(defval=180, title="Overbought level 3")

ccioversold = input(defval=-100, title="Oversold level 1")
ccioversold2 = input(defval=-140, title="Oversold level 2")
ccioversold3 = input(defval=-180, title="Oversold level 3")

//cciOB = (ccivalue >= ccioverbought and ccivalue < ccioverbought2)
//cciOS = (ccivalue <= ccioversold and ccivalue > ccioversold2)

//cciOB2 = (ccivalue >= ccioverbought2 and ccivalue < ccioverbought3)
//cciOS2 = (ccivalue <= ccioversold and ccivalue > ccioversold3)

//cciOB3 = (ccivalue >= ccioverbought3)
//cciOS3 = (ccivalue <= ccioversold3)

//Supertrend

length = input(title="ATR Period", type=input.integer, defval=55)
mult = input(title="ATR Multiplier", type=input.float, step=0.1, defval=5.0)
wicks = input(title="Take Wicks into Account ?", type=input.bool, defval=true)
illuminate = input(title="Illuminate Trend", type=input.bool, defval=false)

atr = mult * atr(length)

longStop = hl2 - atr
longStopPrev = nz(longStop[1], longStop)
longStop := (wicks ? low[1] : close[1]) > longStopPrev ? max(longStop, longStopPrev) : longStop

shortStop = hl2 + atr
shortStopPrev = nz(shortStop[1], shortStop)
shortStop := (wicks ? high[1] : close[1]) < shortStopPrev ? min(shortStop, shortStopPrev) : shortStop

dir = 1
dir := nz(dir[1], dir)
dir := dir == -1 and (wicks ? high : close) > shortStopPrev ? 1 : dir == 1 and (wicks ? low : close) < longStopPrev ? -1 : dir

//entries
uptrend = emashort>ema and dir == 1
upsignal = ccivalue<=ccioversold and ccivalue>ccioversold2
upsignal2 = ccivalue<=ccioversold2 and ccivalue>ccioversold3
upsignal3 = ccivalue<=ccioversold3
downtrend = emashort<ema and dir == -1
downsignal = ccivalue>=ccioverbought and ccivalue<ccioverbought2
downsignal2 = ccivalue>=ccioverbought2 and ccivalue<ccioverbought3
downsignal3 = ccivalue>=ccioverbought3

//adapts to the current bar, I need to save the bars number when the condition for buy was true, static number is spread
spread = input (0.00020, title="Spread")
upstoploss = longStop - spread
downstoploss = shortStop + spread
strategy.initial_capital = 50000
ordersize=floor(strategy.initial_capital/close)
testlong = input(title="Test longs", type=input.bool, defval=true)
testshort = input(title="Test shorts", type=input.bool, defval=true)
//new
degree = input(title="Test level 1 overbought/sold levels", type=input.bool, defval=true)
degree2 = input(title="Test level 2 overbought/sold levels", type=input.bool, defval=false)
degree3 = input(title="Test level 3 overbought/sold levels", type=input.bool, defval=false)

statictarget = input(title="Use static target", type=input.bool, defval=true)
statictargetvalue = input(title="Static target in pips", type=input.integer, defval=400)

//timetrade = input(title="Open trades only withing specified time", type=input.bool, defval=true)
//timtrade = input()

//přidat možnost TP podle ATR a sl podle ATR
buy1 = uptrend and upsignal and strategy.opentrades==0 and testlong and degree
x1 = barssince (buy1)
if (buy1)
//bodlo by zakázat atrtarget v tomto případě
    if (statictarget)
        strategy.entry("Oath1", strategy.long, ordersize)
        strategy.exit( "Oath1 Close", from_entry="Oath1" , profit=statictargetvalue,stop=upstoploss[x1])
 
buy2 = uptrend and upsignal2 and strategy.opentrades==0 and testlong and degree2
x2 = barssince (buy2)
if (buy2)
//bodlo by zakázat atrtarget v tomto případě
    if (statictarget)
        strategy.entry("Oath2", strategy.long, ordersize)
        strategy.exit( "Oath2 Close", from_entry="Oath2" , profit=statictargetvalue,stop=upstoploss[x2])
  
buy3 = uptrend and upsignal3 and strategy.opentrades==0 and testlong and degree3
x3 = barssince (buy3)
if (buy3)
//bodlo by zakázat atrtarget v tomto případě
    if (statictarget)
        strategy.entry("Oath3", strategy.long, ordersize)
        strategy.exit( "Oath3 Close", from_entry="Oath3" , profit=statictargetvalue,stop=upstoploss[x3])

sell1 = downtrend and downsignal and strategy.opentrades==0 and testshort and degree
y1 = barssince (sell1)
if (sell1)
    if (statictarget)
        strategy.entry("Oath1.s", strategy.short, ordersize)
        strategy.exit( "Oath1 Close", from_entry="Oath1.s" , profit=statictargetvalue,stop=downstoploss[y1])

sell2 = downtrend and downsignal2 and strategy.opentrades==0 and testshort and degree2
y2 = barssince (sell2)
if (sell2)
    if (statictarget)
        strategy.entry("Oath2.s", strategy.short, ordersize)
        strategy.exit( "Oath2 Close", from_entry="Oath2.s" , profit=statictargetvalue,stop=downstoploss[y2])

sell3 = downtrend and downsignal3 and strategy.opentrades==0 and testshort and degree3
y3 = barssince (sell3)
if (sell3)
    if (statictarget)
        strategy.entry("Oath3.s", strategy.short, ordersize)
        strategy.exit( "Oath3 Close", from_entry="Oath3.s" , profit=statictargetvalue,stop=downstoploss[y3])

plotshape(uptrend and upsignal and degree, location=location.belowbar, color=color.green, transp=0, style=shape.triangleup, size=size.tiny, text="Oath up")
plotshape(downtrend and downsignal and degree, location=location.abovebar, color=color.red, transp=0, style=shape.triangledown, size=size.tiny, text="Oath down")
plotshape(uptrend and upsignal2 and degree2, location=location.belowbar, color=color.green, transp=0, style=shape.triangleup, size=size.tiny, text="Oath up+")
plotshape(downtrend and downsignal2 and degree2, location=location.abovebar, color=color.red, transp=0, style=shape.triangledown, size=size.tiny, text="Oath down+")
plotshape(uptrend and upsignal3 and degree3, location=location.belowbar, color=color.green, transp=0, style=shape.triangleup, size=size.tiny, text="Oath up++")
plotshape(downtrend and downsignal3 and degree3, location=location.abovebar, color=color.red, transp=0, style=shape.triangledown, size=size.tiny, text="Oath down++")



더 많은