촛불 패턴 기반 전략

저자:차오장, 날짜: 2023-09-22 12:28:59
태그:

전반적인 설명

이 전략은 촛불 패턴을 기반으로 다른 촛불 신호를 식별하고 트렌드를 따라 거래합니다. 스톱 로스, 영리 및 트레일링 스톱과 같은 적절한 리스크 관리 방법을 사용하면 시장 변동의 영향을 줄이기를 목표로합니다.

전략 논리

이 전략은 주로 거래 신호에 대한 다음 촛불 패턴을 식별합니다.

  • 글링: 상승 추세와 하락 추세

  • 파이어싱 라인/다크 클라우드 커버: 상승 파이어싱 라인 및 하락 암흑 클라우드 커버 패턴

  • 아침 별/밤 별: 상승성 아침 별과 하락성 저녁 별 패턴

  • 벨트 홀드 (Belt Hold): 올림 벨트 홀드 (bullish belt hold) 와 하림 벨트 홀드 (bearish belt hold) 패턴

  • 3개의 흰 군인/3개의 검은 까마귀: 3개의 흰 군인과 3개의 검은 까마귀 패턴

  • 남쪽의 3개의 별: 남쪽 패턴의 3개의 별

  • 스틱 샌드위치: 스틱 샌드위치 패턴

  • 미팅 라인: 상승 및 하락 미팅 라인 패턴

  • (kicking): 올림 (bullish kicking) 과 하림 (bearish kicking) 패턴

  • 사다리 바닥: 사다리 바닥 패턴

이러한 촛불 신호를 감지하면 미리 정의된 스톱 로스로 다음 바의 오픈 가격 근처에 대기 주문을 배치하고 트렌드를 따라 수익을 취합니다. 또한 리딩 스톱과 브레이크 이븐 스톱을 사용하여 위험을 관리합니다.

또한 이동 평균 필터를 추가하여 가격이 MA의 잘못된 쪽에 있을 때 신호를 취하지 않도록 합니다.

장점

  1. 고전적인 촛불 패턴을 바탕으로 보편적으로 적용할 수 있습니다.

  2. 패턴 규칙에 기반한 기계적 거래, 주관적 요인에 영향을 받지 않습니다.

  3. 합리적인 스톱 로스 및 수익 설정으로 단일 거래 리스크를 제어합니다.

  4. 트레일링 스톱 메커니즘은 시장과 함께 스톱 손실을 동적으로 조정합니다.

  5. MA 필터는 잘못된 거래에 걸리지 않도록 더 많은 논리를 추가합니다.

위험 과 해결책

  1. 촛불 패턴에는 잘못된 식별 문제가 있습니다. 이는 잘못된 신호로 이어질 수 있습니다. 매개 변수를 최적화하거나 유효하지 않은 패턴을 필터링할 수 있습니다.

  2. 정적 스톱 손실은 시장 사건의 위험을 완전히 피할 수 없습니다. 더 넓은 스톱 또는 트레일링 스톱을 사용할 수 있습니다.

  3. 거래 세션에 민감하고, 24시간 운영할 수 없습니다. 거래 시간을 조정하거나 경매 필터를 추가할 수 있습니다.

  4. MA 필터는 몇 가지 기회를 놓칠 수 있습니다. MA 기간을 줄일 수 있습니다. 또는 필터를 제거 할 수 있습니다.

  5. 갈등 때문에 길고 짧은 양쪽 모두에서 이익을 얻는 것이 어렵습니다. 길고 짧은 전략을 분리 할 수 있습니다.

최적화 방향

  1. 촛불 패턴의 매개 변수를 최적화하여 식별을 개선합니다.

  2. 최적의 방법을 찾기 위해 다른 트레일링 스톱 방법을 테스트하십시오.

  3. 돈 관리나 변동성 스톱 로스 같은 보다 고급 리스크 관리 기술을 시도해보세요.

  4. 필터링 논리를 개선하기 위해 더 많은 필터를 추가합니다.

  5. 기계 학습을 이용한 촛불 패턴 인식 모델을 구축합니다.

  6. 긴 신호와 짧은 신호를 모두 식별할 수 있는 전략 논리를 개발합니다.

요약

이 전략은 트렌드 검출을 위해 고전적인 촛불 패턴을 사용하여 신호에 따라 기계적으로 거래를합니다. 엄격한 스톱 로스 및 트레일링 스톱을 통해 위험을 관리하고 MA 필터를 추가하여 논리를 개선합니다. 전략은 이해하기 쉽고 구현 할 수 있지만 잘못된 식별 및 매개 변수 조정의 어려움과 같은 문제도 있습니다. 더 나은 성능을 달성하기 위해 더 많은 기술적 지표와 기계 학습 모델을 도입하여 미래의 최적화를 수행 할 수 있습니다.


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

//@version=2
strategy("Candle Patterns Strategy - 2", shorttitle="CPS - 2", overlay=true)
// New risk management system: order entry, moving stop loss to breakeven + moving average filter (SMA)

//--- Patterns Input ---

OnEngulfing = input(defval=true, title="Engulfing", type=bool)
OnHarami = input(defval=true, title="Harami", type=bool)
OnPiercingLine = input(defval=true, title="Piercing Line / Dark Cloud Cover", type=bool)
OnMorningStar = input(defval=true, title="Morning Star / Evening Star ", type=bool)
OnBeltHold = input(defval=true, title="Belt Hold", type=bool)
OnThreeWhiteSoldiers = input(defval=true, title="Three White Soldiers / Three Black Crows", type=bool)
OnThreeStarsInTheSouth = input(defval=true, title="Three Stars in the South", type=bool)
OnStickSandwich = input(defval=true, title="Stick Sandwich", type=bool)
OnMeetingLine = input(defval=true, title="Meeting Line", type=bool)
OnKicking = input(defval=true, title="Kicking", type=bool)
OnLadderBottom = input(defval=true, title="Ladder Bottom", type=bool)

//--- Risk Management Input ---
tick = input (defval = 0.01, title="Tick Size", minval = 0.001)
inpsl = input(defval = 10, title="Stop Loss", minval = 1)
inptp = input(defval = 100, title="Take Profit", minval = 1)
inpbm = input (defval=10, title="Breakeven Margin", minval = 1)
inpindent = input(defval = 5, title="Price Movement Confirmation", minval = 0)
InpSmaFilter = input(defval=false, title="MA Filter", type=bool)
maPer=input(defval = 50, title="MA Period", minval = 1)
//inptrail = input(defval = 0, title="Trailing Stop", minval = 0)
// If the zero value is set for stop loss, take profit or trailing stop, then the function is disabled
//sl = inpsl >= 1 ? inpsl : na
sl = inpsl * tick
bm = inpbm * tick
tp = inptp //* tick
indent = inpindent * tick
//trail = inptrail >= 1 ? inptrail : na

//--- Session Input ---

sess = input(defval = "0000-0000", title="Trading Session")
t = time(timeframe.period, sess)
session_open = na(t) ? false : true

// --- Candlestick Patterns ---

//Engulfing 
bullish_engulfing = high[0]>high[1] and low[0]<low[1] and open[0]<open[1] and close[0]>close[1] and close[0]>open[0] and close[1]<close[2] and close[0]>open[1] ? OnEngulfing : na
bearish_engulfing = high[0]>high[1] and low[0]<low[1] and open[0]>open[1] and close[0]<close[1] and close[0]<open[0] and close[1]>close[2] and close[0]<open[1] ? OnEngulfing : na

//Harami
bullish_harami =  open[1]>close[1] and close[1]<close[2] and open[0]>close[1] and open[0]<open[1] and close[0]>close[1] and close[0]<open[1] and high[0]<high[1] and low[0]>low[1] and close[0]>=open[0] ? OnHarami : na
bearish_harami =   open[1]<close[1] and close[1]>close[2] and open[0]<close[1] and open[0]>open[1] and close[0]<close[1] and close[0]>open[1] and high[0]<high[1] and low[0]>low[1] and close[0]<=open[0] ? OnHarami : na

//Piercing Line/Dark Cloud Cover 
piercing_line = close[2]>close[1] and open[0]<low[1] and close[0]>avg(open[1],close[1]) and close[0]<open[1] ? OnPiercingLine : na
dark_cloud_cover = close[2]<close[1] and open[0]>high[1] and close[0]<avg(open[1],close[1]) and close[0]>open[1] ? OnPiercingLine : na

//Morning Star/Evening Star
morning_star = close[3]>close[2] and close[2]<open[2] and open[1]<close[2] and close[1]<close[2] and open[0]>open[1] and open[0]>close[1] and close[0]>close[2] and open[2]-close[2]>close[0]-open[0] ? OnMorningStar : na
evening_star = close[3]<close[2] and close[2]>open[2] and open[1]>close[2] and close[1]>close[2] and open[0]<open[1] and open[0]<close[1] and close[0]<close[2] and close[2]-open[2]>open[0]-close[0] ? OnMorningStar : na

//Belt Hold
bullish_belt_hold = close[1]<open[1] and low[1]>open[0] and close[1]>open[0] and open[0]==low[0] and close[0]>avg(close[0],open[0]) ? OnBeltHold :na
bearish_belt_hold =  close[1]>open[1] and high[1]<open[0] and close[1]<open[0] and open[0]==high[0] and close[0]<avg(close[0],open[0]) ? OnBeltHold :na

//Three White Soldiers/Three Black Crows 
three_white_soldiers = close[3]<open[3] and open[2]<close[3] and close[2]>avg(close[2],open[2]) and open[1]>open[2] and open[1]<close[2] and close[1]>avg(close[1],open[1]) and open[0]>open[1] and open[0]<close[1] and close[0]>avg(close[0],open[0]) and high[1]>high[2] and high[0]>high[1] ? OnThreeWhiteSoldiers : na
three_black_crows =  close[3]>open[3] and open[2]>close[3] and close[2]<avg(close[2],open[2]) and open[1]<open[2] and open[1]>close[2] and close[1]<avg(close[1],open[1]) and open[0]<open[1] and open[0]>close[1] and close[0]<avg(close[0],open[0]) and low[1]<low[2] and low[0]<low[1] ? OnThreeWhiteSoldiers : na

//Three Stars in the South
three_stars_in_the_south = open[3]>close[3] and open[2]>close[2] and open[2]==high[2] and open[1]>close[1] and open[1]<open[2] and open[1]>close[2] and low[1]>low[2] and open[1]==high[1] and open[0]>close[0] and open[0]<open[1] and open[0]>close[1] and open[0]==high[0] and close[0]==low[0] and close[0]>=low[1] ? OnThreeStarsInTheSouth : na

//Stick Sandwich
stick_sandwich = open[2]>close[2] and open[1]>close[2] and open[1]<close[1] and open[0]>close[1] and open[0]>close[0] and close[0]==close[2] ? OnStickSandwich : na

//Meeting Line 
bullish_ml = open[2]>close[2] and open[1]>close[1] and close[1]==close[0] and open[0]<close[0] and open[1]>=high[0] ? OnMeetingLine : na
bearish_ml = open[2]<close[2] and open[1]<close[1] and close[1]==close[0] and open[0]>close[0] and open[1]<=low[0] ? OnMeetingLine : na

//Kicking 
bullish_kicking =  open[1]>close[1] and open[1]==high[1] and close[1]==low[1] and open[0]>open[1] and open[0]==low[0] and close[0]==high[0] and close[0]-open[0]>open[1]-close[1] ? OnKicking : na
bearish_kicking = open[1]<close[1] and open[1]==low[1] and close[1]==high[1] and open[0]<open[1] and open[0]==high[0] and close[0]==low[0] and open[0]-close[0]>close[1]-open[1] ? OnKicking : na

//Ladder Bottom
ladder_bottom = open[4]>close[4] and open[3]>close[3] and open[3]<open[4] and open[2]>close[2] and open[2]<open[3] and open[1]>close[1] and open[1]<open[2] and open[0]<close[0] and open[0]>open[1] and low[4]>low[3] and low[3]>low[2] and low[2]>low[1] ? OnLadderBottom : na

// --- Plotting Patterns ---

plotshape(bullish_engulfing, text='Engulfing', style=shape.triangleup, color=#1FADA2, editable=true, title="Bullish Engulfing Text")
plotshape(bearish_engulfing,text='Engulfing', style=shape.triangledown, color=#F35A54, editable=true, title="Bearish Engulfing Text")
plotshape(bullish_harami,text='Harami', style=shape.triangleup, color=#1FADA2, editable=true, title="Bullish Harami Text")
plotshape(bearish_harami,text='Harami', style=shape.triangledown, color=#F35A54, editable=true, title="BEarish Harami Text")
plotshape(piercing_line,text='Piercing Line', style=shape.triangleup, color=#1FADA2, editable=false)
plotshape(dark_cloud_cover,text='Dark Cloud Cover', style=shape.triangledown, color=#F35A54, editable=false)
plotshape(morning_star,text='Morning Star', style=shape.triangleup, color=#1FADA2, editable=false)
plotshape(evening_star,text='Evening Star', style=shape.triangledown, color=#F35A54, editable=false)
plotshape(bullish_belt_hold,text='Belt Hold', style=shape.triangleup, color=#1FADA2, editable=false)    
plotshape(bearish_belt_hold,text='Belt Hold', style=shape.triangledown, color=#F35A54, editable=false)
plotshape(three_white_soldiers,text='Three White Soldiers', style=shape.triangleup, color=#1FADA2, editable=false)
plotshape(three_black_crows,text='Three Black Crows', style=shape.triangledown, color=#F35A54, editable=false)
plotshape(three_stars_in_the_south,text='3 Stars South', style=shape.triangleup, color=#1FADA2, editable=false)
plotshape(stick_sandwich,text='Stick Sandwich', style=shape.triangleup, color=#1FADA2, editable=false)
plotshape(bullish_ml,text='Meeting Line', style=shape.triangleup, color=#1FADA2, editable=false)
plotshape(bearish_ml,text='Meeting Line', style=shape.triangledown, color=#F35A54, editable=false)
plotshape(bullish_kicking,text='Kicking', style=shape.triangleup, color=#1FADA2, editable=false)
plotshape(bearish_kicking,text='Kicking', style=shape.triangledown, color=#F35A54, editable=false)
plotshape(ladder_bottom,text='Ladder Bottom', style=shape.triangleup, color=#1FADA2, editable=false)

// --- STRATEGY ---

SignalUp = bullish_engulfing or bullish_harami or piercing_line or morning_star or bullish_belt_hold or three_white_soldiers or three_stars_in_the_south or stick_sandwich or bullish_ml or bullish_kicking or ladder_bottom
SignalDown = bearish_engulfing or bearish_harami or dark_cloud_cover or evening_star or bearish_belt_hold or three_black_crows or bearish_ml or bearish_kicking

PointOfEntry = SignalUp ? high[0] + indent : SignalDown ? low[0] - indent : na

bu = strategy.position_avg_price
shlo = strategy.position_size
stL = shlo > 0 and close [0] > bu + bm ? bu : shlo < 0 and close [0] < bu - bm ? bu : na
du = sma(close, maPer)
smaF = SignalUp and high[0]>du[0] ? true : SignalUp and high[0]<du[0] ? false : SignalDown and high[0]>du[0] ? false : SignalDown and high[0]<du[0] ? true : na 
smaFilter = InpSmaFilter ? smaF : true
duplot = InpSmaFilter ? du : na
plot(duplot, color=red)

// -- Orders --

strategy.order("buy", true, stop = PointOfEntry, oca_name = "trade",  when = SignalUp and session_open and smaFilter)
strategy.cancel("buy", when = not session_open or SignalDown or strategy.opentrades > 0)
strategy.order("stop sell", false, stop = bu-sl, oca_name = "trade",  when = strategy.opentrades > 0 and shlo > 0 and session_open)
strategy.cancel("stop sell", close [0] > bu + bm or not session_open or strategy.opentrades == 0 )
strategy.order("breakeven sell", false, stop = bu + 1*tick, oca_name = "trade",  when = strategy.opentrades > 0 and shlo > 0 and close [0] > bu + bm and session_open)
strategy.cancel("breakeven sell", when = strategy.opentrades == 0 or not session_open)

strategy.order("sell", false, stop = PointOfEntry, oca_name = "trade",  when = SignalDown and session_open and smaFilter)
strategy.cancel("sell", when = not session_open or SignalUp or strategy.opentrades > 0)
strategy.order("stop buy", true, stop = bu+sl, oca_name = "trade",  when = strategy.opentrades > 0 and shlo < 0 and session_open)
strategy.cancel("stop buy", when = close [0] < bu - bm or not session_open or  strategy.opentrades == 0 )
strategy.order("breakeven buy", true, stop = bu - 1 * tick, oca_name = "trade",  when = strategy.opentrades > 0 and shlo < 0 and close [0] < bu - bm and session_open)
strategy.cancel("breakeven buy", when = strategy.opentrades == 0 or not session_open)

strategy.close("buy", when = not session_open or SignalDown )
strategy.close("sell", when = not session_open or SignalUp)
strategy.exit("Take Profit", from_entry = "buy", profit = tp)
strategy.exit("Take Profit", from_entry = "sell", profit = tp)

더 많은