매월 폐쇄 가격과 이동 평균 크로스오버 전략

저자:차오장, 날짜: 2023-11-23 17:09:01
태그:

img

전반적인 설명

이 전략은 월별 폐쇄 가격과 이동 평균 라인 사이의 교차에 기반하여 거래 신호를 생성합니다. 월별 폐쇄 가격이 이동 평균 이상으로 넘어가면 길고 월별 폐쇄 가격이 이동 평균 이하로 넘어가면 평평합니다.

전략 논리

이 전략의 핵심 논리는 다음과 같습니다.

  1. 이동평균 기간 매개 변수를 입력으로 삼고 SMA와 EMA를 선택하세요.
  2. 이동평균선을 표시할 수 있는 옵션
  3. 신호 소스로 다른 티커의 폐쇄 가격을 사용할 수 있는 옵션.
  4. 매월 폐쇄 가격과 이동 평균 사이의 관계를 기반으로 거래 신호를 결정합니다.
    • 마이너스 마이너스 마이너스 마이너스 마이너스 마이너스
    • 마이너스 마이너스 마이너스 마이너스 마이너스 마이너스

이 전략은 가격 소음을 필터링하고 중장기 트렌드 반전을 포착하기 위해 이동 평균의 매끄러운 능력을 활용합니다. MA를 넘어서면 떠오르는 상승 추세를 나타냅니다. 아래로 넘어가면 추세가 하향 추세를 나타냅니다.

장점

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

  1. 월별 데이터를 사용하여 일내 소음을 효과적으로 필터링하고 중장기 트렌드를 포착합니다.
  2. 다양한 틱러에 대한 최적화를 위해 사용자 정의 가능한 MA 기간
  3. 신호 소스로 다른 틱을 사용하는 옵션은 안정성을 향상시킵니다.
  4. 첨단 반 재칠기 기술을 구현합니다
  5. 테스트의 용이성을 위해 유연한 역 테스트 시간 프레임

요약하자면, 이것은 중장기 투자자에게 특히 적합한 매개 변수 조정을 통해 대부분의 주식에 적응할 수 있는 간단하면서도 실용적인 전략 프레임워크입니다.

위험성

또한 몇 가지 위험 요소가 있습니다.

  1. 월별 데이터 업데이트는 느리고, 실시간 가격 변화를 반영할 수 없습니다.
  2. 뒤쳐지고 단기적인 기회를 놓칠 수 있습니다.
  3. MA는 내재적인 지연, 신호 타이밍 예측 불가능
  4. 열등한 매개 변수 선택은 과도한 보수주의 또는 놓친 기회로 이어집니다.

위험 감소를 위한 제안 방법:

  1. 보조 판단을 위해 더 빠른 시간 프레임 기술 지표를 포함
  2. 가장 좋은 매개 변수를 찾기 위해 MA 기간을 최적화
  3. 신호 소스로 더 안정적인 벤치마크를 사용
  4. 손실을 제한하기 위해 포지션 크기를 조정합니다.

더 나은 기회

이 전략은 개선 가능성이 크다.

  1. 수익을 확보하고 위험을 통제하기 위해 스톱 로스를 포함합니다.
  2. 신호 정확성을 향상시키기 위해 KD, MACD와 같은 보완 지표를 추가하십시오.
  3. 기계 학습 기술을 사용하여 MA 매개 변수를 동적으로 최적화하십시오.
  4. 트렌드에 맞는 포지션 크기를 도입
  5. 시장 조건에 따라 긴 / 짧은 전환 기능을 구축
  6. 더 빠른 반응을 위해 더 빠른 시간 프레임 가격과 통합

결론

월별 클로즈와 MA 크로스오버 전략은 간단하고 직설적인 논리를 가지고 있으며 매개 변수 조정을 통해 다양한 틱러에 적응 할 수 있습니다. 중장기 투자자에게 특히 적합합니다. 중지 손실, 매개 변수 최적화 및 기타 모듈의 지속적인 향상으로이 전략은 큰 약속을 보여줍니다.


/*backtest
start: 2022-11-16 00:00:00
end: 2023-11-22 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/
// © universique

//@version=4
strategy("Monthly MA Close ", shorttitle="MMAC", overlay=true, default_qty_type =  strategy.percent_of_equity, default_qty_value = 100)
//MAY 6 2020 18:00

// No repaint function 
// Function to securely and simply call `security()` so that it never repaints and never looks ahead.
f_secureSecurity(_symbol, _res, _src) => security(_symbol, _res, _src[1], lookahead = barmerge.lookahead_on)
//sec10 = f_secureSecurity(syminfo.tickerid, higherTf, data)

// ————— Converts current chart resolution into a float minutes value.
f_resInMinutes() => 
    _resInMinutes = timeframe.multiplier * (
      timeframe.isseconds ? 1. / 60             :
      timeframe.isminutes ? 1.                  :
      timeframe.isdaily   ? 60. * 24            :
      timeframe.isweekly  ? 60. * 24 * 7        :
      timeframe.ismonthly ? 60. * 24 * 30.4375  : na)
// ————— Returns the float minutes value of the string _res.
f_tfResInMinutes(_res) =>
    // _res: resolution of any TF (in "timeframe.period" string format).
    // Dependency: f_resInMinutes().
    security(syminfo.tickerid, _res, f_resInMinutes())

// —————————— Determine if current timeframe is smaller that higher timeframe selected in Inputs.
// Get higher timeframe in minutes.
//higherTfInMinutes = f_tfResInMinutes(higherTf)
// Get current timeframe in minutes.
currentTfInMinutes = f_resInMinutes()
// Compare current TF to higher TF to make sure it is smaller, otherwise our plots don't make sense.
//chartOnLowerTf = currentTfInMinutes < higherTfInMinutes

// Input
switch1=input(true, title="Show MA")
exponential = input(true, title="Exponential MA")
ticker = input(false, title="Other ticker MA")

tic_ma = input(title="Ticker MA", type=input.symbol, defval="BTC_USDT:swap")
res_ma = input(title="Time MA (W, D, [min])", type=input.string, defval="M")
len_ma = input(8, minval=1, title="Period MA")

ma_cus = exponential?f_secureSecurity(tic_ma, res_ma, ema(close,len_ma)) : f_secureSecurity(tic_ma, res_ma, sma(close,len_ma))
ma_long = exponential?f_secureSecurity(syminfo.tickerid, res_ma, ema(close,len_ma)) : f_secureSecurity(syminfo.tickerid, res_ma, sma(close,len_ma))

cl1 = f_secureSecurity(syminfo.tickerid, 'M', close)
cl2 = f_secureSecurity(tic_ma, 'M', close)

// Input Backtest Range
showDate  = input(defval = false, title = "Show Date Range", type = input.bool)
fromMonth = input(defval = 1,    title = "From Month",      type = input.integer, minval = 1, maxval = 12)
fromDay   = input(defval = 1,    title = "From Day",        type = input.integer, minval = 1, maxval = 31)
fromYear  = input(defval = 1995, title = "From Year",       type = input.integer, minval = 1850)
thruMonth = input(defval = 1,    title = "Thru Month",      type = input.integer, minval = 1, maxval = 12)
thruDay   = input(defval = 1,    title = "Thru Day",        type = input.integer, minval = 1, maxval = 31)
thruYear  = input(defval = 2112, title = "Thru Year",       type = input.integer, minval = 1850)

// Funcion Example
start     = timestamp(fromYear, fromMonth, fromDay, 00, 00)        // backtest start window
finish    = timestamp(thruYear, thruMonth, thruDay, 23, 59)        // backtest finish window
window()  => time >= start and time <= finish ? true : false       // create function "within window of time"

// Calculation
bullish_cross = ticker?cl2>ma_cus : cl1>ma_long
bearish_cross = ticker?cl2<ma_cus : cl1<ma_long

MAColor = bullish_cross ? color.green : bearish_cross ? color.red : color.orange

// Strategy
strategy.entry("long", strategy.long, when = window() and bullish_cross)
strategy.close("long", when = window() and bearish_cross)

// Output
plot(switch1?ma_long:na,color = MAColor,linewidth=4)

// Alerts
alertcondition(bullish_cross, title='Bullish', message='Bullish')
alertcondition(bearish_cross, title='Bearish', message='Bearish')

더 많은