가우스 이동 평균 거래 전략

저자:차오장, 날짜: 2024-01-03 16:06:45
태그:

img

전반적인 설명

이 전략은 가우스 분포의 아이디어를 적용하고 하이킨-아시 촛불 폐쇄 가격의 10 기간 지수 이동 평균에 기초하여 Z 점수를 계산합니다. 그 다음 경로가 그들을 넘을 때 입문 및 출구 신호의 20 기간 지수 이동 평균에 기초하여 임계값이 설정됩니다.

전략 논리

  1. 하이킨-아시 촛불 닫기 가격의 10기 지수 이동 평균을 계산합니다.

  2. 위의 이동평균 데이터를 기반으로, 25주기 룩백 윈도우에서 Z 점수를 계산한다. Z 점수는 데이터 포인트가 평균에서 몇 개의 표준편차를 반영하여 데이터가 정상인지 비정상인지 판단할 수 있다.

  3. Z 점수의 20개 기간 기하급수적인 이동 평균을 취해서 emaScore라는 곡선을 얻습니다. 이 곡선은 Z 점수의 장기 트렌드를 반영합니다.

  4. emaScore 데이터의 분포를 기반으로 상부 및 하부 임계치를 설정합니다. 곡선의 일부 변동을 고려하여 90% 및 10% 수준이 임계값으로 선택됩니다.

  5. emaScore가 중간선 또는 아래쪽 문턱을 넘어서면 길다. emaScore가 상위 문턱, 아래쪽 문턱 또는 100주기 최고점을 넘어서면 짧다.

이점 분석

  1. Z 점수를 통해 가우스 분포 아이디어를 적용하여 정상성을 판단하고 잘못된 파장을 필터합니다.

  2. 이중 지수 이동 평균은 장기 트렌드를 결정하는 필터링 효과를 가지고 있습니다.

  3. 합리적인 기준을 설정하면 잘못된 거래 확률이 낮아집니다.

  4. 100개 기간의 최고/최저점을 포함하면 역전 기회를 잡는 데 도움이 됩니다.

위험 분석

  1. Z 점수와 MAs의 조합은 매개 변수 조정에 민감합니다. 최적화가 필요합니다.

  2. 적절한 임계 수준은 전략의 타당성과 직접 관련이 있습니다. 너무 넓거나 좁으면 실패합니다.

  3. 100주기 최고/최하점은 쉽게 잘못된 신호를 생성할 수 있습니다. 적절하게 조건을 느슨하게하십시오.

  4. 하이킨 아시도 조금 뒤떨어져 있습니다.

최적화 방향

  1. 서로 다른 이동평균 기간을 테스트하고, Z 점수 뷰백 창을 테스트합니다.

  2. 자동 최적화 파라미터를 위한 발걸음 전진 분석을 활용합니다.

  3. 다른 임계 설정 방법을 시도하십시오. 예를 들어 성병 배수.

  4. 잘못된 신호를 방지하기 위해 최고/최하점 논리를 개선합니다.

  5. 다른 촛불 종류나 전형적인 가격을 테스트해서 헤이킨-아시를 대체할 수 있습니다.

요약

이 전략은 가격 비정상성을 판단하고 가우스 분포, 이중 기하급수적 이동 평균 및 동적 임계 설정의 아이디어를 기반으로 거래 신호를 생성합니다. 주요 장점은 잘못된 브레이크오웃을 필터링하고 반전을 잡는 것입니다. 그러나 매개 변수 선택과 조합에 대한 큰 영향이 있습니다. 최상의 매개 변수와 조합을 찾기 위해 추가 테스트와 최적화가 필요합니다.


/*backtest
start: 2023-12-26 00:00:00
end: 2024-01-02 00:00:00
period: 5m
basePeriod: 1m
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/
// © jensenvilhelm

// Here is an attempt to create a robust strategy for BTCUSD on a 5 minute chart
// I can't seem to get this code to work the way i want.... if you want to give it a try, please let me know -
// how it goes in comment section. 

//@version=5
// Define the strategy settings
strategy("The Z-score", shorttitle="TZS", overlay=true)

// User can set the start date for the strategy
startDate = timestamp("2023 06 01")

// Heikin-Ashi Open, Close, High and Low calculation
haClose = ohlc4
var float haOpen = na
haOpen := na(haOpen[1]) ? (open + close) / 2 : (haOpen[1] + haClose[1]) / 2
haHigh = math.max(nz(haOpen, high), nz(haClose, high), high)
haLow = math.min(nz(haOpen, low), nz(haClose, low), low)

// Function to calculate the Z-Score
z_score(_series, _length) =>
    _mean = ta.sma(_series, _length)
    _stddev = ta.stdev(_series, _length)
    (_series - _mean) / _stddev

// Compute the score and its EMA
score = z_score(ta.ema(haClose, 10), 25)
emaScore = ta.ema(score, 20)

// Calculate lower and upper thresholds using percentiles of EMA
lowerBlue = ta.percentile_linear_interpolation(emaScore, 50, 10)
upperBlue = ta.percentile_linear_interpolation(emaScore, 50, 90)

// Calculate the middle line as 50th percentile
middleLine = ta.percentile_linear_interpolation(emaScore, 50, 50) 

// Plot the EMA of the score and the thresholds
plot(emaScore,"The White Line", color=color.white, linewidth=2)
plot(lowerBlue,"Lower Blue Line", linewidth=2)
plot(upperBlue, "Upper Blue Line", linewidth=2)
plot(middleLine, "Middle Yellow Line", linewidth=2, color=color.yellow)
plot(score,"The Z-Score Mixed With EMA 10", color=color.green)

// Calculate highest and lowest EMA score over 100 bars period
highest = ta.highest(emaScore, 100)
lowest = ta.lowest(emaScore, 100)

// Plot highest and lowest EMA score lines 
plot(highest, "Highest of emaScore", color=color.red, linewidth=2)
plot(lowest, "Lowest of emaScore", color=color.red, linewidth=2)

// Define entry and exit conditions for long and short positions
longCon = ta.crossover(score, lowerBlue) or ta.crossover(emaScore, middleLine)
addOn = ta.crossover(score, highest)
shortCon = ta.crossunder(emaScore, upperBlue) or ta.crossunder(emaScore, lowerBlue) or ta.crossunder(emaScore, highest)

// Execute trading logic based on conditions and after the start date
if (time >= startDate)
    if longCon
        strategy.entry("Long", strategy.long)
        if shortCon
            strategy.close("Long")
    if addOn
        strategy.entry("LongNR2", strategy.long)
        if shortCon
            strategy.close("LongNR2")
    
    if shortCon
        strategy.entry("Short", strategy.short)
        if longCon
            strategy.close("Short")


더 많은