골든 크로스 상승 추세 추적 전략

저자:차오장, 날짜: 2024-01-03 11:46:44
태그:

img

전반적인 설명

이 전략은 이동 평균의 황금 십자 원리에 기초하여 설계되었습니다. 구체적으로, 그것은 50 기간 라인과 200 기간 라인 두 가지 간단한 이동 평균을 사용합니다. 50 기간 라인이 200 기간 라인을 아래에서 뚫을 때 구매 신호가 생성됩니다. 50 기간 라인이 위에서 200 기간 라인을 뚫을 때 판매 신호가 생성됩니다.

전략 논리

이 전략은 파인 스크립트 언어로 작성되었으며, 주요 논리는 다음과 같습니다.

  1. 두 개의 SMA를 계산합니다: 50주기 SMA와 200주기 SMA
  2. 골든 크로스를 결정합니다. 50주기 SMA가 200주기 SMA를 넘을 때, 길게 이동합니다.
  3. 사망 교차를 결정합니다. 50주기 SMA가 200주기 SMA보다 낮을 때 Close 포지션

여기서 SMA 지표를 사용하는 것의 중요성은 시장 소음을 효과적으로 필터링하고 장기 트렌드를 포착 할 수 있다는 것입니다. 더 빠른 SMA 라인이 느린 SMA 라인의 위를 넘을 때 단기 상승 트렌드 모멘텀이 장기 하락 트렌드를 물리치고 구매 신호를 생성한다는 것을 나타냅니다.

장점

이 전략은 다음과 같은 장점을 가지고 있습니다.

  1. 간단하고 이해하기 쉬운 원칙, 실행하기 쉬운
  2. 합리적인 PARAMETERS 설정, 두 개의 SMA 기간을 사용자 정의 할 수 있으며 다른 시장에 적응 할 수 있습니다.
  3. 안정적인 파이인 언어 버전으로 작성되어 효율적으로 실행됩니다.
  4. 풍부한 시각적 설정, 사용하기 쉽습니다.

위험 과 해결책

이 전략은 또한 몇 가지 위험을 안고 있습니다.

  1. 잘못된 신호를 생성하는 잘못된 브레이크가 발생할 수 있습니다.

  2. 단기 시장에 반응할 수 없습니다. 장기 투자자만 사용할 수 있습니다. 적절한 빠른 SMA 기간을 줄일 수 있습니다.

  3. 마감액은 크거나, 손해를 막거나, 포지션 관리에 적절한 조정을 할 수 있습니다.

최적화 방향

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

  1. 필터링을 위한 다른 지표를 추가하여 여러 구매/판매 조건을 결합하여 잘못된 신호를 줄이십시오.

  2. 스톱 로스 메커니즘을 추가합니다. 가격이 특정 수준을 넘으면 필수 스톱 로스입니다.

  3. 포지션 관리를 최적화하십시오. 트렌드를 따라 피라미딩, 후속 스톱 로스 등을 통해 인출을 통제하고 높은 수익을 추구하십시오.

  4. 매개 변수 최적화. 수익/위험 비율에 다른 매개 변수의 영향을 평가합니다.

결론

일반적으로, 이것은 전형적인 트렌드 추적 전략이다. 그것은 간단하고 효율적으로 장기적인 트렌드를 캡처하기 위해 SMA의 장점을 활용한다. 하나의 스타일과 튜닝 공간에 따라 사용자 정의 할 수 있다. 또한 추가 최적화와 개선을 위해 기존의 결함을 알아볼 필요가 있다.


/*backtest
start: 2023-12-26 00:00:00
end: 2024-01-02 00:00:00
period: 30m
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// @version=4
//
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// www.tradingview.com/u/TradeFab/
// www.tradefab.com
// ___  __        __   __  __       __
//  |  |__)  /\  |  \ |__ |__  /\  |__)
//  |  |  \ /~~\ |__/ |__ |   /~~\ |__)
//
// DISCLAIMER: Futures, stocks and options trading involves substantial risk of loss 
// and is not suitable for every investor. You are responsible for all the risks and 
// financial resources you use and for the chosen trading system.
// Past performance is not indicative for future results. In making an investment decision,
// traders must rely on their own examination of the entity making the trading decisions!
//
// TradeFab's Golden Cross Strategy.
// The strategy goes long when the faster SMA 50 (the simple moving average of the last 50 bars) crosses
// above the SMA 200. Orders are closed when the SMA 50 crosses below SMA 200. The strategy does not short.
//
VERSION = "1.2"
// 1.2 FB 2020-02-09 converted to Pine version 4
// 1.1 FB 2017-01-15 added short trading
// 1.0 FB 2017-01-13 basic version using SMAs
//
strategy(
   title        = "TFs Golden Cross " + VERSION, 
   shorttitle   = "TFs Golden Cross " + VERSION, 
   overlay      = true
   )


///////////////////////////////////////////////////////////
// === INPUTS ===
///////////////////////////////////////////////////////////
inFastSmaPeriod     = input(title="Fast SMA Period", type=input.integer, defval=50, minval=1)
inSlowSmaPeriod     = input(title="Slow SMA Period", type=input.integer, defval=200, minval=1)

// backtest period
testStartYear       = input(title="Backtest Start Year",    type=input.integer, defval=2019, minval=2000)
testStartMonth      = input(title="Backtest Start Month",   type=input.integer, defval=1, minval=1, maxval=12)
testStartDay        = input(title="Backtest Start Day",     type=input.integer, defval=1, minval=1, maxval=31)
testStopYear        = input(title="Backtest Stop Year",     type=input.integer, defval=2099, minval=2000)
testStopMonth       = input(title="Backtest Stop Month",    type=input.integer, defval=12, minval=1, maxval=12)
testStopDay         = input(title="Backtest Stop Day",      type=input.integer, defval=31, minval=1, maxval=31)


///////////////////////////////////////////////////////////
// === LOGIC ===
///////////////////////////////////////////////////////////
smaFast = sma(close, inFastSmaPeriod)
smaSlow = sma(close, inSlowSmaPeriod)

bullishCross = crossover (smaFast, smaSlow)
bearishCross = crossunder(smaFast, smaSlow)

// detect valid backtest period
isTestPeriod() => true


///////////////////////////////////////////////////////////
// === POSITION EXECUTION ===
///////////////////////////////////////////////////////////
strategy.entry("long",  strategy.long,  when=bullishCross)
strategy.entry("short", strategy.short, when=bearishCross)


///////////////////////////////////////////////////////////
// === PLOTTING ===
///////////////////////////////////////////////////////////
// background color
nopColor = color.new(color.gray, 50)
bgcolor(not isTestPeriod() ? nopColor : na)

bartrendcolor = 
   close > smaFast and 
   close > smaSlow and 
   change(smaSlow) > 0 
       ? color.green 
       : close < smaFast and 
         close < smaSlow and 
         change(smaSlow) < 0 
             ? color.red 
             : color.blue
barcolor(bartrendcolor)
plot(smaFast, color=change(smaFast) > 0 ? color.green : color.red, linewidth=2)
plot(smaSlow, color=change(smaSlow) > 0 ? color.green : color.red, linewidth=2)

// label
posColor = color.new(color.green, 75)
negColor = color.new(color.red, 75)
dftColor = color.new(color.blue, 75)
posProfit= (strategy.position_size != 0) ? (close * 100 / strategy.position_avg_price - 100) : 0.0
posDir   = (strategy.position_size  > 0) ? "long" : strategy.position_size < 0 ? "short" : "flat"
posCol   = (posProfit > 0) ? posColor : (posProfit < 0) ? negColor : dftColor

var label lb = na
label.delete(lb)
lb := label.new(bar_index, max(high, highest(5)[1]),
   color=posCol,
   text="Pos: "+ posDir +
      "\nPnL: "+tostring(posProfit, "#.##")+"%" +
      "\nClose: "+tostring(close, "#.##"))
  

더 많은