역동적 인 포식 트렌드 전략

저자:차오장, 날짜: 2024-02-29 11:24:18
태그:

img

전반적인 설명

동적 포식 트렌드 전략 (Dynamic Engulfing Trend strategy) 은 트렌드 방향으로 포식 패턴을 기반으로 긴 또는 짧은 포지션을 취하는 거래 전략이다. 이 전략은 시장 변동성을 측정하기 위해 평균 진정한 범위 (ATR), 시장 트렌드 방향을 결정하기 위해 슈퍼 트렌드 지표를 사용하여 포식 패턴이 트렌드 방향과 일치 할 때 거래를 수행합니다. 스톱 손실 및 수익 수치는 또한 포식 패턴을 기반으로 동적으로 계산됩니다.

전략 논리

  1. 시장 변동성을 측정하기 위해 ATR를 계산합니다.
  2. 슈퍼트렌드 지표를 계산해 시장 트렌드를 파악해
  3. 상승 추세와 하락 추세의 조건을 정의합니다.
  4. 상승 추세 (uptrend) 와 하락 추세 (downtrend) 를 식별합니다.
  5. 스톱 로스 (SL) 와 영업 (TP) 수준은 포용 패턴을 기반으로 계산합니다.
  6. 트렌드 방향과 일치할 때 트레이드를 입력합니다.
  7. 가격 SL 또는 TP 수준에 도달하면 출구 거래.
  8. 차트에 침몰 패턴을 그려보세요.

이점 분석

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

  1. 신호 품질을 향상시켜 포식 패턴과 트렌드를 결합합니다.
  2. 정확한 항목에 대한 트렌드 반전을 식별 할 수 있습니다.
  3. 더 나은 타이밍을 위해 긴 / 짧은 신호를 명확히하십시오.
  4. 그글링 스톱 전략은 위험을 관리하면서 추세를 따르고 있습니다.
  5. 쉬운 최적화를 위한 모듈화된 코드 프레임워크

위험 분석

또한 고려해야 할 몇 가지 위험이 있습니다.

  1. 삼키는 패턴은 거짓 탈출이 될 수 있습니다.
  2. 패턴 크기, 기간 등 최적의 매개 변수를 결정하기가 어렵습니다.
  3. 불완전한 경향 결정은 잘못된 신호로 이어질 수 있습니다.
  4. 스톱 로스 및 영업 수익 수준은 재량에 의존하고 주관적일 수 있습니다.
  5. 성능은 역사적인 데이터에 기초한 매개 변수 조정에 달려 있습니다.

위험은 다음과 같이 완화 될 수 있습니다.

  1. 가짜 신호를 제거하기 위해 필터를 추가합니다.
  2. 안정적인 매개 변수 계산을 위해 적응형 ATR을 사용합니다.
  3. 머신러닝을 이용한 트렌드 결정 개선
  4. 유전 알고리즘을 통해 최적의 매개 변수를 찾는 것
  5. 안정성을 보장하기 위해 더 긴 기간 동안 백테스팅을 합니다.

최적화 방향

더 많은 최적화를 할 수 있습니다.

  1. 머신러닝은 트렌드 결정을 개선할 수 있습니다.
  2. 새로운 패턴 인식 방법은 더 잘 포식 패턴을 식별 할 수 있습니다.
  3. 최신 스톱 로스/프로프트 전략은 레벨을 동적으로 최적화할 수 있습니다.
  4. 높은 주파수 데이터는 단기적인 시스템을 개발할 수 있습니다.
  5. 다른 악기들에 대한 매개 변수 조정

결론

요약하자면, 동적 포식 트렌드 전략은 높은 품질의 포식 패턴 신호와 정확한 트렌드 결정을 결합하여 정확한 입력과 합리적인 스톱 손실 및 수익을 창출하는 거래 시스템을 생성합니다. 매개 변수, 위험 관리 및 기술 통합의 추가 개선은 안정성과 수익성을 향상시킬 수 있습니다. 구조화된 코드 프레임워크는 또한이 전략을 다른 시장에서 사용자 정의 할 수 있습니다.


/*backtest
start: 2024-01-01 00:00:00
end: 2024-01-31 23:59:59
period: 1h
basePeriod: 15m
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/
// © Malikdrajat


//@version=4
strategy("Engulfing with Trend", overlay=true)

Periods = input(title="ATR Period", type=input.integer, defval=10)
src = input(hl2, title="Source")
Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0)
changeATR= input(title="Change ATR Calculation Method ?", type=input.bool, defval=true)
showsignals = input(title="Show Buy/Sell Signals ?", type=input.bool, defval=true)
highlighting = input(title="Highlighter On/Off ?", type=input.bool, defval=true)

atr2 = sma(tr, Periods)
atr= changeATR ? atr(Periods) : atr2

up=src-(Multiplier*atr)
up1 = nz(up[1],up)
up := close[1] > up1 ? max(up,up1) : up
dn=src+(Multiplier*atr)
dn1 = nz(dn[1], dn)
dn := close[1] < dn1 ? min(dn, dn1) : dn

trend = 1
trend := nz(trend[1], trend)
trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend

upPlot = plot(trend == 1 ? up : na, title="Up Trend", style=plot.style_linebr, linewidth=2, color=color.green)
buySignal = trend == 1 and trend[1] == -1
plotshape(buySignal ? up : na, title="UpTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green, transp=0)
plotshape(buySignal and showsignals ? up : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white, transp=0)
dnPlot = plot(trend == 1 ? na : dn, title="Down Trend", style=plot.style_linebr, linewidth=2, color=color.red)
sellSignal = trend == -1 and trend[1] == 1
plotshape(sellSignal ? dn : na, title="DownTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.red, transp=0)
plotshape(sellSignal and showsignals ? dn : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0)
mPlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0)
longFillColor = highlighting ? (trend == 1 ? color.green : color.white) : color.white
shortFillColor = highlighting ? (trend == -1 ? color.red : color.white) : color.white
fill(mPlot, upPlot, title="UpTrend Highligter", color=longFillColor)
fill(mPlot, dnPlot, title="DownTrend Highligter", color=shortFillColor)
alertcondition(buySignal, title="SuperTrend Buy", message="SuperTrend Buy!")
alertcondition(sellSignal, title="SuperTrend Sell", message="SuperTrend Sell!")
changeCond = trend != trend[1]
alertcondition(changeCond, title="SuperTrend Direction Change", message="SuperTrend has changed direction!")

// Define Downtrend and Uptrend conditions
downtrend = trend == -1
uptrend = trend == 1


// Engulfing 
boringThreshold = input(25, title="Boring Candle Threshold (%)", minval=1, maxval=100, step=1)
engulfingThreshold = input(50, title="Engulfing Candle Threshold (%)", minval=1, maxval=100, step=1)
stopLevel = input(200, title="Stop Level (Pips)", minval=1)


// Boring Candle (Inside Bar) and Engulfing Candlestick Conditions
isBoringCandle = abs(open[1] - close[1]) * 100 / abs(high[1] - low[1]) <= boringThreshold
isEngulfingCandle = abs(open - close) * 100 / abs(high - low) <= engulfingThreshold

// Bullish and Bearish Engulfing Conditions
bullEngulfing = uptrend and close[1] < open[1] and close > open[1] and not isBoringCandle and not isEngulfingCandle
bearEngulfing = downtrend and close[1] > open[1] and close < open[1] and not isBoringCandle and not isEngulfingCandle

// Stop Loss, Take Profit, and Entry Price Calculation
bullStop = close + (stopLevel * syminfo.mintick)
bearStop = close - (stopLevel * syminfo.mintick)
bullSL = low 
bearSL = high
bullTP = bullStop + (bullStop - low)
bearTP = bearStop - (high - bearStop)

// Entry Conditions
enterLong = bullEngulfing and uptrend
enterShort = bearEngulfing and downtrend

// Exit Conditions
exitLong = crossover(close, bullTP) or crossover(close, bullSL)
exitShort = crossover(close, bearTP) or crossover(close, bearSL)

// Check if exit conditions are met by the next candle
exitLongNextCandle = exitLong and (crossover(close[1], bullTP[1]) or crossover(close[1], bullSL[1]))
exitShortNextCandle = exitShort and (crossover(close[1], bearTP[1]) or crossover(close[1], bearSL[1]))

// Strategy Execution
strategy.entry("Buy", strategy.long, when=enterLong )
strategy.entry("Sell", strategy.short, when=enterShort )

// Exit Conditions for Long (Buy) Positions
if (bullEngulfing and not na(bullTP) and not na(bullSL))
    strategy.exit("Exit Long", from_entry="Buy", stop=bullSL, limit=bullTP)

// Exit Conditions for Short (Sell) Positions
if (bearEngulfing and not na(bearTP) and not na(bearSL))
    strategy.exit("Exit Short", from_entry="Sell", stop=bearSL, limit=bearTP)

// Plot Shapes and Labels
plotshape(bullEngulfing, style=shape.triangleup, location=location.abovebar, color=color.green)
plotshape(bearEngulfing, style=shape.triangledown, location=location.abovebar, color=color.red)

// Determine OP, SL, and TP
plot(bullEngulfing ? bullStop : na, title="Bullish Engulfing stop", color=color.red, linewidth=3, style=plot.style_linebr)
plot(bearEngulfing ? bearStop : na, title="Bearish Engulfing stop", color=color.red, linewidth=3, style=plot.style_linebr)
plot(bullEngulfing ? bullSL : na, title="Bullish Engulfing SL", color=color.red, linewidth=3, style=plot.style_linebr)
plot(bearEngulfing ? bearSL : na, title="Bearish Engulfing SL", color=color.red, linewidth=3, style=plot.style_linebr)
plot(bullEngulfing ? bullTP : na, title="Bullish Engulfing TP", color=color.green, linewidth=3, style=plot.style_linebr)
plot(bearEngulfing ? bearTP : na, title="Bearish Engulfing TP", color=color.green, linewidth=3, style=plot.style_linebr)



더 많은