트렌드 돌파 전략


생성 날짜: 2023-09-28 15:54:32 마지막으로 수정됨: 2023-09-28 15:54:32
복사: 1 클릭수: 701
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

개요

이 전략은 암호화폐 시장의 강력한 트렌드를 포착하는 것을 목표로 하며, 트렌드 형성 신호를 식별하기 위해 다중 채널과 이동 평균을 사용하며, 가짜 브레이크를 필터링 할 수있는 양적 지표와 결합하여, 적응적 인 손실을 사용하여 수익을 고정하는 동시에, 트렌드 시장에서 수익을 얻을 수 있습니다.

전략 원칙

이 전략은 빠른 채널, 느린 채널 및 빠른 이동 평균의 3가지를 결합하여 트렌드를 식별합니다. 빠른 채널 파라미터가 더 민감하게 설정되어 단기 가격 변동을 포착합니다. 느린 채널 파라미터는 더 느리게 설정되어 큰 트렌드를 판단합니다. 빠른 이동 평균 파라미터는 둘 사이에 있으며 채널을 뚫을 때 거래 신호를 발생시킵니다.

구체적으로, 그것은 먼저 빠른 통로의 상하 궤도와 이동 평균을 계산한다. 가격이 상하 궤도를 돌파 할 때, 느린 통로의 하하 궤도 또한 이동 평균 위에 있다면, 더 많은 신호를 생성한다. 반대로, 느린 통로의 궤도가 이동 평균 아래에 있는지 판단 할 때, 빈 신호를 생성한다.

또한, K선 형태를 검출하여 가짜 브레이크를 필터링하기 위해 몇 개의 K선을 순서대로 배열하도록 요구합니다. 가격 변동률 지표를 계산하여 통로 내의 흔들림에 갇히지 않도록합니다. 거래량 지표가 추가되어 브레이크의 시간이 따라갈 수 있도록합니다.

스톱의 경우, 이 전략은 적응 스톱을 사용합니다. 최근 기간 동안의 변동성에 따라 스톱의 폭을 동적으로 조정합니다. 이것은 스톱을 보장하면서 가능한 한 많은 트렌드 상황을 추적 할 수 있습니다.

우위 분석

이 전략의 가장 큰 장점은 거래 신호를 형성하는 판단 규칙이 더 엄격하다는 점이며, 비 트렌드적 인 가짜 돌파구를 효과적으로 필터링하여 시장의 트렌드 전환점을 실제로 포착 할 수 있다는 것입니다. 구체적으로 다음과 같은 몇 가지 측면이 있습니다.

  1. 다중 채널과 이동 평균의 조합으로 판단 기준이 더 엄격하여 잘못된 판단의 가능성을 줄일 수 있다.

  2. K선을 순서대로 배열하여 점검하여, 단일 기동 K선에서 잘못된 신호를 발생시키지 않도록 한다.

  3. 가격 변동률 지표와 함께 조정에 들어가는지 판단하여 역전 기회를 놓치지 않도록 한다.

  4. 양에너지 지표 판단을 추가하면 양과 가격과 함께 나타나는 경우에만 신호가 발생하여 무효 돌파구를 방지한다.

  5. 자기 적응형 상쇄장치는 상쇄를 보장하는 조건에서 트렌드 수익을 최대화 할 수 있습니다.

따라서, 전체적으로 이 전략은 구성 최적화, 의사결정 엄격, 손해 자체 적응 등의 특징을 가지고 있으며, 트렌드 상황을 포착하는데 매우 적합하다.

위험 분석

이 전략은 가짜 침입과 가로채기 경향을 필터링하는 데 많은 개선이 이루어졌지만, 여전히 주의해야 할 몇 가지 위험이 있습니다.

  1. 매개 변수 설정은 너무 복잡하고, 다른 매개 변수 조합의 효과는 차이가 크며, 많은 테스트를 거쳐 최적 매개 변수를 찾는 것이 필요하며, 잘못 설정하면 너무 많은 오류 신호가 발생할 수 있다.

  2. 급속한 평균과 통로 간격이 지나간다는 것은 종종 포지션을 열거나 닫는 것을 유발할 수 있으며, 지속적인 추세를 추적하는 것은 좋지 않습니다.

  3. 적응형 상쇄 메커니즘의 상쇄 손실의 범위는 간단한 표준 차원에 의존하여 계산되며, 극단적 인 경우 상쇄 손실이 너무 작을 수 있습니다.

  4. 기술적인 지표에 너무 의존해서 근본적으로 급격한 변화가 생기면 대응하기 힘들다.

  5. 이 전략은 트렌드 추적 전략에 속하며, 축적된 흔들리는 시장에서 좋지 않은 성과를 거두었다.

이러한 위험들에 대해 다음과 같은 조치를 취하는 것이 좋습니다.

  1. 충분히 회수하여 최적의 파라미터 조합을 결정하고, 기계 학습과 같은 방법을 사용하여 파라미터 최적화를 고려할 수 있다.

  2. 채널 간격이 적절히 넓혀지고 이동 평균 주기가 적절히 길어지면서 불필요한 창고 빈도를 줄일 수 있다.

  3. 헤지 펀드 같은 더 고급 변동률 계산 모델을 도입하는 것을 고려할 수 있다.

  4. 기초 정보를 적시에 참고하고, 기술 지표만으로 거래하는 것을 피하십시오.

  5. 시장 상황에 대한 판단을 높이고, 불안한 시장에서 거래를 중단한다.

최적화 방향

이 전략은 다음과 같은 부분에서 더 개선될 수 있습니다.

  1. 기계 학습 알고리즘을 추가하여 매개 변수를 자동으로 최적화 할 수 있습니다. 다양한 시장 환경에서 매개 변수의 성능을 기록하고, 쿼리 테이블을 구축하여 동적 최적화를 구현 할 수 있습니다.

  2. 시장 상태에 대한 판단을 높이는 것, 예를 들어 시장이 추세인지 아니면 흔들리는지 판단하는 것을 높이는 것, 흔들리는 시장에서 거래를 중단하여 불필요한 손실을 피하는 것 등

  3. 손실을 막는 전략을 최적화하기 위해, 추적 손실, 비율 손실 및 기타 다른 손실을 막는 방법을 고려할 수 있습니다.

  4. 기본적 요소를 추가하고, 중요한 기본적 사건이 발생했을 때 경고를 발산하여 기술 지표만으로 손실을 피하십시오.

  5. 포트폴리오 최적화를 통해, 이 전략을 다른 비관계적 전략 포트폴리오와 결합하면, 위험을 더욱 확산시킬 수 있다.

  6. 양적 거래 프레임워크에 가입하여 신호를 자동으로 실행하고 엄격한 위험 관리를 구현합니다.

요약하다

요약하자면, 이 전략은 전반적으로 암호화폐 시장의 트렌드 기회를 포착하는 데 적합합니다. 그것은 다중 채널과 이동 평균을 사용하여 거래 신호를 생성하고, 가짜 돌파구의 잡음을 효과적으로 필터링하여 트렌드 수익을 성공적으로 잠금합니다. 그러나 변수 최적화, 손실 차단 방법, 시장 상태 판단 등의 문제에 주의해야합니다. 계속 개선 할 수 있다면 안정적인 투자 수익을 얻을 수 있습니다.

전략 소스 코드
/*backtest
start: 2022-09-21 00:00:00
end: 2023-09-27 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
strategy("Extremely Overfit", overlay=true, commission_type=strategy.commission.percent, commission_value=.16, default_qty_type=strategy.percent_of_equity, default_qty_value=100, pyramiding = 1)
price = close

goLong = input(title="go long?", type=input.bool, defval=true)
goShort = input(title="go short?", type=input.bool, defval=true)
//trendRestrict = input(title="basic trend restriction?", type=input.bool, defval=false)
dynamicRestrict = true //input(title="dynamic trend restriction?", type=input.bool, defval=true)
longtrendimpt = true //input(title="additional weight on long-term trends?", type=input.bool, defval=true)
volRestrict = true //input(title="volume restriction?", type=input.bool, defval=true)
conservativeClose = false //input(title="conservative order closing?", type=input.bool, defval=false)

Restrictiveness = input ( -40,step=10,title ="Restrictiveness (higher = make fewer trades)")
volatilityImportance = 3.2 //input( 3.2, step = 0.1, minval = 0)
fastChannelLength = input( 6 )
fastChannelMargin = input ( 3.2, step = 0.1, minval = 0)
slowChannelLength = input ( 6, step = 1, minval = 0)
slowChannelMargin = input ( 1.5, step = 0.1, minval = 0)
fastHMAlength = input (4, step = 1, minval = 0)
stopLoss = input( 3, step = 0.1, minval = 0)
//altClosePeriod = input( 27, step = 1, minval = 1)
//altCloseFactor = input( 4.9, step = 0.1)
stopLossFlexibility = 50 //input(50, step=10, title="effect of volatility on SL?")
volumeMAlength = 14 //input ( 14, step = 1, minval = 1)
volumeVolatilityCutoff = 3.8 // ( 3.8, step = 1, minval = 0)
trendSensitivity = 3.8 //input ( 3.8, step = 0.1)
obvLookback = 10 //input(10, step = 10, minval = 10)
obvCorrThreshold = 0.89 //input(0.89, step = 0.01)
ROClength = 80 //input( 80, step = 10)
ROCcutoff = 5.6 //input( 5.6, step=0.1)

trendRestrict = false
//trendLookback = input ( 360, step = 10, minval = 10)
//longTrendLookback = input(720, step = 10, minval = 10)
//longTrendImportance = input(1.5, step = 0.05)
trendLookback = 360
longTrendLookback = 720
longTrendImportance = 1.5

//conservativeness = input( 2.4, step = 0.1)
conservativeness = 0
//trendPower = input( 0, step=1)
trendPower = 0
//conservativenessLookback = input( 650, step = 10, minval = 0)
conservativenessLookback = 10
//consAffectFactor = input( 0.85,step=0.01)
consAffectFactor = 0.85
//volatilityLookback = input(50, step=1, minval=2)
volatilityLookback = int(50)
recentVol = stdev(price,volatilityLookback)/sqrt(volatilityLookback)

//price channel

fastChannel = ema(price, fastChannelLength)
fastChannelUB = fastChannel * (1 + (float(fastChannelMargin) / 1000)) + (recentVol * (float(volatilityImportance) * (1 + (Restrictiveness/100))))
fastChannelLB = fastChannel * (1 - (float(fastChannelMargin) / 1000)) - (recentVol * (float(volatilityImportance) * (1 + (Restrictiveness/100))))
fchU = ((fastChannelUB < open) and (fastChannelUB < close))
fchL = ((fastChannelLB > open) and (fastChannelLB > close))
//plot(fastChannelUB)
//plot(fastChannelLB)

//slow channel
//slowChannelLBmargin = input ( 2, step = 0.1, minval = 0 )
slowChannel = ema(ema(price,slowChannelLength),slowChannelLength)
slowChannelUB = slowChannel * (1 + (float(slowChannelMargin) / 2000)) + (recentVol * (float(volatilityImportance) * (1 + (Restrictiveness/100))))
slowChannelLB = slowChannel * (1 - (float(slowChannelMargin) / 2000)) - (recentVol * (float(volatilityImportance) * (1 + (Restrictiveness/100))))
schU = ((slowChannelUB < close))
schL = ((slowChannelLB > close))
cschU = (((slowChannelUB * (1 + conservativeness)) < close))
cschL = (((slowChannelUB * (1 - conservativeness)) > close))
//plot(slowChannel,color = #00FF00)
//plot(slowChannelUB,color = #00FF00)
//plot(slowChannelLB,color = #00FF00)


fastHMA = hma(price,fastHMAlength)
fastAboveUB = (fastHMA > slowChannelUB)
fastBelowLB = (fastHMA < slowChannelLB)
//plot(fastHMA, color = 	#FF0000, linewidth = 2)

//consecutive candles
//consecutiveCandlesReq = input(1, step = 1, minval = 1, maxval = 4)
consecutiveCandlesReq = 1
consecutiveBullReq = float(consecutiveCandlesReq)
consecutiveBearReq = float(consecutiveCandlesReq)
cbull = ((close[0] > close[1]) and (consecutiveBullReq == 1)) or (((close[0] > close[1]) and (close[1] > close[2])) and consecutiveBullReq == 2) or (((close[0] > close[1]) and (close[1] > close[2]) and (close[2] > close[3])) and consecutiveBullReq == 3) or (((close[0] > close[1]) and (close[1] > close[2]) and (close[2] > close[3]) and (close[3] > close[4])) and consecutiveBullReq == 4)
cbear = ((close[0] < close[1]) and (consecutiveBearReq == 1)) or (((close[0] < close[1]) and (close[1] < close[2])) and consecutiveBearReq == 2) or (((close[0] < close[1]) and (close[1] < close[2]) and (close[2] < close[3])) and consecutiveBearReq == 3) or (((close[0] < close[1]) and (close[1] < close[2]) and (close[2] < close[3]) and (close[3] < close[4])) and consecutiveBearReq == 4)

//trend detection
//trendCutoff = input(0, step = 0.1)
trendCutoff = 0
trendDetectionPct = float(trendCutoff/100)
trendVal = float((close[0] - close[trendLookback])/close[0])
trendUp = (trendVal > (0 + trendDetectionPct))
trendDown = (trendVal < (0 - trendDetectionPct))
//plot(trendVal+36.5,linewidth=2)

// peak indicators
peakHigh = ((fastHMA > fastChannelUB) and (fastChannelLB > slowChannelUB))
peakLow = ((fastHMA < fastChannelLB) and (fastChannelUB < slowChannelLB))
TpeakHigh = (fastHMA > fastChannelUB) and (fastChannelUB > slowChannelUB)
TpeakLow = (fastHMA < fastChannelUB) and (fastChannelLB < slowChannelLB)
//TpeakHigh = (fastHMA > fastChannelUB) and (fastChannelLB > avg(slowChannelUB,slowChannelLB))
//TpeakLow = (fastHMA < fastChannelUB) and (fastChannelUB < avg(slowChannelLB,slowChannelUB))
//TpeakHigh = ((crossover(fastHMA,fastChannelUB)) and (fastChannelLB > slowChannelUB))
//TpeakLow = ((crossover(fastChannelLB,fastHMA)) and (fastChannelUB < slowChannelLB))
//TpeakHigh = (fastHMA > (fastChannelUB * (1 + (trendPower/800)))) and (fastChannelUB > (slowChannelUB * (1 + (trendPower/800))))
//TpeakLow = (fastHMA < (fastChannelUB * (1 - (trendPower/800)))) and (fastChannelLB < (slowChannelLB * (1 - (trendPower/800))))
//TpeakHigh = (fastHMA > (fastChannelUB * (1 + (trendPower/800)))) and (avg(fastChannelUB,fastChannelLB) > (slowChannelUB * (1 + (trendPower/800))))
//TpeakLow = (fastHMA < (fastChannelUB * (1 - (trendPower/800)))) and (avg(fastChannelLB,fastChannelUB) < (slowChannelLB * (1 - (trendPower/800))))
//plot(fastChannelUB * (1 + (trendPower/700)), color=#FF69B4)

// and for closing...
closeLong = (crossover(fastHMA,fastChannelUB) and (fastChannelLB > slowChannelUB))
closeShort = (crossover(fastChannelLB,fastHMA) and (fastChannelUB < slowChannelLB))
//closeLong = (crossover(fastHMA,fastChannelUB) and (fastChannelLB > slowChannelUB)) or (roc(price,altClosePeriod) > altCloseFactor)
//closeShort = (crossover(fastChannelLB,fastHMA) and (fastChannelUB < slowChannelLB))  or (roc(price,altClosePeriod) < (altCloseFactor) * -1)
//closeLong = (crossover(fastHMA,fastChannelUB) and (fastChannelLB > slowChannelUB)) or (((price - fastChannelUB) > (altCloseFactor * abs(((fastChannelUB - fastChannelLB)/2) - ((slowChannelUB - slowChannelLB)/2)))) and (fastChannelLB > slowChannelUB))
//closeShort = (crossover(fastChannelLB,fastHMA) and (fastChannelUB < slowChannelLB)) or (((fastChannelLB - price) > (altCloseFactor * abs(((fastChannelUB - fastChannelLB)/2) - ((slowChannelUB - slowChannelLB)/2)))) and (fastChannelUB < slowChannelLB))
//closeLong = crossover(fastHMA,fastChannelUB) and ((fastChannelLB[0] - fastChannelLB[1]) < (slowChannelUB[0] - slowChannelUB[1]))
//closeShort = crossover(fastChannelLB,fastHMA) and ((fastChannelUB[0] - fastChannelUB[1]) > (slowChannelLB[0] - slowChannelLB[1]))


//stop-loss
priceDev = stdev(price,trendLookback) * (1 + stopLossFlexibility/5)
stopLossMod = stopLoss * (1 + (priceDev/price))
//longStopPrice  = strategy.position_avg_price * (1 - (stopLoss/100))
//shortStopPrice = strategy.position_avg_price * (1 + (stopLoss/100))
longStopPrice  = strategy.position_avg_price * (1 - (stopLossMod/100))
shortStopPrice = strategy.position_avg_price * (1 + (stopLossMod/100))


// volume
volumeMA = ema(volume,volumeMAlength)
volumeDecrease = ((not volRestrict ) or (volumeMA[0] < ema(volumeMA[1] * (1 - (volumeVolatilityCutoff/100)),5)))
volumeCutoff = ema(volumeMA[1] * (1 - (volumeVolatilityCutoff/100)),5)
//plot(volumeMA)
//plot(volumeCutoff)

// detect volatility
//trendinessLookback = input ( 600, step = 10, minval = 0)
trendinessLookback = trendLookback
trendiness = (stdev(price,trendinessLookback)/price) * (1 - (Restrictiveness/100))
longtermTrend = ((price - price[longTrendLookback])/price)
//dynamicTrendDetected = (dynamicRestrict and (abs(trendiness * 100) < trendSensitivity))
dynamicTrendDetected = (longtrendimpt and (dynamicRestrict and (abs(trendiness * 100) < (trendSensitivity+(longtermTrend * longTrendImportance))))) or (not longtrendimpt and ((dynamicRestrict and (abs(trendiness * 100) < trendSensitivity))))

// adapt conservativeness to volatility

//consVal = sma(((stdev(price,conservativenessLookback))/price)*100,25)
consVal = sma(((stdev(price,conservativenessLookback))/price)*100,25)
cVnorm = sma(avg(consVal,3),60)
cVal = consVal - cVnorm

//conservativenessMod = conservativeness * (cVal * consAffectFactor)
conservativenessMod = conservativeness * (consVal * consAffectFactor)
//plot(consVal,linewidth=4)
//plot(cVnorm,color = #00FF00)
//plot(cVal,linewidth=2)

// ROC cutoff (for CLOSING)
//rocCloseLong = (ema(roc(price,ROClength),10) > ROCcutoff)
//rocCloseShort = (ema(roc(price,ROClength),10) < (ROCcutoff * -1))
ROCval = roc(price,ROClength)
ROCema = ema(ROCval,30)
ROCabs = abs(ROCema)
ROCallow = ROCabs < ROCcutoff
ROCallowLong = (ROCabs < ROCcutoff)  or ((ROCabs >= ROCcutoff) and ((fastChannelLB < slowChannelLB) and (fastHMA < fastChannelLB)))
ROCallowShort = (ROCabs < ROCcutoff) or ((ROCabs >= ROCcutoff) and ((fastChannelUB > slowChannelUB) and (fastHMA > fastChannelUB)))
//plot(ROCallow)

// obv
evidence_obv = (correlation(price,obv[0],obvLookback))
obvAllow = evidence_obv > obvCorrThreshold


//if (not na(vrsi))
if trendRestrict or dynamicTrendDetected
    //if (strategy.position_size == 0)
    if not (strategy.position_size < 0)
        if trendUp
        	//if cbear and schL and fchL and trendUp and goLong
        	if cbear and TpeakLow and volumeDecrease and ROCallow and goLong and obvAllow
        	//if cbear and peakLow and rocHigh and volumeDecrease and goLong
        		strategy.entry("Long", strategy.long, comment="Long")
    if not (strategy.position_size > 0)
        if trendDown
        	//if cbull and schU and fchU and trendDown and goShort
        	if cbull and TpeakHigh and volumeDecrease and ROCallow and goShort and obvAllow
        	//if cbull and peakHigh and rocLow and volumeDecrease and goShort
        		strategy.entry("Short", strategy.short, comment="Short")
else
    //if (strategy.position_size == 0)
    if not (strategy.position_size < 0)
        //if cbear and peakLow and goLong
    	//if cbear and peakLow and volumeDecrease and ROCallow and goLong
    	if TpeakLow and goLong and obvAllow
    		strategy.entry("Long", strategy.long, comment="Long")
    if not (strategy.position_size > 0)
        //if cbull and peakHigh and goShort
    	//if cbull and peakHigh and volumeDecrease and ROCallow and goShort
    	if TpeakHigh and goShort and obvAllow
    		strategy.entry("Short", strategy.short, comment="Short")

if conservativeClose
    //pkHigh = ((fastHMA > fastChannelUB) and (fastChannelUB > (slowChannelUB * (1 + conservativeness/1000))))
    //pkLow = ((fastHMA < fastChannelLB) and (fastChannelLB < (slowChannelLB * (1 - conservativeness/1000))))
    //pkHigh = ((fastHMA > fastChannelUB) and (fastChannelUB > (slowChannelUB * (1 + conservativenessMod/1000))))
    //pkLow = ((fastHMA < fastChannelLB) and (fastChannelLB < (slowChannelLB * (1 - conservativenessMod/1000))))
    pkHigh = ((fastHMA > fastChannelUB) and (fastChannelUB > (slowChannelUB * (1 + ((conservativenessMod/1000) * (1 - Restrictiveness/100))))))
    pkLow = ((fastHMA < fastChannelLB) and (fastChannelLB < (slowChannelLB * (1 - ((conservativenessMod/1000) * (1 - Restrictiveness/100))))))
    
    if (strategy.position_size > 0)
        //if fastAboveUB
        //if pkHigh and closeLong
        if closeLong
    		strategy.close("Long", comment="closeLong")
    if (strategy.position_size < 0)
        //if fastBelowLB
        //if pkLow and closeShort
        if closeShort
    		strategy.close("Short", comment="closeShort")
else
    if (strategy.position_size > 0)
        //if fastAboveUB
        if peakHigh
    		strategy.close("Long", comment="closeLong")
    if (strategy.position_size < 0)
        //if fastBelowLB
        if peakLow
    		strategy.close("Short", comment="closeShort")

if (strategy.position_size > 0)
    strategy.exit(id="Long", stop=longStopPrice, comment="stopLong")

if (strategy.position_size < 0)
    strategy.exit(id="Short", stop=shortStopPrice, comment="stopShort")
//plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr)