이동평균선 돌파 전략


생성 날짜: 2023-09-26 16:18:37 마지막으로 수정됨: 2023-09-26 16:18:37
복사: 0 클릭수: 884
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

개요

평균선 돌파 전략은 이동 평균을 이용하여 판단하는 짧은 선 거래 전략이다. 이 전략은 평균선 길이를 설정하여 평균선이 돌파될 때 매매를 하는 것이다. 이 전략은 조작이 간단하고 쉽게 습득할 수 있다.

전략 원칙

이 전략은 주로 두 개의 이동 평균, 빠른 선과 느린 선을 설정하여 가격 움직임을 판단합니다. 빠른 선의 주기는 짧고 반응 민감합니다. 느린 선의 주기는 길고 반응은 평평합니다.

코드는 입력 파라미터를 설정하여 단선주기 (shortPeriod) 와 느린선주기 (longPeriod) 를 정의한다. 그리고 두 평행선의 값을 계산한다.

단기평균선이 아래로 올라가 긴 주기평균선을 돌파할 때, 가격운동이 하향으로 돌진하여 더 많은 것을 나타냅니다. 단기평균선이 위로 내려가 긴 주기평균선을 돌파할 때, 가격운동이 하향으로 돌진하여 더 많은 것을 나타냅니다.

이 경우, 입장이 가능한 조건은

快线由下向上突破慢线
快线>慢线

코스피 상장 조건:

快线由上向下跌破慢线  
快线<慢线

또한, 전략은 위험을 제어하기 위해 스톱로스, 스톱, 금액과 같은 파라미터를 설정합니다.

전략적 이점

  • 작동이 간단하고, 배우기 쉽고, 초보자에게 적합합니다.
  • 평균선에는 약간의 추세 필터링 기능이 있으며, 일부 소음을 필터링 할 수 있습니다.
  • 유연하게 평선 주기 조정, 다른 주기 운영에 적응
  • 리스크를 제어하기 위해 미리 설정할 수 있는 스톱포인트

전략적 위험

  • 가짜 침입이 발생하여 잘못된 신호가 발생하기 쉽다.
  • 급격한 변동 시장에 적합하지 않으며, 트렌드가 분명할 때 사용해야 합니다.
  • 평균선 시스템이 늦어졌고, 출입시간이 맞지 않았다.
  • 강력한 추세를 효과적으로 필터링할 수 없는 역전

위험 예방:

  • 가짜 신호를 방지하기 위해 다른 지표와 함께 필터링
  • 유동성이 뚜렷한 경우를 선택하고, 흔들리는 시장에서는 사용하지 마십시오.
  • 평균자책점을 적절하게 조정하여 출전 시기를 최적화
  • 제약범위를 적절히 완화하고, 제약범위를 적절히 완화하고, 제약범위를 적절히 완화합니다.

전략 최적화 방향

  • 평선 시스템 파라미터를 최적화하여 최적의 주기 조합을 찾습니다.
  • BOLL 통로, KD 등과 같은 다른 지표 판단을 추가합니다.
  • 포지션 관리 전략을 최적화하여 수익을 극대화하십시오.
  • 다양한 종류의 계약의 매개 변수 강도를 테스트하는 방법
  • 기계 학습 알고리즘을 추가하고, 빅데이터를 활용하여 최적화

요약하다

평평선 돌파 전략의 개념은 간단하며, 속속 평평선 판단을 통해 더 많은 공백 시간을 수행하고, 조작이 쉽다. 그러나 허위 돌파, 지연 등과 같은 몇 가지 문제도 있다. 변수 최적화, 다른 지표의 조합과 같은 방법을 통해 개선할 수 있다.

전략 소스 코드
/*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")