현재 트렌드 트렌드 전략

저자:차오장, 날짜: 2023-09-21 15:00:08
태그:

전반적인 설명

현재 트렌드 전략은 독특한 사용자 정의 트렌드 추적 전략입니다. 이 조합은 전략이 다양한 시장 조건에 적합하도록 단기 및 장기 시장 트렌드를 모두 활용 할 수 있습니다.

어떻게 작동 합니까?

이 전략은 두 부분으로 구성됩니다.

  1. 사용자 지정 RSI 또는 MFI 지표: 이 지표는 RSI 또는 MFI를 기반으로 하는 PresentTrend 값을 계산하고, 그 크로스오버와 크로스온더를 기반으로 구매 및 판매 신호를 생성하여 잠재적 인 트렌드 반전을 나타냅니다.

  2. ATR 지표: 트렌드를 따르는 대표적인 지표로, 평균 실제 범위 (ATR) 를 사용합니다.

이 전략은 두 전략의 모든 구매 신호가 사실이고 모든 판매 신호가 사실일 때 짧은 위치에 진입합니다. 이것은 단기 및 장기 트렌드가 일치 할 때만 거래가 이루어지는 것을 보장하며 잠재적으로 전략의 신뢰성을 높일 수 있습니다.

장점

  • 다른 시장 조건에 적응 할 수있는 단기 및 장기적 경향을 결합합니다.
  • 신호 신뢰성을 높이기 위해 사용자 지정 표시기와 ATR을 사용합니다.
  • 단장, 단장 또는 쌍방향 거래 옵션은 다른 거래 스타일에 적합합니다.
  • 감수성과 안정성 균형을 위해 최적화된 기본 매개 변수
  • 매개 변수는 최적화를 위한 개인적인 선호도에 따라 조정할 수 있습니다

위험 과 해결책

  • 트렌드를 따르는 모든 전략과 마찬가지로
  • 쌍방향 거래는 거래와 수수료의 수를 증가시킬 수 있습니다.
  • 잘못된 매개 변수 조정은 과도한 잘못된 신호를 생성 할 수 있습니다.
  • 윙사 위험을 줄이기 위해 더 짧은 보유 기간을 사용할 수 있습니다.
  • 장기 또는 단기 옵션은 거래 수를 줄여줍니다.
  • 매개 변수는 실행 가능성을 보장하기 위해 철저히 테스트하고 조정해야합니다.

최적화 방향

  • 더 나은 손실 통제를 위해 손실 중지 메커니즘을 추가
  • 가짜 거래를 줄이기 위해 추가 지표로 신호를 필터링합니다.
  • 최적을 찾기 위해 다른 유지 기간 매개 변수를 테스트
  • 자동 매개 변수 최적화를 위한 기계 학습을 탐구
  • 주문 흐름 정보와 같은 더 많은 데이터 소스를 포함
  • 실행 효율성을 향상시키기 위해 전략 코드를 최적화

결론

전체적으로, 현재 트렌드 전략은 매우 효과적인 트렌드 추적 시스템이다. 단기 및 장기 트렌드 지표를 결합하여 신호 신뢰성을 향상시키는 동시에 민감합니다. 조정 가능한 방향, 매개 변수 및 추가 로직으로 전략은 다른 시장 환경과 거래자의 필요에 적응 할 수 있습니다. 본질적인 트렌드 추적 위험이 남아있는 동안, 현재 트렌드는 고려할 가치가있는 매력적인 옵션입니다.


/*backtest
start: 2023-08-21 00:00:00
end: 2023-09-20 00:00:00
period: 2h
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/
// © PresentTrading

//@version=5

// Define the strategy settings
strategy('PresentTrend - Strategy [presentTrading]' , overlay=true, precision=3, default_qty_type=strategy.cash, 
 commission_value= 0.1, commission_type=strategy.commission.percent, slippage= 1, 
  currency=currency.USD, default_qty_type = strategy.percent_of_equity, default_qty_value = 10, initial_capital= 10000)

// Define the input parameters
priceSource  = input.source(title='Source', defval=hlc3, group='PresentTrend') // The price source to use
lengthParam  = input.int(title='Length', defval=14, group='PresentTrend') // The length of the moving average
multiplier = input.float(title='Multiplier', defval=1.618, step=0.1, group='PresentTrend') // The multiplier for the ATR
indicatorChoice  = input.bool(title='Whether to use RSI or MFI', defval=false, group='PresentTrend') // Whether to use RSI or MFI

// Add a parameter for choosing Long or Short
tradeDirection = input.string(title="Trade Direction", defval="Both", options=["Long", "Short", "Both"])

// Calculate the ATR and the upT and downT values
ATR = ta.sma(ta.tr, lengthParam)
upperThreshold = low - ATR * multiplier 
lowerThreshold  = high + ATR * multiplier 

// Initialize the PresentTrend indicator
PresentTrend = 0.0

// Calculate the PresentTrend indicator
PresentTrend := (indicatorChoice ? ta.rsi(priceSource, lengthParam) >= 50 : ta.mfi(hlc3, lengthParam) >= 50) ? upperThreshold < nz(PresentTrend[1]) ? nz(PresentTrend[1]) : upperThreshold : lowerThreshold > nz(PresentTrend[1]) ? nz(PresentTrend[1]) : lowerThreshold

// Calculate the buy and sell signals
longSignal  = ta.crossover(PresentTrend, PresentTrend[2])
shortSignal  = ta.crossunder(PresentTrend, PresentTrend[2])

// Calculate the number of bars since the last buy and sell signals
barsSinceBuy = ta.barssince(longSignal)
barsSinceSell = ta.barssince(shortSignal)
previousBuy = ta.barssince(longSignal[1])
previousSell = ta.barssince(shortSignal[1])

// Initialize the direction variable
trendDirection = 0

// Calculate the direction of the trend
trendDirection := longSignal and previousBuy > barsSinceSell ? 1 : shortSignal and previousSell > barsSinceBuy ? -1 : trendDirection[1]

// Check the trade direction parameter before entering a trade
if (trendDirection == 1 and (tradeDirection == "Long" or tradeDirection == "Both"))
    strategy.entry("Buy", strategy.long) 
if (trendDirection == -1 and (tradeDirection == "Short" or tradeDirection == "Both"))
    strategy.entry("Sell", strategy.short) 

// Add a stop mechanism when the tradeDirection is one-sided
if (tradeDirection == "Long" and trendDirection == -1)
    strategy.close("Buy")
if (tradeDirection == "Short" and trendDirection == 1)
    strategy.close("Sell")

// Visualization
plot(PresentTrend, color=color.blue, title="PresentTrend")
plotshape(series=longSignal, location=location.belowbar, color=color.green, style=shape.labelup, title="Buy Signal")
plotshape(series=shortSignal, location=location.abovebar, color=color.red, style=shape.labeldown, title="Sell Signal")


더 많은