전략 을 따르는 환자 경향

저자:차오장, 날짜: 2024-01-18 12:40:11
태그:

img

전반적인 설명

환자 트렌드 추적 전략 (Patient Trend Following Strategy) 은 트렌드 추적 전략이다. 트렌드 방향을 결정하기 위해 이동 평균과 거래 신호를 생성하기 위해 CCI 오시일레이터의 조합을 사용합니다. 이 전략은 큰 트렌드를 추구하고 범위 시장에서 윙스를 효과적으로 피할 수 있습니다.

전략 논리

이 전략은 트렌드 방향을 정의하기 위해 21 기간 및 55 기간 EMA 조합을 사용합니다. 짧은 EMA가 긴 EMA보다 높을 때 상승 추세가 정의됩니다. 짧은 EMA가 긴 EMA보다 낮을 때 하락 추세가 정의됩니다.

CCI 지표는 과잉 구매 및 과잉 판매 상황을 탐지하는 데 사용됩니다. CCI가 -100을 넘어서면 최하위 과잉 판매 상태를 신호하고 100을 넘어서면 최하위 과잉 구매 상태를 신호합니다. CCI의 다른 과잉 구매 및 과잉 판매 수준은 다른 신뢰 수준으로 거래 신호를 생성합니다.

상승 추세가 결정되면 CCI의 강한 하부 과잉 판매 신호가 긴 엔트리 오더를 유발합니다. 하부 추세가 결정되면 CCI의 강한 상위 과잉 구매 신호가 짧은 엔트리 오더를 유발합니다.

스톱 로스는 슈퍼 트렌드 라인에 설정됩니다. 이윤은 피프의 고정된 수입니다.

이점 분석

이 전략의 주요 장점은 다음과 같습니다.

  1. 큰 트렌드를 따르고, 속임수를 피하는 것
  2. CCI는 역전점을 효과적으로 감지합니다.
  3. 슈퍼트렌드 (SuperTrend) 를 이용한 합리적인 스톱 로스 설정
  4. 적립된 스톱 로스 및 수익 취득, 통제 가능한 위험

위험 분석

이 전략의 주요 위험은 다음과 같습니다.

  1. 잘못된 큰 트렌드 결정의 확률
  2. CCI로부터 잘못된 신호가 나올 확률
  3. 부적절한 스톱 로스 수준으로 불필요한 스톱 로스 발생 확률
  4. 일정한 취득이익을 가진 트렌드 수익이 누락되는 확률

이러한 위험에 대처하기 위해 EMA 기간, CCI 기간 및 Stop Loss/Take Profit 수준과 같은 매개 변수를 최적화 할 수 있습니다. 신호 검증을위한 더 많은 지표를 도입하는 것도 필요합니다.

최적화 방향

주요 최적화 방향은 다음과 같습니다.

  1. 더 많은 지표 조합을 테스트하여 더 나은 트렌드 및 신호 검증 지표를 찾습니다.

  2. 동적 스톱 로스를 활용하고 ATR로 수익을 취하여 트렌드를 더 잘 추적하고 위험을 제어합니다.

  3. 트렌드 확률을 판단하기 위해 역사적인 데이터에 훈련된 기계 학습 모델을 도입합니다.

  4. 다양한 거래 도구에 대한 매개 변수를 최적화합니다.

결론

환자 트렌드 다음 전략은 전체적으로 매우 실용적인 트렌드 거래 전략입니다. 그것은 이동 평균으로 큰 트렌드를 정의하고 CCI 오시일레이터로 반전 신호를 감지하며 슈퍼 트렌드 지표를 사용하여 합리적인 스톱 로스 수준을 설정합니다. 추가 매개 변수 조정 및 신호 검증을위한 더 많은 지표 조합으로이 전략은 더 이상 최적화 될 수 있으며 라이브 거래에서 추적 할 가치가 있습니다.


/*backtest
start: 2024-01-10 00:00:00
end: 2024-01-17 00:00:00
period: 1m
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/
// © greenmask9

//@version=4
strategy("Patient Trendfollower (7) Strategy", overlay=true)

// 21 EMA
emalength = input(21, title="Short EMA")
emashort = ema(close, emalength)
plot(emashort, color = color.purple, linewidth=1)

// 55 EMA
emalength2 = input(55, title="Long EMA")
ema = ema(close, emalength2)
plot(ema, color = color.green, linewidth=1)

//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)
plotshape(cciOB,  title= "Overbought", location=location.abovebar, color=color.lime, transp=0, style=shape.circle)
cciOS = (ccivalue <= ccioversold and ccivalue > ccioversold2)
plotshape(cciOS, title= "Oversold", location=location.belowbar, color=color.lime, transp=0, style=shape.circle)

cciOB2 = (ccivalue >= ccioverbought2 and ccivalue < ccioverbought3)
plotshape(cciOB2,  title= "Overbought", location=location.abovebar, color=color.red, transp=0, style=shape.circle)
cciOS2 = (ccivalue <= ccioversold and ccivalue > ccioversold3)
plotshape(cciOS2, title= "Oversold", location=location.belowbar, color=color.red, transp=0, style=shape.circle)

cciOB3 = (ccivalue >= ccioverbought3)
plotshape(cciOB3,  title= "Overbought", location=location.abovebar, color=color.black, transp=0, style=shape.circle)
cciOS3 = (ccivalue <= ccioversold3)
plotshape(cciOS3, title= "Oversold", location=location.belowbar, color=color.black, transp=0, style=shape.circle)

//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=true)

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

longColor = color.new(color.green, 90)
shortColor = color.new(color.red, 90)
noneColor = color.new(color.white, 100)

longStopPlot = plot(dir == 1 ? longStop : na, title="Long Stop", style=plot.style_linebr, linewidth=2, color=longColor)
shortStopPlot = plot(dir == 1 ? na : shortStop, title="Short Stop", style=plot.style_linebr, linewidth=2, color=shortColor)
midPricePlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0)

longFillColor = illuminate ? (dir == 1 ? longColor : noneColor) : noneColor
shortFillColor = illuminate ? (dir == -1 ? shortColor : noneColor) : noneColor
fill(midPricePlot, longStopPlot, title="Long State Filling", color=longFillColor)
fill(midPricePlot, shortStopPlot, title="Short State Filling", color=shortFillColor)

//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("Long1", strategy.long, ordersize)
        strategy.exit( "Exitlong", from_entry="Long1" , 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("Long2", strategy.long, ordersize)
        strategy.exit( "Exitlong", from_entry="Long2" , 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("Long3", strategy.long, ordersize)
        strategy.exit( "Exitlong", from_entry="Long3" , 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("Sell1", strategy.short, ordersize)
        strategy.exit( "Exitshort", from_entry="Sell1" , 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("Sell2", strategy.short, ordersize)
        strategy.exit( "Exitshort", from_entry="Sell2" , 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("Sell3", strategy.short, ordersize)
        strategy.exit( "Exitshort", from_entry="Sell3" , profit=statictargetvalue,stop=downstoploss[y3])


더 많은