이동평균 파업 전략

저자:차오장, 날짜: 2023-09-26 16:18:37
태그:

전반적인 설명

이동평균 브레이크아웃 전략은 이동평균을 사용하여 진입과 출구를 결정하는 단기 거래 전략이다. 단순성과 사용 편의성이 특징이다.

전략 논리

핵심 논리는 두 개의 이동 평균, 빠른 라인과 느린 라인을 기반으로 가격의 흐름을 측정합니다. 빠른 라인은 짧은 기간을 가지고 더 민감합니다. 느린 라인은 더 긴 기간을 가지고 더 안정적입니다.

코드는 사용자가 입력 매개 변수를 통해 빠른 라인 기간 shortPeriod와 느린 라인 기간 longPeriod을 설정할 수 있습니다. 두 이동 평균의 값은 shortSMA와 longSMA로 계산됩니다.

빠른 이동 평균이 느린 이동 평균을 넘을 때, 상향 브레이크와 긴 진입을 신호합니다. 빠른 MA가 느린 MA를 넘을 때, 하향 브레이크와 짧은 진입을 신호합니다.

긴 입구 조건:

Fast MA crosses above slow MA
Fast MA > Slow MA

단기 출입 조건:

Fast MA crosses below slow MA
Fast MA < Slow MA 

이 전략은 또한 위험을 통제하기 위해 스톱 로스, 수익 취득 및 포지션 사이즈 설정을 포함합니다.

장점

  • 사용하기 쉽고 초보자도 쉽게 이해할 수 있습니다.
  • 이동 평균은 소음을 필터링합니다.
  • 각기 다른 기간에 대한 미세 조정 MA 기간의 유연성
  • 미리 정의된 스톱 로스 및 수익 취득

위험성

  • 거짓의 탈출과 윙사 (whipsaws) 에 민감합니다.
  • 범위를 제한하는 불안정한 시장에 이상적이지 않습니다.
  • 늦어질 수 있습니다.
  • 트렌드 반전을 효과적으로 필터링 할 수 없습니다.

위험 관리:

  • 잘못된 신호를 피하기 위해 필터를 추가합니다.
  • 경향 이 분명 할 때 전략 을 적용 하라
  • 더 나은 항목을 위해 MA 매개 변수를 최적화
  • 더 넓은 정류를 허용하여 조기 정류를 피하십시오.

더 나은 기회

  • 가장 좋은 조합을 찾기 위해 MA 매개 변수를 최적화
  • BOLL 채널이나 KD와 같은 추가 지표를 추가합니다.
  • 수익을 극대화하기 위해 출구 규칙을 개선
  • 다른 기기에 대한 견고성 테스트
  • 빅데이터를 이용한 머신러닝을 통합

결론

이동 평균 브레이크아웃 전략은 빠르고 느린 MA를 가진 신호를 생성하여 이해하기 쉽습니다. 그러나 잘못된 브레이크와 지연 문제와 같은 몇 가지 결함이 있습니다. 매개 변수 조정, 추가 필터 및 기타 향상으로 전략을 개선 할 수 있습니다. 전반적으로 알고리즘 거래에 초보자 친화적 인 첫 번째 단계로 작용하며 핵심 개념을 파악한 후 더 고급 전략의 길을 개척합니다.


/*backtest
start: 2023-08-26 00:00:00
end: 2023-09-25 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/
// © YohanNaftali

//@version=5

///////////////////////////////////////////////////////////////////////////////
// Heikin Ashi Candle Startegy
// ver 2021.12.29
// © YohanNaftali
// This script composed by Yohan Naftali for educational purpose only 
// Reader who will use this signal must do own research
///////////////////////////////////////////////////////////////////////////////
strategy(
     title = 'Heikin Ashi Candle Startegy Long',  
     shorttitle = 'HA Strategy Long',  
     format = format.price,
     precision = 0,
     overlay = true)

// Input
validationPeriod = input.int( 
     defval = 3, 
     title = 'Validation Period', 
     group = 'Candle')

qtyOrder = input.float(
     defval = 1.0,
     title = 'Qty', 
     group = 'Order')

maxActive = input.float(
     defval = 1.0,
     title = 'Maximum Active Open Position', 
     group = 'Order')

// Long Strategy
tpLong = input.float(
     defval = 1,
     title = "Take Profit (%)",
     minval = 0.0, 
     step = 0.1, 
     group = "Long") * 0.01

slLong = input.float(
     defval = 25,
     title = "Stop Loss (%)", 
     minval=0.0, 
     step=0.1,
     group="Long") * 0.01

trailingStopLong = input.float(
     defval = 0.2,
     title = "Trailing Stop (%)",
     minval = 0.0, 
     step = 0.1,
     group = 'Long') * 0.01

// Calculation
haTicker = ticker.heikinashi(syminfo.tickerid)
haClose = request.security(haTicker, timeframe.period, close)
haOpen = request.security(haTicker, timeframe.period, open)

// Long
limitLong = tpLong > 0.0 ? strategy.position_avg_price * (1 + tpLong) : na
stopLong = slLong > 0.0 ? strategy.position_avg_price * (1 - slLong) : na
float trailLong = 0.0
trailLong := if strategy.position_size > 0
    trailClose = close * (1 - trailLong)
    math.max(trailClose, trailLong[1])
else
    0

isGreen = true
for i = 0 to validationPeriod-1
    isGreen := isGreen and haClose[i] > haOpen[i]        
isLong = isGreen and haClose[validationPeriod] < haOpen[validationPeriod]



plot(
     limitLong,
     title = 'Limit', 
     color = color.rgb(0, 0, 255, 0), 
     style = plot.style_stepline,
     linewidth = 1)

plot(
     trailLong,
     title = 'Trailing', 
     color = color.rgb(255, 255, 0, 0), 
     style = plot.style_stepline,
     linewidth = 1)

plot(
     stopLong,
     title = 'Stop', 
     style = plot.style_stepline,
     color = color.rgb(255, 0, 0, 0), 
     linewidth = 1)

// plotshape(
//      isLong, 
//      title = 'Entry', 
//      style = shape.arrowup, 
//      location = location.belowbar, 
//      offset = 1, 
//      color = color.new(color.green, 0), 
//      text = 'Long Entry',
//      size = size.small)

// Strategy
strategy.risk.max_position_size(maxActive)
strategy.risk.allow_entry_in(strategy.direction.long)

strategy.entry(
     id = "Long", 
     direction = strategy.long, 
     qty = qtyOrder,  
     when = isLong,       
     alert_message = "LN")
if (strategy.position_size > 0)
    strategy.exit(
         id = "Long Exit",
         from_entry = "Long",
         limit = limitLong,
         stop = stopLong,
         trail_price = trailLong,
         alert_message = "LX")      

더 많은