조정된 이동평균 및 누적 높은 낮은 지수 조합 전략

저자:차오장날짜: 2023-11-21 15:19:35
태그:

img

전반적인 설명

이 전략은 주로 고저지수, 이동평균지수, 슈퍼 트렌드 지수를 결합하여 시장 추세와 오픈 포지션을 결정합니다.

전략 논리

  1. 하이 로우 인덱스는 특정 기간 동안의 최신 가격이 새로운 최고 또는 새로운 최저치를 기록했는지 여부를 판단하고 점수를 축적합니다. 점수가 상승하면 상승 세력의 강화를 나타냅니다. 점수가 떨어지면 하락 세력의 강화를 나타냅니다.

  2. 이동 평균 지수는 가격이 상승하는 계단 모양의 상승 추세인지 하락하는 계단 모양의 하락 추세인지 판단합니다. 이동 평균이 계단 모양의 상승을 나타내면 상승 세력의 강화를 나타냅니다. 계단 모양의 하락을 나타내면 하락 세력의 강화를 나타냅니다.

  3. 시장 트렌드를 결정하기 위해 하이 로브 인덱스와 이동 평균 인덱스의 판단을 결합하고 슈퍼 트렌드 인덱스의 방향과 결합한 거래 기회를 찾습니다. 구체적으로, 하이 로브 인덱스와 이동 평균 인덱스가 상승세력을 강화하고 슈퍼 트렌드 인덱스의 방향이 하향이 될 때 긴 포지션을 열십시오. 두 인덱스가 하락세력을 강화하고 슈퍼 트렌드 인덱스의 방향이 상승할 때 짧은 포지션을 열십시오.

장점

  1. 높은 낮은 지수는 가격 움직임과 추진력의 변화를 효과적으로 판단 할 수 있습니다. 이동 평균 지수는 가격 추세를 효과적으로 결정할 수 있습니다. 둘의 조합은 시장 방향을 더 정확하게 결정할 수 있습니다.

  2. 슈퍼 트렌드 인덱스와 결합한 포지션 오픈은 포지션의 조기 또는 늦은 오픈을 피할 수 있습니다. 슈퍼 트렌드 인덱스는 가격 반전 지점을 효과적으로 식별 할 수 있습니다.

  3. 여러 가지 지표가 서로 확인되고 잘못된 신호를 줄입니다.

위험성

  1. 고저지수 및 이동평균 지수에서 잘못된 신호가 손실을 초래할 수 있습니다.

  2. 불충분한 참여와 슈퍼 트렌드 인덱스의 잘못된 매개 변수 설정은 잘못된 신호를 생성할 수 있습니다.

  3. 급속한 트렌드 역전 및 잘못된 스톱 로스 설정은 큰 손실로 이어질 수 있습니다.

  4. 위험은 지표 매개 변수를 최적화하고 스톱 로스 가격 수준을 조정함으로써 감소할 수 있습니다.

최적화

  1. 매개 변수들의 최적의 조합을 찾기 위해 서로 다른 종류의 이동 평균 지표를 테스트합니다.

  2. 신호가 더 안정적이고 신뢰할 수 있도록 높은 낮은 지표와 이동 평균 지표의 매개 변수를 최적화하십시오.

  3. 거짓 신호를 줄이기 위해 MACD, KD 등과 같은 다른 확인 지표를 포함합니다.

  4. 자동으로 매개 변수와 신호 무게를 최적화하기 위해 기계 학습 알고리즘을 통합합니다.

  5. 덜 인기 있는 상품을 거래하는 것을 피하기 위해 감정 분석을 포함하십시오.

결론

이 전략은 고저지수 및 이동평균 지수를 통해 시장 추세와 동력을 결정하고, 슈퍼 트렌드 지수를 사용하여 신호를 필터링하여 상승세와 하락세 세력이 서로 대립하고 슈퍼 트렌드 지수가 역전될 때 포지션을 개척합니다. 이 전략의 장점은 여러 신호 검증과 적시에 포지션을 개척하는 데 있습니다. 이는 위험을 효과적으로 제어 할 수 있습니다. 기존 문제에는 잘못된 신호와 트렌드 판단이 있습니다. 전략이 더 견고하고 신뢰할 수 있도록 매개 변수 최적화, 중지 손실 설정, 신호 필터링 등을 통해 다양한 개선이 가능합니다.


/*backtest
start: 2023-10-21 00:00:00
end: 2023-11-20 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © HeWhoMustNotBeNamed

//@version=4
strategy("AlignedMA and Cumulative HighLow Strategy", overlay=true, initial_capital = 1000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type = strategy.commission.percent, pyramiding = 1, commission_value = 0.01, calc_on_order_fills = true)

MAType = input(title="Moving Average Type", defval="sma", options=["ema", "sma", "hma", "rma", "vwma", "wma"])
includePartiallyAligned = input(true)
HighLowPeriod = input(50, minval=1,step=1)
LookbackPeriod = input(10, minval=1,step=1)

supertrendMult = input(2, minval=1, maxval=10, step=0.5)
supertrendLength = input(10, minval=1)

tradeDirection = input(title="Trade Direction", defval=strategy.direction.long, options=[strategy.direction.all, strategy.direction.long, strategy.direction.short])
backtestYears = input(10, minval=1, step=1)

f_getMovingAverage(source, MAType, length)=>
    ma = sma(source, length)
    if(MAType == "ema")
        ma := ema(source,length)
    if(MAType == "hma")
        ma := hma(source,length)
    if(MAType == "rma")
        ma := rma(source,length)
    if(MAType == "vwma")
        ma := vwma(source,length)
    if(MAType == "wma")
        ma := wma(source,length)
    ma
    
f_getMaAlignment(MAType, includePartiallyAligned)=>
    ma5 = f_getMovingAverage(close,MAType,5)
    ma10 = f_getMovingAverage(close,MAType,10)
    ma20 = f_getMovingAverage(close,MAType,20)
    ma30 = f_getMovingAverage(close,MAType,30)
    ma50 = f_getMovingAverage(close,MAType,50)
    ma100 = f_getMovingAverage(close,MAType,100)
    ma200 = f_getMovingAverage(close,MAType,200)

    upwardScore = 0
    upwardScore := close > ma5? upwardScore+1:upwardScore
    upwardScore := ma5 > ma10? upwardScore+1:upwardScore
    upwardScore := ma10 > ma20? upwardScore+1:upwardScore
    upwardScore := ma20 > ma30? upwardScore+1:upwardScore
    upwardScore := ma30 > ma50? upwardScore+1:upwardScore
    upwardScore := ma50 > ma100? upwardScore+1:upwardScore
    upwardScore := ma100 > ma200? upwardScore+1:upwardScore
    
    upwards = close > ma5 and ma5 > ma10 and ma10 > ma20 and ma20 > ma30 and ma30 > ma50 and ma50 > ma100 and ma100 > ma200
    downwards = close < ma5 and ma5 < ma10 and ma10 < ma20 and ma20 < ma30 and ma30 < ma50 and ma50 < ma100 and ma100 < ma200
    upwards?1:downwards?-1:includePartiallyAligned ? (upwardScore > 5? 0.5: upwardScore < 2?-0.5:upwardScore>3?0.25:-0.25) : 0

f_getHighLowValue(HighLowPeriod)=>
    currentHigh = highest(high,HighLowPeriod) == high
    currentLow = lowest(low,HighLowPeriod) == low
    currentHigh?1:currentLow?-1:0

inDateRange = time >= timestamp(syminfo.timezone, year(timenow) - backtestYears, 01, 01, 0, 0)

maAlignment = f_getMaAlignment(MAType,includePartiallyAligned)
alignedMaIndex = sum(maAlignment,LookbackPeriod)

maAlignmentDirection = alignedMaIndex > alignedMaIndex[1] ? 1 : alignedMaIndex < alignedMaIndex[1] ? -1 : 0
maAlignmentDirection := maAlignmentDirection == 0? nz(maAlignmentDirection[1],0):maAlignmentDirection

highLowIndex = f_getHighLowValue(HighLowPeriod)
cumulativeHighLowIndex = sum(highLowIndex,LookbackPeriod)

hlDirection = cumulativeHighLowIndex > cumulativeHighLowIndex[1] ? 1 : cumulativeHighLowIndex < cumulativeHighLowIndex[1] ? -1 : 0
hlDirection := hlDirection == 0? nz(hlDirection[1],0):hlDirection

[superTrend, dir] = supertrend(supertrendMult, supertrendLength)

buyEntry = (dir == -1 and maAlignmentDirection == 1 and hlDirection == 1)
sellEntry = (dir == 1 and maAlignmentDirection == -1 and hlDirection == -1)

barColor = buyEntry?color.lime:sellEntry?color.orange:color.gray
barcolor(barColor)

// strategy.risk.allow_entry_in(tradeDirection)
strategy.entry("Buy", strategy.long, when=barColor == color.lime and inDateRange, oca_name="oca_buy")
strategy.close("Buy", when=dir == 1)

strategy.entry("Sell", strategy.short, when=barColor == color.orange and inDateRange, oca_name="oca_sell")
strategy.close("Sell", when=dir == -1)


더 많은