촛불 패턴 거래 전략

저자:차오장, 날짜: 2024-02-19 15:07:33
태그:

img

전반적인 설명

이것은 촛불 패턴을 기반으로 한 자동 거래 전략입니다. 전략은 다양한 촛불 패턴 신호를 식별하고 패턴 조건이 충족되면 위험을 제어하기 위해 설정된 스톱 손실, 영업 및 트레일링 스톱으로 포지션을 입력합니다.

전략 논리

이 전략은 주로 다음과 같은 촛불 패턴을 입력 신호로 식별합니다. 포식 패턴, 하라미 패턴, 뚫린 선 / 어두운 구름 덮개, 아침 별 / 저녁 별, 벨트 보유 패턴, 세 명의 흰 군인 / 세 명의 검은 까마귀 패턴, 남쪽 패턴의 세 개의 별 등. 상승 신호가 감지되면 길게 이동하고 하락 신호가 감지되면 짧게 이동합니다.

또한, 스톱 로스, 트레이프 로프 및 트레이링 스톱은 리스크 제어를 위해 구성되어 있습니다. 구체적으로, 스톱 로스는 엔트리 가격 이하의 특정 비율로 설정되어 있으며, 엔트리 가격 이상의 특정 피프의 수익 타겟을 취하고, 엔트리 이상의 특정 동적 수준에서 트레이링 스톱 트레일을 취합니다. 이것은 효과적으로 허용 가능한 금액을 초과하는 손실을 방지합니다.

모든 포지션은 전략에서 정의된 거래 세션 밖에서 닫히므로 오버나이트 리스크가 제거된다는 점에 유의해야합니다.

이점 분석

이 전략의 가장 큰 장점은 진입을 결정하기 위해 효과적인 기술적 지표인 촛불 패턴을 사용하는 데 있다. 방대한 역사적 데이터는 특정 독특한 촛불 형성이 수시로 수요/공급 역학 및 시장 심리학의 변화를 의미한다는 것을 보여주었으며, 따라서 진입에 대한 좋은 타이밍을 제공합니다.

또 다른 장점은 포괄적 인 위험 관리 메커니즘입니다. 손실 중지, 이익 취득 및 후속 중지 허용 범위를 넘어 손실을 크게 줄일 수 있습니다.

마지막으로, 전략은 패턴 매개 변수와 리스크 제어 매개 변수를 조정하여 다른 도구와 거래 선호도에 맞게 실행할 수 있습니다.

위험 분석

이 전략의 가장 큰 위험은 기술 지표로서 촛불 패턴 자체의 고유한 불안정성에서 비롯됩니다. 촛불 패턴이 시장 트렌드 변화를 명확히 반영 할 수 있지만 시장의 무작위 변동에도 민감하며 잠재적으로 잘못된 신호로 이어집니다.

또한 촛불 형성과 그 후의 가격 행동 사이에 인과 관계가 없습니다. 전형적인 패턴이 검출되더라도 가격이 예상 된 패턴 결과에 반대 할 수 있습니다.

위의 위험을 완화하기 위해서는 스톱 로스, 취익 및 트래일링 스톱 규칙을 엄격히 준수하는 것이 필수적입니다. 촛불 패턴을 다른 더 안정적인 지표와 결합하면 기술 패턴에만 의존하는 잠재적 인 위험을 피하는 데 도움이 될 수 있습니다.

최적화 방향

촛불 패턴의 한계를 감안할 때, 볼링거 밴드, 트렌드 이동 평균 또는 RSI 및 MACD와 같은 오시레이터와 같은 더 강력한 지표와 결합하면 입시 타이밍과 신호 품질을 개선하는 것이 가치가 있습니다.

또 다른 전망적 최적화 방향은 패턴과 실제 가격 움직임 사이의 통계적 관계를 밝히기 위해 큰 역사적 데이터에 훈련된 기계 학습 모델을 활용하여 패턴 신호의 정확성을 향상시키는 것입니다.

마지막으로, 이 전략은 더 정교한 알고리즘으로 업그레이드 될 수 있는 프레임워크로 사용될 수 있습니다. 예를 들어 더 섬세한 스톱 로스 방법, 고급 언어를 통해 더 많은 데이터 인터페이스를 가진 복잡한 모델링.

결론

결론적으로, 이것은 라이브 테스트를 가치가있는 전략이며, 신호 입력을위한 효율적인 촛불 패턴을 사용하여, 포괄적인 스톱 손실 / 취득 / 트레일링 스톱 로직을 사용하여 위험을 제어합니다. 코딩 앵글은 더 나은 라이브 결과를 생성하기 위해이 프레임워크에 기반한 최적화를 권장합니다.


/*backtest
start: 2024-01-01 00:00:00
end: 2024-01-31 23:59:59
period: 4h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4

//DanyChe
//The script allows you to test popular candlestick patterns on various instruments and timeframes. In addition, you can configure risk management (if the value is zero, it means the function is disabled), and you can also specify the time of the trading session (for example, so that the positions are not transferred to the next day). 
//The author is grateful to JayRogers and Phi35, their code examples helped a lot in writing the strategy.
strategy("Candle Patterns Strategy", shorttitle="CPS", overlay=true)

//--- Patterns Input ---

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

//--- Risk Management Input ---

inpsl = input(defval = 100, title="Stop Loss", minval = 0)
inptp = input(defval = 1000, title="Take Profit", minval = 0)
inptrail = input(defval = 40, 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
tp = inptp >= 1 ? inptp : na
trail = inptrail >= 1 ? inptrail : na

//--- Session Input ---

sess = input(defval = "0000-0000", title="Trading session")
t = time('240', 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 ---

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

strategy.entry("long", true, when = SignalUp and session_open)
strategy.entry("short", false, when = SignalDown and session_open)
strategy.close("long", when = not session_open)
strategy.close("short", when = not session_open)
strategy.exit("Risk Exit long", from_entry = "long", profit = tp, trail_points = trail, loss = sl)
strategy.exit("Risk Exit short", from_entry = "short", profit = tp, trail_points = trail, loss = sl )

더 많은