양적 촛불 패턴 및 트렌드 다음 전략

저자:차오장, 날짜: 2024-01-31 17:24:30
태그:

img

전반적인 설명

이 전략은 양적 촛불 패턴 및 트렌드 다음 전략 (Quantitative Candlestick Pattern and Trend Following Strategy) 이라고 불립니다. 촛불 패턴 분석 및 트렌드 다음 거래의 전략 아이디어를 통합합니다.

이 전략은 주로 현재 시장 정서와 잠재적 인 전환점을 판단하기 위해 다른 촛불 패턴을 식별합니다. 가장 높은 가격과 가장 낮은 가격을 추적하여 엔트리 및 출구 신호를 형성하고 중장기 가격 추세를 파악합니다.

전략 원칙

이 전략의 주요 모듈은 다음과 같습니다.

  1. 촛불 패턴 식별

    전략은 먼저 몸, 그림자와 같은 촛불의 요소를 정의하고 도지, 아침 별, 세 내부 위 등 40 개 이상의 일반적인 촛불 패턴을 식별하기위한 몇 가지 매개 변수를 설정합니다. 이러한 패턴이 확인되면 마크가 그래프화되어 상승 또는 하락 신호로 판단됩니다.

  2. 트렌드 식별

    이 전략은 트렌드를 결정하기 위해 N 일 동안 가장 높고 가장 낮은 가격의 추적을 이용합니다. 가격이 N 일 동안 가장 높은 가격 이상으로 떨어지면 상승 추세로 판단됩니다. 가격이 N 일 동안 가장 낮은 가격 이하로 떨어지면 하락 추세로 판단됩니다.

  3. 출입 및 출입

    촛불 패턴 식별에서 상승/하락 신호와 트렌드 식별에서 최고/최저 가격의 돌파구에 따라 전략은 입출 규칙을 형성합니다.

    예를 들어, 해머와 같은 상승 패턴이 확인되고 가격이 N일 최고 가격 이상으로 넘어지면, 긴 지위를 가십시오. 가격이 N일 최저 가격 이하로 넘어지면 긴 지위를 닫습니다.

  4. 백테스트 범위 설정

    마지막으로, 전략은 전체 논리적 루프를 완료하기 위해 백테스트의 시작 및 종료 시간을 설정합니다.

이점 분석

이 전략의 장점:

  1. 패턴과 경향의 조합

    패턴 식별과 트렌드 추적을 모두 활용하여 패턴을 통해 잠재적인 전환점을 발견하고 트렌드에 따라 입력 시기를 결정할 수 있습니다.

  2. 폭넓은 패턴

    이 전략은 40 개 이상의 일반적인 촛불 패턴을 다루고 있으며, 더 많은 잠재적 인 거래 기회를 위해 다른 시장 환경에서 더 넓은 커버리지를 제공합니다.

  3. 높은 매개 변수 수성

    추적일, 패턴 식별 파라미터와 같은 매개 변수는 사용자에 의해 조정됩니다. 그것은 더 나은 적응력을 가지고 있으며 특정 시장에 더 쉽게 조정됩니다.

  4. 확장 하기 쉽다

    기존의 논리에 기반한 더 많은 패턴 식별으로 확장하거나 더 많은 요소를 추가하여 전략 성능을 더 최적화 할 수 있습니다.

위험 분석

전략의 주요 위험은:

  1. 패턴 식별의 정확성

    촛불 패턴 식별은 100%의 정확성을 제공하지 않으며, 여전히 잘못된 식별과 잘못된 신호 발사 가능성이 있습니다.

  2. 스톱 로스 모듈이 없는 경우

    현재 전략에는 스톱 로스 로직이 없으며 단일 거래의 손실을 효과적으로 제어 할 수 없습니다. 트렌드 식별이 실패하면 엄청난 손실로 이어질 수 있습니다.

  3. 백테스트의 데이터 적응 위험

    현재 좋은 결과는 백테스트 데이터에 맞게 일부 데이터 적응 위험을 초래할 수 있습니다. 실제 거래 성과가 감소 할 수 있습니다.

최적화 방향

주요 최적화 방향:

  1. 스톱 로스 모듈 추가

    이동 스톱 손실, 비율 스톱 손실 등과 같은 모듈을 추가하여 위험을 효과적으로 제어하고 거래당 최대 손실을 제한합니다.

  2. 패턴 식별의 정확성을 향상시키기 위해 기계 학습을 활용

    기계 학습 알고리즘을 사용하여 모델을 훈련하고 촛불 패턴 식별의 정확도를 향상시키고 잘못된 신호를 줄입니다.

  3. 다중시장 검증

    외환, 암호화폐와 같은 더 많은 시장에서 전략의 견고성을 테스트하여 단일 백테스트에서 데이터 적합성 위험을 피합니다.

  4. 더 많은 요인 들 을 소개 하라

    더 많은 양적 요소를 가져오면, 양과 가격 지표, 돈의 흐름 지표와 같이 전략 논리를 풍부하게 하고 안정성을 향상시킬 수 있습니다.

결론

전체적으로, 이 전략은 촛불 패턴 식별과 트렌드를 따라 거래를 결합하여 잠재적 인 전환점을 발견하고 알파를 달성하기 위해 동시에 가격 트렌드를 포착합니다. 리스크 제어, 머신 러닝 모델에서 멀티 팩터 모델에 이르기까지 최적화 공간이 풍부하여 실제 거래에 더 견고하고 가치가 있습니다.


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

//@version=3
strategy("Candle analysis & long/short strategy (HF) inspired by TurtleBC", shorttitle="TurtleBC-V.Troussel", overlay=true,initial_capital=1000)

//VARIABLES
body=close-open
range=high-low
middle=(open+close)/2
abody=abs(body)
ratio=abody/range
longcandle= (ratio>0.6)
bodytop=max(open, close)
bodybottom=min(open, close)
shadowtop=high-bodytop
shadowbottom=bodybottom-low

//Doji
DojiSize = input(0.05, minval=0.01, title="Doji size")
data=(abs(open - close) <= (high - low) * DojiSize)
plotchar(data, title="Doji", text='Doji', color=black)

//BULLISH SIGNALS
//Homing Pigeon
HomingPigeon=(body[1]<0 and body<0 and longcandle[1] and bodybottom>bodybottom[1] and bodytop<bodytop[1])
plotshape(HomingPigeon, title= "Homing Pigeon", location=location.belowbar, color=lime, style=shape.arrowup, text="Homing\nPigeon")

//Dragonfly Doji Bottom
DragonflyDojiBottom=(body[1]<0 and longcandle[1] and low<low[1] and shadowbottom>3*abody and shadowtop<shadowbottom/3)
plotshape(DragonflyDojiBottom, title= "Dragonfly Doji Bottom", location=location.belowbar, color=lime, style=shape.arrowup, text="Dragonfly\nDoji\nBottom")

//Concealing Baby Swallow
ConcealingBabySwallow=(body[3]<0 and body[2]<0 and body[1]<0 and body<0 and ratio[3]>0.8 and ratio[2]>0.8 and ratio>0.8 and open[1]<close[2] and high[1]>close[2] and shadowtop[1]>0.6*(abody[1]+shadowbottom[1]) and bodybottom<bodybottom[1] and bodytop>high[1])
plotshape(ConcealingBabySwallow, title= "Concealing Baby Swallow", location=location.belowbar, color=lime, style=shape.arrowup, text="Concealing\nBaby\nSwallow")

//Gravestone Doji Bottom
GravestoneDojiBottom=(body[1]<0 and longcandle[1] and low<low[1] and shadowtop>3*abody and shadowbottom<shadowtop/3)
plotshape(GravestoneDojiBottom, title= "Gravestone Doji Bottom", location=location.belowbar, color=lime, style=shape.arrowup, text="Gravestone\nDoji\nBottom")

//Last Engulfing Bottom
LastEngulfingBottom=(body[1]>0 and body<0 and bodybottom<bodybottom[1] and bodytop>bodytop[1] and longcandle)
plotshape(LastEngulfingBottom, title= "Last Engulfing Bottom", location=location.belowbar, color=lime, style=shape.arrowup, text="Last\nEngulfing\nBottom")

//Bullish Harami Cross
BullishHaramiCross=(body[1]<0 and longcandle[1] and bodybottom>bodybottom[1] and bodytop<bodytop[1] and ratio<0.3 and range<0.3*range[1])
plotshape(BullishHaramiCross, title= "Bullish Harami Cross", location=location.belowbar, color=lime, style=shape.arrowup, text="Bullish\nHarami\nCross")

//Three Stars in the South
ThreeStarsInTheSouth=(body[2]<0 and body[1]<0 and body<0 and shadowtop[2]<range[2]/4 and shadowbottom[2]>abody[2]/2 and low[1]>low[2] and high[1]<high[2] and abody[1]<abody[2]  and shadowtop[1]<range[1]/4 and shadowbottom[1]>abody[1]/2 and low>low[1] and high<high[1] and abody<abody[1] and shadowtop<range/4 and shadowbottom<range/4)
plotshape(ThreeStarsInTheSouth, title= "Three Stars In TheSouth", location=location.belowbar, color=lime, style=shape.arrowup, text="Three\nStars\nIn\nThe\nSouth")

//Bullish Breakaway
BullishBreakaway=(body[4]<0 and body[3]<0 and body>0 and open[3]<close[4] and close[2]<close[3] and close[1]<close[2] and longcandle and close<close[4] and close>open[3])
plotshape(BullishBreakaway, title= "Bullish Breakaway", location=location.belowbar, color=lime, style=shape.arrowup, text="Bullish\nBreakaway")

//Hammer
Hammer=(body[1]<0 and longcandle[1] and low<low[1] and shadowbottom>2*abody and shadowtop<0.3*abody)
plotshape(Hammer, title= "Hammer", location=location.belowbar, color=lime, style=shape.arrowup, text="Hammer")

//Inverted Hammer
InvertedHammer=(body[1]<0 and longcandle[1] and low<low[1] and shadowtop>2*abody and shadowbottom<0.3*abody)
plotshape(InvertedHammer, title= "Inverted Hammer", location=location.belowbar, color=lime, style=shape.arrowup, text="Inverted\nHammer")

//Rising Three Methods
RisingThreeMethods=(body[4]>0 and body[3]<0 and body[1]<0 and body>0 and longcandle[4] and longcandle and close[2]<close[3] and close[1]<close[2] and high[2]<high[3] and high[1]<high[2] and low[1]>low[4] and open>close[1] and close>high[4] and close>high[3] and close>high[2] and close>high[1])
plotshape(RisingThreeMethods, title= "Rising Three Methods", location=location.belowbar, color=lime, style=shape.arrowup, text="Rising\nThree\nMethods")

//BullishThreeLineStrike
BullishThreeLineStrike=(body[3]>0 and body[2]>0 and body[1]>0 and body<0 and longcandle[3] and longcandle[2] and longcandle[1] and close[2]>close[3] and close[1]>close[2] and open>close[1] and close<open[3])
plotshape(BullishThreeLineStrike, title= "Bullish Three Line Strike", location=location.belowbar, color=lime, style=shape.arrowup, text="Bullish\nThreeLine\nStrike")

//Bullish Mat Hold
BullishMatHold=(body[4]>0 and body[3]<0 and body[1]<0 and body>0 and longcandle[4] and close[3]>close[4] and close[2]<close[3] and close[1]<close[2] and high[2]<high[3] and high[1]<high[2] and low[1]>low[4] and open>close[1] and close>high[4] and  close>high[3] and close>high[2] and close>high[1])
plotshape(BullishMatHold, title= "Bullish Mat Hold", location=location.belowbar, color=lime, style=shape.arrowup, text="Bullish\nMat\nHold")

//Doji Star Bottom
DojiStarBottom=(body[1]<0 and longcandle[1] and low<low[1] and open<close[1] and ratio<0.3 and range<0.3*range[1])
plotshape(DojiStarBottom, title= "Doji Star Bottom", location=location.belowbar, color=lime, style=shape.arrowup, text="Doji\nStar\nBottom")

//Morning Star
MorningStar=(body[2]<0 and body>0 and longcandle[2] and open[1]<close[2] and open>close[1] and ratio[1]<0.3 and abody[1]<abody[2] and abody[1]<abody and low[1]<low and low[1]<low[2] and high[1]<open[2] and high[1]<close)
plotshape(MorningStar,  title= "Morning Star", location=location.belowbar, color=lime, style=shape.arrowup, text="Morning\nStar")

//Abandoned Baby Bottom
AbandonedBabyBottom=(body[2]<0 and body>0 and longcandle[2] and ratio[1]<0.3 and high[1]<low[2] and high[1]<low)
plotshape(AbandonedBabyBottom,  title= "Abandoned Baby Bottom", location=location.belowbar, color=lime, style=shape.arrowup, text="Abandoned\nBaby\nBottom")

//Bullish Harami
BullishHarami=(body[1]<0 and body>0 and longcandle[1] and bodybottom>bodybottom[1] and bodytop<bodytop[1])
plotshape(BullishHarami,  title= "Bullish Harami", location=location.belowbar, color=lime, style=shape.arrowup, text="Bullish\nHarami")

//Three Inside Up
ThreeInsideUp=(body[2]<0 and body[1]>0 and body>0 and BullishHarami[1] and close>close[1])
plotshape(ThreeInsideUp,  title= "Three Inside Up", location=location.belowbar, color=lime, style=shape.arrowup, text="Three\nInside\nUp")

//Bullish Engulfing
BullishEngulfing=(body[1]<0 and body>0 and bodybottom<bodybottom[1] and bodytop>bodytop[1] and longcandle)
plotshape(BullishEngulfing, title= "Bullish Engulfing", location=location.belowbar, color=lime, style=shape.arrowup, text="Bullish\nEngulfing")

//Piercing Line
PiercingLine=(body[1]<0 and body>0 and longcandle[1] and longcandle and open<low[1] and close>middle[1] and close<open[1])
plotshape(PiercingLine, title= "Piercing Line", location=location.belowbar, color=lime, style=shape.arrowup, text="Piercing\nLine")

//Three Outside Up
ThreeOutsideUp=(body[2]<0 and body[1]>0 and body>0 and BullishEngulfing[1] and close>close[1])
plotshape(ThreeOutsideUp, title= "Three Outside Up", location=location.belowbar, color=lime, style=shape.arrowup, text="Three\nOutside\nUp")

//Three White Soldiers
ThreeWhiteSoldiers=(body[2]>0 and body[1]>0 and body>0 and high[1]>high[2] and high>high[1] and close[1]>close[2] and close>close[1] and open[1]>open[2] and open[1]<close[2] and open>open[1] and open<close[1])
plotshape(ThreeWhiteSoldiers, title= "Three White Soldiers", location=location.belowbar, color=lime, style=shape.arrowup, text="Three\nWhite\nSoldiers")

//BEARISH SIGNALS

//Evening Star
EveningStar=(body[2]>0 and body<0 and longcandle[2] and open[1]>close[2] and open<close[1] and ratio[1]<0.3 and abody[1]<abody[2] and abody[1]<abody and high[1]>high and high[1]>high[2] and low[1]>open[2] and low[1]>close)
plotshape(EveningStar, title= "Evening Star", color=red, style=shape.arrowdown, text="Evening\nStar")

//Dark Cloud Cover
DarkCloudCover=(body[1]>0 and body<0 and longcandle[1] and longcandle and open>high[1] and close<middle[1] and close>open[1])
plotshape(DarkCloudCover, title= "Dark Cloud Cover", color=red, style=shape.arrowdown, text="Dark\nCloud\nCover")

//Abandoned Baby Top
AbandonedBabyTop=(body[2]>0 and body<0 and longcandle[2] and ratio[1]<0.3 and low[1]>high[2] and low[1]>high)
plotshape(AbandonedBabyTop, title= "Abandoned Baby Top", color=red, style=shape.arrowdown, text="Abandoned\nBaby\nTop")

//Bearish Harami
BearishHarami=(body[1]>0 and body<0 and longcandle[1] and bodybottom>bodybottom[1] and bodytop<bodytop[1])
plotshape(BearishHarami, title= "Bearish Harami", color=red, style=shape.arrowdown, text="Bearish\nHarami")

//Descending Hawk
DescendingHawk=(body[1]>0 and body>0 and longcandle[1] and bodybottom>bodybottom[1] and bodytop<bodytop[1])
plotshape(DescendingHawk, title= "Descending Hawk", color=red, style=shape.arrowdown, text="Descending\nHawk")

//Bearish Engulfing
BearishEngulfing=(body[1]>0 and body<0 and bodybottom<bodybottom[1] and bodytop>bodytop[1] and longcandle)
plotshape(BearishEngulfing, title= "Bearish Engulfing", color=red, style=shape.arrowdown, text="Bearish\nEngulfing")

//Gravestone Doji Top
GravestoneDojiTop=(body[1]>0 and longcandle[1] and high>high[1] and shadowtop>3*abody and shadowbottom<shadowtop/3)
plotshape(GravestoneDojiTop, title= "Gravestone Doji Top", color=red, style=shape.arrowdown, text="Gravestone\nDoji\nTop")

//Shooting Star
ShootingStar=(body[1]>0 and longcandle[1] and high>high[1] and shadowtop>2*abody and shadowbottom<0.3*abody)
plotshape(ShootingStar, title= "Shooting Star", color=red, style=shape.arrowdown, text="Shooting\nStar")

//Hanging Man
HangingMan=(body[1]>0 and longcandle[1] and high>high[1] and shadowbottom>2*abody and shadowtop<0.3*abody)
plotshape(HangingMan, title= "Hanging Man", color=red, style=shape.arrowdown, text="Hanging\nMan")

//Bearish Three Line Strike
BearishThreeLineStrike=(body[3]<0 and body[2]<0 and body[1]<0 and body>0 and longcandle[3] and longcandle[2] and longcandle[1] and close[2]<close[3] and close[1]<close[2] and open<close[1] and close>open[3])
plotshape(BearishThreeLineStrike, title= "Bearish Three Line Strike", color=red, style=shape.arrowdown, text="Bearish\nThree\nLine\nStrike")

//Falling Three Methods
FallingThreeMethods=(body[4]<0 and body[3]>0 and body[1]>0 and body<0 and longcandle[4] and longcandle and close[2]>close[3] and close[1]>close[2] and low[2]>low[3] and low[1]>low[2] and high[1]<high[4] and open<close[1] and close<low[4] and close<low[3] and close<low[2] and close<low[1])
plotshape(FallingThreeMethods, title= "Falling Three Methods", color=red, style=shape.arrowdown, text="Falling\n\nThreeMethods")

//Three Inside Down
ThreeInsideDown=(body[2]>0 and body[1]<0 and body<0 and BearishHarami[1] and close<close[1])
plotshape(ThreeInsideDown, title= "Three Inside Down", color=red, style=shape.arrowdown, text="Three\nInside\nDown")

//Three Outside Down
ThreeOutsideDown=(body[2]>0 and body[1]<0 and body<0 and BearishEngulfing[1] and close<close[1])
plotshape(ThreeOutsideDown, title= "Three Outside Down", color=red, style=shape.arrowdown, text="Three\nOutside\nDown")

//Three Black Crows
ThreeBlackCrows=(body[2]<0 and body[1]<0 and body<0 and longcandle[2] and longcandle[1] and longcandle and low[1]<low[2] and low<low[1] and close[1]<close[2] and close<close[1] and open[1]<open[2] and open[1]>close[2] and open<open[1] and open>close[1])
plotshape(ThreeBlackCrows, title= "Three Black Crows", color=red, style=shape.arrowdown, text="Three\nBlack\nCrows")

//Upside Gap Two Crows
UpsideGapTwoCrows=(body[2]>0 and body[1]<0 and body<0 and longcandle[2] and open[1]>close[2] and bodytop>bodytop[1] and bodybottom<bodybottom[1] and close>close[2])
plotshape(UpsideGapTwoCrows, title= "Upside Gap Two Crows", color=red, style=shape.arrowdown, text="Upside\nGap\nTwo\nCrows")

//Last Engulfing Top
LastEngulfingTop=(body[1]<0 and body>0 and bodybottom<bodybottom[1] and bodytop>bodytop[1] and longcandle)
plotshape(LastEngulfingTop, title= "Last Engulfing Top", color=red, style=shape.arrowdown, text="Last\nEngulfing\nTop")

//Dragonfly Doji Top
DragonflyDojiTop=(body[1]>0 and longcandle[1] and high>high[1] and shadowbottom>3*abody and shadowtop<shadowbottom/3)
plotshape(DragonflyDojiTop, title= "Dragonfly Doji Top", color=red, style=shape.arrowdown, text="Dragonfly\nDoji\nTop")

//Bearish Harami Cross
BearishHaramiCross=(body[1]>0 and longcandle[1] and bodybottom>bodybottom[1] and bodytop<bodytop[1] and ratio<0.3 and range<0.3*range[1])
plotshape(BearishHaramiCross, title= "Bearish Harami Cross", color=red, style=shape.arrowdown, text="Bearish\nHarami\nCross")

//Advance Block
AdvanceBlock=(body[2]>0 and body[1]>0 and body>0 and high[2]<high[1] and high[1]<high and open[1]>bodybottom[2] and open[1]<bodytop[2] and open>bodybottom[1] and open<bodytop[1] and abody[1]<abody[2] and abody<abody[1])
plotshape(AdvanceBlock, title= "Advance Block", color=red, style=shape.arrowdown, text="Advance\nBlock")

//Bearish Breakaway
BearishBreakaway=(body[4]>0 and body[3]>0 and body<0 and open[3]>close[4] and close[2]>close[3] and close[1]>close[2] and longcandle and close>close[4] and close<open[3])
plotshape(BearishBreakaway, title= "Bearish Breakaway", color=red, style=shape.arrowdown, text="Bearish\nBreakaway")

//Two Crows

TwoCrows=(body[2]>0 and body[1]<0 and body<0 and longcandle[2] and open[1]>close[2] and close[1]>close[2] and open<bodytop[1] and open>bodybottom[1] and close<bodytop[2] and close>bodybottom[2])
plotshape(TwoCrows, title= "Two Crows", color=red, style=shape.arrowdown, text="Two\nCrows")






// === BACKTEST RANGE ===
FromMonth = input(defval = 1, title = "From Month", minval = 1)
FromDay   = input(defval = 1, title = "From Day", minval = 1)
FromYear  = input(defval = 2016, title = "From Year", minval = 2016)
ToMonth   = input(defval = 1, title = "To Month", minval = 1)
ToDay     = input(defval = 1, title = "To Day", minval = 1)
ToYear    = input(defval = 9999, title = "To Year", minval = 9999)

enter_fast = input(20, minval=1)
exit_fast = input(10, minval=1)
exit_fast_short=input(10,minval=1)


fastL = highest(close, enter_fast)
fastS = highest(close ,exit_fast_short)
fastLC = lowest(close, exit_fast)


//entrées et sorties pour long et short, le short utilise la sortie du long comme entrée
enterL1 = close > fastL[1]
exitL1 = close <= fastLC[1]
exitS=close>fastS[1]



strategy.entry("Long", strategy.long, when = enterL1 )
strategy.close("Long", when = exitL1)

strategy.entry("Short", strategy.short, when = exitL1)
strategy.close("Short", when = exitS)







더 많은