양적 전략: MA 강점 및 약점 추세 추적


생성 날짜: 2024-01-19 16:50:13 마지막으로 수정됨: 2024-01-19 16:50:13
복사: 3 클릭수: 609
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

양적 전략: MA 강점 및 약점 추세 추적

개요

이 전략은 여러 기간의 이동 평균 ((MA) 강약 상황을 계산하여 시장 추세 강약점을 평가하여 추세를 판단하고 추적할 수 있다. 短期MA 지표가 연속적으로 상승하여 높은 점수를 기록하면 MA 강도 지표가 형성된다. 이 지표가 자체의 장기MA를 초과할 때 구매 신호를 생성한다. 전략은 긴 단기MA 포트폴리오를 구성하여 다른 주기적 추세를 추적할 수 있다.

전략 원칙

  1. 5일, 10일, 20일 등 여러 MA를 계산하여 가격이 각 MA를 상향으로 돌파하는지 판단하고, 브레이크 마크를 돌파하고, MA 강도 을 형성하는 점수를 계산한다.
  2. MA 강도에 이동 평균을 적용하여 평균선 지표를 형성하고, 평균선이 빈 상태임을 판단하여 거래 신호를 생성한다.
  3. 추적 주기 파라미터를 구성할 수 있다: 단기 MA 그룹 수, 장기 평균선 주기, 포지션 개설 조건 등.

이 전략은 주로 평균선 지표의 빈도를 판단하고, 평균선 지표 반응 MA 선의 평균 강도를 통해. MA 선은 집중적으로 트렌드 방향과 강도를 판단하고, 평균선 지표는 지속성을 판단한다.

우위 분석

  1. 트렌드 강도를 평가하는 다차원 모델. 단일 MA 라인이 충분히 강도를 결정할 수 없습니다. 이 전략은 다중 MA 돌파구를 측정하여 충분히 강도가있는 후 신호를 발산합니다.
  2. 설정 가능한 추적 주기。 단기MA 파라미터를 조정하면 다양한 수준의 트렌드를 포착할 수 있고, 장기MA 파라미터를 조정하면 출전 속도를 제어할 수。 사용자는 시장에 따라 주기 조정할 수。
  3. 단지 더 많은 것을 하면 실수하는 것을 피할 수 있고, 장기적인 상승 추세를 추적할 수 있다. 전략은 단지 더 많은 것을 하고, 단지 추종을 하지 않고 추락을 하지 않고, 역전 손실을 줄일 수 있다.

위험 분석

  1. 회수 위험 Short line average line below the long line average line. 짧은 선이 긴 선의 평균선 아래로 지나갈 때, 큰 회수 위험 Single losses can be reduced by a stop loss method. 단편 손실을 줄일 수 있다.
  2. 반전 위험이 있다. 시장의 장기적인 운영은 반드시 조정이 있다. 전략은 Exiting를 적시에 막아야 한다. 대주기 끝에 파장, 채널 등의 기술을 결합하여 반전 위험을 제어하는 것이 권장된다.
  3. 매개 변수 위험。 부적절한 매개 변수 구성으로 잘못된 신호가 나올 수 있다。 매개 변수를 다른 품종에 맞게 조정하여 매개 변수가 안정되도록 해야 한다。

최적화 방향

  1. 더 많은 지표 필터링과 결합하여 진입할 수 있다. 합성 트래픽을 고려할 수 있으며, 양적으로 검증할 수 있는 상태에서 신호를 발신하여 가짜 돌파를 방지한다.
  2. 손실을 증가시키는 방법. 이동 중지, 곡선 중단은 회귀에서 손실을 줄일 수 있습니다. 중지 방식도 고려할 수 있으며, 수익을 잠금하여 반전을 방지합니다.
  3. 선물, 외환 품종을 고려한다. MA 라인 브레이크는 유행 품종에 더 적합하다. 다양한 선물 품종의 파라미터 안정성을 평가하고 최적의 품종을 선택할 수 있다.

요약하다

이 전략은 MA 강도 지표를 계산하여 가격 추세를 판단하고, 평행선 교차를 신호 소스로 트렌드 추적을 한다. 전략의 장점은 트렌드 강도를 정확하게 판단하고, 신뢰도가 높다. 주요 위험은 트렌드 반전과 파라미터를 조정하는 것이다. 입장 신호의 정확성을 최적화하고, 스톱로스를 증가시키고, 적절한 품종을 선택함으로써 더 나은 수익을 얻을 수 있다.

전략 소스 코드
/*backtest
start: 2023-12-19 00:00:00
end: 2024-01-18 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("MA Strength Strategy", overlay=false, initial_capital = 20000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type = strategy.commission.percent, pyramiding = 1, commission_value = 0.01)
MAType = input(title="Moving Average Type", defval="ema", options=["ema", "sma", "hma", "rma", "vwma", "wma"])
LookbackPeriod = input(10, step=10)

IndexMAType = input(title="Moving Average Type", defval="hma", options=["ema", "sma", "hma", "rma", "vwma", "wma"])
IndexMAPeriod = input(200, step=10)

considerTrendDirection = input(true)
considerTrendDirectionForExit = input(true)
offset = input(1, step=1)
tradeDirection = input(title="Trade Direction", defval=strategy.direction.long, options=[strategy.direction.all, strategy.direction.long, strategy.direction.short])
i_startTime = input(defval = timestamp("01 Jan 2010 00:00 +0000"), title = "Start Time", type = input.time)
i_endTime = input(defval = timestamp("01 Jan 2099 00:00 +0000"), title = "End Time", type = input.time)
inDateRange = true

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.0
    upwardScore := close > ma5? upwardScore+1.10:upwardScore
    upwardScore := ma5 > ma10? upwardScore+1.10:upwardScore
    upwardScore := ma10 > ma20? upwardScore+1.10:upwardScore
    upwardScore := ma20 > ma30? upwardScore+1.10:upwardScore
    upwardScore := ma30 > ma50? upwardScore+1.15:upwardScore
    upwardScore := ma50 > ma100? upwardScore+1.20:upwardScore
    upwardScore := ma100 > ma200? upwardScore+1.25: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
    trendStrength = upwards?1:downwards?-1:includePartiallyAligned ? (upwardScore > 6? 0.5: upwardScore < 2?-0.5:upwardScore>4?0.25:-0.25) : 0
    [trendStrength, upwardScore]
    
includePartiallyAligned = true
[trendStrength, upwardScore] = f_getMaAlignment(MAType, includePartiallyAligned)

upwardSum = sum(upwardScore, LookbackPeriod)

indexSma = f_getMovingAverage(upwardSum,IndexMAType,IndexMAPeriod)

plot(upwardSum, title="Moving Average Strength", color=color.green, linewidth=2, style=plot.style_linebr)
plot(indexSma, title="Strength MA", color=color.red, linewidth=1, style=plot.style_linebr)
buyCondition = crossover(upwardSum,indexSma) and (upwardSum > upwardSum[offset] or not considerTrendDirection) 
sellCondition = crossunder(upwardSum,indexSma) and (upwardSum < upwardSum[offset]  or not considerTrendDirection)

exitBuyCondition = crossunder(upwardSum,indexSma)
exitSellCondition = crossover(upwardSum,indexSma) 
strategy.risk.allow_entry_in(tradeDirection)
strategy.entry("Buy", strategy.long, when= inDateRange and buyCondition, oca_name="oca_buy")
strategy.close("Buy", when = considerTrendDirectionForExit? sellCondition : exitBuyCondition)
strategy.entry("Sell", strategy.short, when= inDateRange and sellCondition, oca_name="oca_sell")
strategy.close( "Sell", when = considerTrendDirectionForExit? buyCondition : exitSellCondition)