카드 기반 전략


생성 날짜: 2024-02-19 15:07:33 마지막으로 수정됨: 2024-02-19 15:07:33
복사: 1 클릭수: 593
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

카드 기반 전략

개요

이것은 카드 모양을 기반으로 한 자동 거래 전략이다. 이 전략은 여러 가지 카드 모양 신호를 인식하여 형태 조건이 충족되면 입장을 취하고, 중지, 중지 및 추적 중단을 설정하여 위험을 제어한다.

전략 원칙

이 전략은 주로 다음과 같은 카드 형태를 진입 신호로 식별한다. 패키지 형태, 포장 형태, 쌍방향 형태, 선별 형태, 검은 구름 압도 도시 형태, 임신 라인 형태, 삼병 형태, 기단 바닥 형태 등이다. 위의 구매 신호가 감지되면 더 많은 진입을 한다. 판매 신호가 감지되면 빈 진입을 한다.

또한, 전략은 위험을 제어하기 위해 중지, 중지 및 추적 스톱을 설정합니다. 구체적으로, 중지 지점은 출입 가격의 특정 퍼센트 아래로 설정되어 있으며, 중지 지점은 출입 가격 이상의 고정 값이며, 트래킹 스톱은 출입 가격 이상의 특정 동적 지점입니다.

강조할 점은, 이 전략은 또한 거래 시간을 설정하고, 모든 포지션은 전략이 정의한 거래 시간에 포지션을 청산하여, 하룻밤의 위험을 방지한다.

우위 분석

이 전략의 가장 큰 장점은 카드 형태를 입시 근거로 사용하는 데 있습니다. 많은 역사적 자료는 특정 K 선 형태가 나타나면 수요 공급 관계와 시장 심리의 전환을 나타낼 가능성이 높다는 것을 보여줍니다. 이것은 우리의 입시에 좋은 시점을 제공합니다.

또 다른 장점은 완벽한 위험 제어 메커니즘이 설정되어 있다는 것입니다. 스톱, 스톱 또는 추적 스톱으로 손실을 막고 위험을 통제 할 수 있습니다.

마지막으로, 전략은 다양한 품종과 거래 선호도에 맞게 형태 변수와 위험 제어 변수를 조정하여 유연하게 작동합니다.

위험 분석

이 전략의 가장 큰 위험은 기술 지표로서 카드 모양 자체의 불안정성이다. 카드 모양은 시장의 변화 추세를 명확하게 반영 할 수 있지만 시장의 무작위적인 변동에 영향을 받을 수 있으므로 잘못된 신호가 발생할 확률은 낮지 않습니다.

또한, 카드 형태와 사후에 확인된 가격 변화 사이에 필연적인 인과관계가 없다. 전형적인 형태가 검출된다고 하더라도, 형태 예상과는 반대 방향으로 가격이 들어가는 확률도 존재한다.

위와 같은 위험을 줄이기 위해, 단 하나의 기술 지표로 인한 잠재적인 위험을 피하기 위해, 중단, 중단 및 추적 중단 규칙을 엄격하게 준수하는 것 외에도, 다른 안정적인 지표와 결합하는 것을 고려할 수 있습니다.

최적화 방향

카드 모양의 안정성의 한계를 고려하여, 후속적으로 더 안정적인 지표와 결합하여 시도할 수 있습니다. 예를 들어, 부린 밴드, 이동 평균과 같은 추세형 지표, 또는 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 )