MacD 미래 경로 예측 전략

저자:차오장, 날짜: 2023-12-13 17:21:44
태그:

img

전반적인 설명

이 전략의 핵심 아이디어는 MacD 지표의 미래 트렌드를 분석하여 가격 추세를 예측하는 것입니다. 이 전략은 MacD 지표를 구성하는 빠르고 느린 이동 평균의 크로스오버에 의해 생성되는 거래 신호를 최대한 활용합니다.

전략 원칙

  1. MacD 라인과 신호 라인의 상승과 하락을 결정하기 위해 MacD 표시기의 차이 (역사적 값) 를 계산합니다.
  2. MacD 지표의 미래 값을 4시간 시간 내에 사용하여, 콜 옵션을 설정하여 MacD 지표의 미래 트렌드를 판단하고 가격 동향을 예측합니다.
  3. MacD 지표 차이는 0보다 크면 (부산 시장을 나타냅니다) 그리고 계속 상승할 것으로 예상되는 경우 장거리; MacD 지표 차이는 0보다 작고 (부산 시장을 나타냅니다) 계속 감소할 것으로 예상되는 경우 단축합니다.
  4. 이 전략은 트렌드를 따르는 것과 트렌드 역전 트레이딩 스타일을 결합하여 트렌드를 포착하고 동시에 트렌드 역전 포인트를 포착합니다.

이점 분석

  1. 시장 동향을 판단하기 위해 MacD 지표를 사용하는 장점은 통합을 효과적으로 필터링하고 장기 동향을 포착 할 수 있습니다.
  2. MacD 지표의 미래 동향에 대한 예측의 도움으로, 전략의 미래 지향적 능력을 향상시키기 위해 가격의 전환점을 조기에 식별 할 수 있습니다.
  3. 트렌드 추적 및 트렌드 역전 거래 스타일을 통합하면 트렌드 추적 중에 적절한 시점에 포지션 역전을 통해 더 큰 수익을 얻을 수 있습니다.
  4. 조정 가능한 전략 매개 변수는 사용자가 전략 안정성을 향상시키기 위해 다른 시간 프레임과 시장 환경에 따라 최적화 할 수 있습니다.

위험 분석

  1. MacD 지표의 미래 트렌드에 대한 예측에 의존하면 예측이 정확하지 않으면 거래 실패로 이어질 수 있습니다.
  2. 스톱 로스는 단일 손실을 제어하기 위해 사용되어야 합니다. 잘못된 스톱 로스 범위 설정 또한 전략 성능에 영향을 미칠 것입니다.
  3. MacD 지표의 지연은 빠른 가격 반전 기회를 놓칠 수 있습니다. 높은 변동성 환경에서 전략의 성과에주의가 필요합니다.
  4. 거래 비용의 영향은 모니터링이 필요합니다.

최적화 방향

  1. 예측을 위해 다른 지표를 포함하여 단일 MacD 지표에 대한 의존도를 줄이고 거래량 변화의 조사와 같은 예측 정확도를 향상시킵니다.
  2. 머신러닝 알고리즘을 추가하고, MacD 지표의 미래 트렌드를 예측하기 위해 모델을 훈련합니다.
  3. 가장 좋은 매개 변수 조합을 찾기 위해 매개 변수 설정을 최적화합니다.
  4. 서로 다른 시장 환경은 서로 다른 매개 변수 구성에 적합하며, 자동 최적화 매개 변수를 위해 적응 시스템이 추가 될 수 있습니다.

결론

이 전략은 추세를 결정하는 MacD 지표의 장점을 완전히 발휘하면서도, 이 전략은 또한 지표의 미래 추세를 예측하는 것을 포함합니다. 추세를 포착하는 것을 기반으로, 또한 중요한 전환점을 포착합니다. 단순히 추세를 쫓는 것과 비교하면, 이 전략은 더 많은 예견과 수익 잠재력을 가지고 있습니다. 물론, 추가 최적화와 개선이 필요한 특정 위험도 있습니다. 전반적으로, 전략은 깊이 있는 연구와 응용을받을 자격이 있습니다.


/*backtest
start: 2023-12-05 00:00:00
end: 2023-12-12 00:00:00
period: 5m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// @version=4
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © x11joe
strategy(title="MacD (Future Known or Unknown) Strategy", overlay=false, precision=2,commission_value=0.26, initial_capital=10000, currency=currency.USD, default_qty_type=strategy.percent_of_equity, default_qty_value=100)

//OPTIONAL:: Allow only entries in the long or short position
allowOnlyLong = input(title="Allow position ONLY in LONG",type=input.bool, defval=false)
allowOnlyShort = input(title="Allow position ONLY in SHORT",type=input.bool, defval=false)


strategy.risk.allow_entry_in(allowOnlyLong ? strategy.direction.long : allowOnlyShort ? strategy.direction.short : strategy.direction.all) // There will be no short entries, only exits from long.

// Create MacD inputs
fastLen = input(title="MacD Fast Length", type=input.integer, defval=12)
slowLen = input(title="MacD Slow Length", type=input.integer, defval=26)
sigLen  = input(title="MacD Signal Length", type=input.integer, defval=9)

// Get MACD values
[macdLine, signalLine, _] = macd(close, fastLen, slowLen, sigLen)
hist = macdLine - signalLine

useFuture = input(title="Use The Future?",type=input.bool,defval=true)

macDState(resolutionType) =>
    hist_from_resolution = security(syminfo.tickerid, resolutionType, hist,barmerge.gaps_off, barmerge.lookahead_on)
    Green_IsUp = hist_from_resolution > hist_from_resolution[1] and hist_from_resolution > 0
    Green_IsDown = hist_from_resolution < hist_from_resolution[1] and hist_from_resolution > 0
    Red_IsDown = hist_from_resolution < hist_from_resolution[1] and hist_from_resolution <= 0
    Red_IsUp = hist_from_resolution > hist_from_resolution[1] and hist_from_resolution <= 0
    result=0
    if(Green_IsUp)
        result := 1
    if(Green_IsDown)
        result := 2
    if(Red_IsDown)
        result := 3
    if(Red_IsUp)
        result := 4
    result

macDStateNonFuture(resolutionType) =>
    hist_from_resolution = security(syminfo.tickerid, resolutionType, hist,barmerge.gaps_off, barmerge.lookahead_off)
    Green_IsUp = hist_from_resolution > hist_from_resolution[1] and hist_from_resolution > 0
    Green_IsDown = hist_from_resolution < hist_from_resolution[1] and hist_from_resolution > 0
    Red_IsDown = hist_from_resolution < hist_from_resolution[1] and hist_from_resolution <= 0
    Red_IsUp = hist_from_resolution > hist_from_resolution[1] and hist_from_resolution <= 0
    result=0
    if(Green_IsUp)
        result := 1
    if(Green_IsDown)
        result := 2
    if(Red_IsDown)
        result := 3
    if(Red_IsUp)
        result := 4
    result

// === INPUT BACKTEST RANGE ===
FromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)
FromDay   = input(defval = 1, title = "From Day", minval = 1, maxval = 31)
FromYear  = input(defval = 2019, title = "From Year", minval = 2017)
ToMonth   = input(defval = 1, title = "To Month", minval = 1, maxval = 12)
ToDay     = input(defval = 1, title = "To Day", minval = 1, maxval = 31)
ToYear    = input(defval = 9999, title = "To Year", minval = 2017)

start     = timestamp(FromYear, FromMonth, FromDay, 00, 00)  // backtest start window
finish    = timestamp(ToYear, ToMonth, ToDay, 23, 59)        // backtest finish window
window()  => time >= start and time <= finish ? true : false // create function "within window of time"
// === INPUT BACKTEST RANGE END ===

//Get FUTURE or NON FUTURE data
macDState240=useFuture ? macDState("240") : macDStateNonFuture("240") //1 is green up, 2 if green down, 3 is red, 4 is red up

//Fill in the GAPS
if(macDState240==0)
    macDState240:=macDState240[1]

//Plot Positions
plot(close,color= macDState240==1 ? color.green : macDState240==2 ? color.purple : macDState240==3 ? color.red : color.yellow,linewidth=4,style=plot.style_histogram,transp=50)

if(useFuture)
    strategy.entry("buy_1",long=true,when=window() and (macDState240==4 or macDState240==1))
    strategy.close("buy_1",when=window() and macDState240==3 and macDState240[1]==4)
    strategy.entry("sell_1",long=false,when=window() and macDState240==2)
else
    strategy.entry("buy_1",long=true,when=window() and (macDState240==4 or macDState240==1))//If we are in a red macD trending downwards MacD or in a MacD getting out of Red going upward.
    strategy.close("buy_1",when=window() and macDState240==3 and macDState240[1]==4)//If the state is going upwards from red but we are predicting back to red...
    strategy.entry("sell_1",long=false,when=window() and macDState240==2)//If we are predicting the uptrend to end soon.


더 많은