PPO 황소/곰의 격차 거래 전략

저자:차오장, 날짜: 2023-09-21 15:16:50
태그:

전반적인 설명

이 전략은 트렌드 트레이딩을 위해 PPO 디버전스 패턴을 사용하며, 스톱 로스 출구에 대한 가격 높은/저하점을 사용합니다.

어떻게 작동 합니까?

  1. PPO 지표를 계산합니다.

  2. PPO 황소/곰의 오차를 확인합니다.

  3. 가격이 PPO에서 벗어나면 트레이드를 입력합니다.

  4. 최근 최고/하위 가격에서 손실을 막는 출구

장점

  • PPO 지표의 트렌드를 포착합니다.
  • 격차 신호가 강합니다.
  • 명확한 스톱 로스 포인트
  • 중장기 동향을 파악합니다.

위험성

  • 중등적인 오차 인식 정확성
  • 손실 크기를 효과적으로 제어 할 수 없습니다.
  • 약간의 지연, 추세를 잘못 판단 할 수 있습니다
  • 더 높은 수수료 및 미끄러짐 비용

최적화 방향

  • 감수성을 위해 PPO 매개 변수를 최적화
  • 다른 지표와 함께 필터를 추가
  • 손실 통제를 위해 후속 정지를 포함
  • 이윤 취득의 추가 메커니즘을 고려하십시오.
  • 분산 패턴 인식 논리를 개선

결론

이 전략은 PPO의 트렌드 특성을 활용합니다. 매개 변수, 논리 및 리스크 통제를 더 개선하면 성능을 향상시킬 수 있습니다. 그러나 본질적인 위험이 해결되어야합니다. 전반적으로 PPO의 오차를 기반으로 한 실용적인 트렌드 거래 접근 방식.


/*backtest
start: 2022-09-14 00:00:00
end: 2023-03-11 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=2
//Credit to https://www.tradingview.com/script/p3oqCa56-Pekipek-s-PPO-Divergence-BETA/ (I just changed the visuals a bit)
//A simple strategy that uses the divergences to open trades and the highs/lows to close them. Would love to see any variations! - @scarf
//FYI: I have alerts set up for the purple and orange circles on daily forex charts amd I get a lot of excellent trade entries.
strategy("PPO Bull/Bear Divergence to High/Low Trader", overlay=false)

source = open
long_term_div = input(true, title="Use long term Divergences?")
div_lookback_period = input(55, minval=1, title="Lookback Period")
fastLength = input(12, minval=1), slowLength=input(26,minval=1)
signalLength=input(9,minval=1)
smoother = input(2,minval=1)
fastMA = ema(source, fastLength)
slowMA = ema(source, slowLength)
macd = fastMA - slowMA
macd2=(macd/slowMA)*100
d = sma(macd2, smoother) // smoothing PPO
 
bullishPrice = low 

priceMins = bullishPrice > bullishPrice[1] and bullishPrice[1] < bullishPrice[2] or low[1] == low[2] and low[1] < low and low[1] < low[3] or low[1] == low[2] and low[1] == low[3] and low[1] < low and low[1] < low[4] or low[1] == low[2] and low[1] == low[3] and low[1] and low[1] == low[4] and low[1] < low and low[1] < low[5] // this line identifies bottoms and plateaus in the price
oscMins= d > d[1] and d[1] < d[2] // this line identifies bottoms in the PPO

BottomPointsInPPO = oscMins

bearishPrice = high
priceMax = bearishPrice < bearishPrice[1] and bearishPrice[1] > bearishPrice[2] or high[1] == high[2] and high[1] > high and high[1] > high[3] or high[1] == high[2] and high[1] == high[3] and high[1] > high and high[1] > high[4] or high[1] == high[2] and high[1] == high[3] and high[1] and high[1] == high[4] and high[1] > high and high[1] > high[5]  // this line identifies tops in the price
oscMax = d < d[1] and d[1] > d[2]   // this line identifies tops in the PPO

TopPointsInPPO = oscMax

currenttrough4=valuewhen (oscMins, d[1], 0) // identifies the value of PPO at the most recent BOTTOM in the PPO
lasttrough4=valuewhen (oscMins, d[1], 1) // NOT USED identifies the value of PPO at the second most recent BOTTOM in the PPO
currenttrough5=valuewhen (oscMax, d[1], 0) // identifies the value of PPO at the most recent TOP in the PPO
lasttrough5=valuewhen (oscMax, d[1], 1) // NOT USED identifies the value of PPO at the second most recent TOP in the PPO

currenttrough6=valuewhen (priceMins, low[1], 0) // this line identifies the low (price) at the most recent bottom in the Price
lasttrough6=valuewhen (priceMins, low[1], 1) // NOT USED this line identifies the low (price) at the second most recent bottom in the Price
currenttrough7=valuewhen (priceMax, high[1], 0) // this line identifies the high (price) at the most recent top in the Price
lasttrough7=valuewhen (priceMax, high[1], 1) // NOT USED this line identifies the high (price) at the second most recent top in the Price

delayedlow = priceMins and barssince(oscMins) < 3 ? low[1] : na
delayedhigh = priceMax and barssince(oscMax) < 3 ? high[1] : na

// only take tops/bottoms in price when tops/bottoms are less than 5 bars away
filter = barssince(priceMins) < 5 ? lowest(currenttrough6, 4) : na
filter2 = barssince(priceMax) < 5 ? highest(currenttrough7, 4) : na

//delayedbottom/top when oscillator bottom/top is earlier than price bottom/top
y11 = valuewhen(oscMins, delayedlow, 0)
y12 = valuewhen(oscMax, delayedhigh, 0)

// only take tops/bottoms in price when tops/bottoms are less than 5 bars away, since 2nd most recent top/bottom in osc
y2=valuewhen(oscMax, filter2, 1) // identifies the highest high in the tops of price with 5 bar lookback period SINCE the SECOND most recent top in PPO
y6=valuewhen(oscMins, filter, 1) // identifies the lowest low in the bottoms of price with 5 bar lookback period SINCE the SECOND most recent bottom in PPO

long_term_bull_filt = valuewhen(priceMins, lowest(div_lookback_period), 1)
long_term_bear_filt = valuewhen(priceMax, highest(div_lookback_period), 1)

y3=valuewhen(oscMax, currenttrough5, 0) // identifies the value of PPO in the most recent top of PPO 
y4=valuewhen(oscMax, currenttrough5, 1) // identifies the value of PPO in the second most recent top of PPO 

y7=valuewhen(oscMins, currenttrough4, 0) // identifies the value of PPO in the most recent bottom of PPO
y8=valuewhen(oscMins, currenttrough4, 1) // identifies the value of PPO in the SECOND most recent bottom of PPO

y9=valuewhen(oscMins, currenttrough6, 0)
y10=valuewhen(oscMax, currenttrough7, 0)

bulldiv= BottomPointsInPPO ? d[1] : na // plots dots at bottoms in the PPO
beardiv= TopPointsInPPO ? d[1]: na // plots dots at tops in the PPO


i = currenttrough5 < highest(d, div_lookback_period) // long term bearish oscilator divergence
i2 = y10 > long_term_bear_filt // long term bearish top divergence
i3 = delayedhigh > long_term_bear_filt // long term bearish delayedhigh divergence

i4 = currenttrough4 > lowest(d, div_lookback_period) // long term bullish osc divergence
i5 = y9 < long_term_bull_filt // long term bullish bottom div
i6 = delayedlow < long_term_bull_filt // long term bullish delayedbottom div


plot(0, color=gray)
plot(d, color=black)
plot(bulldiv, title = "Bottoms", color=maroon, style=circles, linewidth=3, offset= -1)
plot(beardiv, title = "Tops", color=green, style=circles, linewidth=3, offset= -1)

bearishdiv1 = (y10 > y2 and oscMax and y3 < y4) ? true : false
bearishdiv2 = (delayedhigh > y2 and y3 < y4) ? true : false
bearishdiv3 = (long_term_div and oscMax and i and i2) ? true : false
bearishdiv4 = (long_term_div and i and i3) ? true : false

bullishdiv1 = (y9 < y6 and oscMins and y7 > y8) ? true : false
bullishdiv2 = (delayedlow < y6 and y7 > y8) ? true : false
bullishdiv3 = (long_term_div and oscMins and i4 and i5) ? true : false
bullishdiv4 = (long_term_div and i4 and i6) ? true : false

bearish = bearishdiv1 or bearishdiv2 or bearishdiv3 or bearishdiv4
bullish = bullishdiv1 or bullishdiv2 or bullishdiv3 or bullishdiv4

//Used for alerts when this is an indicator, not a strategy
//alertcondition( bearishdiv, title="Bearish Div", message="Bearish Div: Short " ) 
//alertcondition( bullishdiv, title="Bullish Div", message="Bullish Div: Long " )

plot(y10>y2 and oscMax and y3 < y4 ? d :na, title = "Bearish Divergence1", color=orange, style= circles, linewidth=6)
plot(y9<y6 and oscMins and y7 > y8 ? d :na, title = "Bullish Divergence1", color=purple, style=circles, linewidth=6)
plot(delayedhigh>y2 and y3 < y4 ? d :na, title = "Bearish Divergence2", color=orange, style= circles, linewidth=6)
plot(delayedlow<y6 and y7 > y8 ? d :na, title = "Bullish Divergence2", color=purple, style=circles, linewidth=6)

plot(long_term_div and oscMax and i and i2 ? d :na, title = "Bearish Divergence3", color=orange, style= circles, linewidth=6)
plot(long_term_div and oscMins and i4 and i5 ? d : na, title = "Bullish Divergence3", color=purple, style=circles, linewidth=6)
plot(long_term_div and i and i3 ? d :na, title = "Bearish Divergence4", color=orange, style= circles, linewidth=6)
plot(long_term_div and i4 and i6 ? d : na, title = "Bullish Divergence4", color=purple, style=circles, linewidth=6)

// Enters trade on orange or purple circle
if (bullish)
    strategy.entry("Long", strategy.long)

if (bearish)
    strategy.entry("Short", strategy.short)

// Exit trade on red or green dot
if (beardiv)
    strategy.close("Long")

if (bulldiv)
    strategy.close("Short")



더 많은