동적 이동 평균 리트랙션 마틴 전략

저자:차오장, 날짜: 2023-11-24 10:19:21
태그:

img

전반적인 설명

동적 이동 평균 리트레이싱 마틴 전략은 이동 평균 크로스오버와 풀백 신호를 결합하여 입출 신호를 생성하는 빈번한 거래 전략이다. 이 전략은 단기 트렌드를 포착하기 위해 3 일 및 8 일 간 간단한 이동 평균의 크로스오버와 분리를 사용하여 단기 트렌드를 포착하고 위험을 제어하기 위해 스톱을 채택하고 이익을 취합니다. 이 전략은 다른 시장 조건에 따라 거래 방향을 선택할 수 있습니다.

전략 논리

이 전략은 3일 및 8일 간단한 이동 평균과 그 크로스오버 신호를 사용합니다. 3일 MA가 8일 MA보다 높을 때 긴 신호가 생성되며, 3일 MA가 8일 MA보다 낮을 때 짧은 신호가 생성됩니다. 긴 신호는 긴 진입을 유발하고 짧은 신호는 짧은 진입을 유발합니다.

포지션이 없다면, 전략은 크로스오버 신호를 기반으로 엔트리를 결정합니다. 엔트리 후, 스톱 로스 가격과 이윤을 취하는 가격은 최신 클로즈 가격, 스톱 로스 비율 및 이윤을 취하는 비율을 기반으로 계산됩니다. 예를 들어, 긴 포지션을 보유 할 때, 스톱 로스 가격은 최신 클로즈 가격 인하 스톱 로스 비율을 8 일 MA로 곱한 것입니다. 이윤을 취하는 가격은 최신 클로즈 가격 인더 스톱 로프 비율을 8 일 MA로 곱한 것입니다.

기존의 긴 포지션이 있다면, 가격이 수익을 취하거나 손실을 멈추게 할 때, 8 일 MA의 pullback 신호가 발생하면 포지션은 닫힐 것입니다. 이 시점에서, 손실 중지 가격과 수익을 취하는 가격은 0으로 재설정됩니다. 짧은 포지션을 처리하는 논리는 비슷합니다.

이 전략은 또한 차트에서 입구와 출구 지점을 그래프화합니다. 예를 들어, 긴 입구는 상향 삼각형으로 그리고 긴 출구는 하향 삼각형으로 그래프화됩니다. 이것은 입구와 출구를 시각적으로 판단하는 데 도움이됩니다.

이점 분석

이 전략의 장점은 다음과 같습니다.

  1. 이동 평균 크로스오버 신호를 사용하여 단기 트렌드를 캡처하여 빈번한 거래를 허용합니다.
  2. 스톱 손실 메커니즘은 단일 손실을 제어 할 수 있습니다.
  3. 이윤을 취하면 부분적인 이윤을 얻을 수 있습니다.
  4. 거래 방향은 각기 다른 단계에 맞게 선택할 수 있습니다.
  5. 차트에 출입점과 출입점을 표시합니다.

위험 분석

이 전략의 주요 위험은 다음과 같습니다.

  1. 단기적인 MA 전략은 벼룩을 깎는 경향이 있습니다.
  2. 이동 평균에서 신호가 뒤떨어질 가능성.
  3. 연속적인 손실은 더 심한 손실로 이어질 수 있습니다.
  4. 잘못 설정된 스톱 손실 비율은 너무 느슨하거나 너무 좁을 수 있습니다.

위험은 정지 손실 비율을 합리적으로 확대하고 MA 매개 변수를 최적화하고 추가 필터 조건을 도입함으로써 감소 할 수 있습니다. 또한 개인 관용을 올바르게 평가하고 과잉 거래를 피하는 것이 중요합니다.

최적화 방향

이 전략은 다음과 같은 측면에서 최적화 될 수 있습니다.

  1. 최적의 매개 변수를 찾기 위해 더 많은 MA 조합을 테스트합니다.
  2. 신호 품질을 향상시키기 위해 RSI, KD 등과 같은 다른 지표를 추가하십시오.
  3. 다른 제품과 시간 프레임에 따라 스톱 손실 비율을 조정합니다.
  4. 고정량 또는 고정 자본과 같은 포지션 사이즈 컨트롤을 추가합니다.
  5. 입력 순서 규칙을 추가합니다.
  6. 스톱 로스 또는 수익을 취하는 수준을 최적화하고 평가합니다.

요약

동적 이동 평균 리트레이싱 마틴 전략은 단기 거래 전략이다. 이동 평균 크로스오버로 형성된 단기 트렌드를 포착하고 적절한 스톱과 수익을 취함으로써 위험을 관리한다. 빈번한 거래 특성으로 인해 수익 기회뿐만 아니라 위험이 발생한다. 매개 변수를 최적화하고 신호를 필터링하고 위험을 제어함으로써이 전략을 더욱 향상시킬 수 있다.


/*backtest
start: 2022-11-17 00:00:00
end: 2023-11-23 00:00:00
period: 1d
basePeriod: 1h
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/
// © blackcat1402
//@version=5
strategy('[blackcat] L1 MartinGale Scalping Strategy', overlay=true, pyramiding = 5)

// Define input variables
takeProfit = input(1.03, title='Take Profit')
stopLoss = input(0.95, title='Stop Loss')
inputTradingMode = input.string(defval='Long', options=['Long', 'Short', 'BiDir'], title='Trading Mode')

//The purpose of this rule is to forbid short entries, only long etries will be placed. The rule affects the following function: 'entry'.
strategy.risk.allow_entry_in(inputTradingMode == 'Long' ? strategy.direction.long : inputTradingMode == 'Short' ? strategy.direction.short : strategy.direction.all)

// Define strategy logic
entryPrice = 0.0
stopPrice = 0.0
takeProfitPrice = 0.0
stopLossPrice = 0.0

// Define SMA crossover and crossunder signals
sma3 = ta.sma(close, 3)
sma8 = ta.sma(close, 8)
plot(sma3, color=color.yellow)
plot(sma8, color=color.fuchsia)
crossoverSignal = ta.crossover(sma3, sma8)
crossunderSignal = ta.crossunder(sma3, sma8)
crossoverState = sma3 > sma8
crossunderState = sma3 < sma8

if strategy.position_size == 0
    if crossoverState
        strategy.entry('Buy', strategy.long)
        entryPrice := close
        stopPrice := close - stopLoss * sma8[1]
        takeProfitPrice := close + takeProfit * sma8[1]
        stopLossPrice := stopPrice
        stopLossPrice
    if crossunderState
        strategy.entry('Sell', strategy.short)
        entryPrice := close
        stopPrice := close + stopLoss *  sma8[1]
        takeProfitPrice := close - takeProfit *  sma8[1]
        stopLossPrice := stopPrice
        stopLossPrice

if strategy.position_size > 0
    if (close > takeProfitPrice or close < stopLossPrice) and crossunderState
        strategy.close('Buy')
        entryPrice := 0.0
        stopPrice := 0.0
        takeProfitPrice := 0.0
        stopLossPrice := 0.0
        stopLossPrice
    else
        strategy.entry('Buy', strategy.long)
        entryPrice := close
        stopPrice := close - stopLoss *  sma8[1]
        takeProfitPrice := close + takeProfit *  sma8[1]
        stopLossPrice := stopPrice
        stopLossPrice

if strategy.position_size < 0
    if (close > takeProfitPrice or close < stopLossPrice) and crossoverState
        strategy.close('Sell')
        entryPrice := 0.0
        stopPrice := 0.0
        takeProfitPrice := 0.0
        stopLossPrice := 0.0
        stopLossPrice
    else
        strategy.entry('Sell', strategy.short)
        entryPrice := close
        stopPrice := close + stopLoss *  sma8[1]
        takeProfitPrice := close - takeProfit *  sma8[1]
        stopLossPrice := stopPrice
        stopLossPrice

// Plot entry and exit points
plotshape(strategy.position_size > 0 and crossoverSignal, 'Buy Entry', shape.triangleup, location.belowbar, color.new(color.green, 0), size=size.small)
plotshape(strategy.position_size > 0 and (close >= takeProfitPrice or close <= stopLossPrice), 'Buy Exit', shape.triangledown, location.abovebar, color.new(color.red, 0), size=size.small)
plotshape(strategy.position_size < 0 and crossunderSignal, 'Sell Entry', shape.triangledown, location.abovebar, color.new(color.red, 0), size=size.small)
plotshape(strategy.position_size < 0 and (close >= takeProfitPrice or close <= stopLossPrice), 'Sell Exit', shape.triangleup, location.belowbar, color.new(color.green, 0), size=size.small)



더 많은