이 전략은 간단한 이동 평균의 골드 크로스 및 데드 포크 원칙을 적용하여 주식의 장단점을 실현합니다. 빠른 선이 하향에서 느린 선을 돌파 할 때 더 많이하고 빠른 선이 상향에서 느린 선을 돌파 할 때 적습니다.
이 전략은 먼저 재측정의 시작 및 종료 시간을 정의하고, 평균의 종류와 주기 길이를 포함한 두 평균의 계산 파라미터를 설정한다.
getMAType () 함수를 사용하여 두 평균의 값을 계산한다. fastMA는 단기 평균이고, slowMA는 장기 평균이다.
이 전략의 핵심 논리는 다음과 같습니다.
FastMA에서 SlowMA를 밟을 때, 여러 개의 신호를 long로 발송합니다.
패스트MA 아래에서 슬로우MA를 통과할 때, 공백 신호 short를 발산한다.
마지막으로, 재검토 기간 동안, 더 많은 신호가 발생하면 장전 전략이 취해집니다. 빈 신호가 발생하면 빈 위치 전략이 취해집니다.
위험 요소에 대해 더 많은 최적화가 가능합니다.
트렌드를 식별하기 위해 다른 기술 지표 필터를 추가하십시오.
단편적 손실을 통제하기 위한 전략이 추가되었습니다.
“전자력 지표”를 도입하여 시장의 변동에 의한 중매를 피하십시오.
매개 변수 최적화 메커니즘을 구축하여 최적의 매개 변수 조합을 자동으로 찾습니다.
이 전략은 다음의 몇 가지 측면에서 더 개선될 수 있습니다.
고정된 스톱포인트를 설정하거나 스톱포인을 추적하여 손실을 제어하는 것과 같은 추가적인 스톱포드 전략
고정 포지션, 동적 포지션, 거래 위험을 제어하는 포지션 관리 전략을 추가하십시오.
필터를 추가하여 다른 기술 지표와 함께 트렌드를 인식하여 승률을 높입니다.
최적화 변수 설정, 그리드 검색, 선형 회귀 등의 방법을 통해 최적의 변수를 찾는다.
포지션 반전, 분할 포지션 구축 등 다중 포지션 전략으로 확장하여 풍요로운 거래 전략을 .
이 지표는 지진이 발생했을 때 을 피하기 위해 사용된다.
거래의 종류를 넓히고, 주식 지수 선물, 외환, 디지털 통화 등으로 확장한다.
이 전략은 이동 평균의 교차 원리에 기초하여 주식의 장단위 선택을 구현한다. 전략의 아이디어는 간단하고 명확하며, 광범위하게 사용되고, 적응력이 강하며, 실용적인 가치가 있다. 그러나 이 전략은 또한 일정하게 뒤처져 있고, 효과적으로 필터링하는 흔들림과 같은 단점이 있다. 향후에는 제약, 최적화 변수, 추가 필터 등의 측면에서 최적화하여 전략을 더 우월하게 할 수 있다.
/*backtest
start: 2023-09-10 00:00:00
end: 2023-10-10 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
//strategy("Golden X BF Strategy", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.0)
/////////////// Time Frame ///////////////
testStartYear = input(2010, "Backtest Start Year")
testStartMonth = input(1, "Backtest Start Month")
testStartDay = input(1, "Backtest Start Day")
testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay, 0, 0)
testStopYear = input(2019, "Backtest Stop Year")
testStopMonth = input(12, "Backtest Stop Month")
testStopDay = input(31, "Backtest Stop Day")
testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay, 0, 0)
testPeriod() => true
///////////// MA Params /////////////
source1 = input(title="MA Source 1", defval=close)
maType1 = input(title="MA Type 1", defval="sma", options=["sma", "ema", "swma", "wma"])
length1 = input(title="MA Length 1", defval=50)
source2 = input(title="MA Source 2", defval=close)
maType2 = input(title="MA Type 2", defval="sma", options=["sma", "ema", "swma", "wma"])
length2 = input(title="MA Length 2", defval=200)
///////////// Get MA Function /////////////
getMAType(maType, sourceType, maLen) =>
res = sma(close, 1)
if maType == "ema"
res := ema(sourceType, maLen)
if maType == "sma"
res := sma(sourceType, maLen)
if maType == "swma"
res := swma(sourceType)
if maType == "wma"
res := wma(sourceType, maLen)
res
///////////// MA /////////////
fastMA = getMAType(maType1, source1, length1)
slowMA = getMAType(maType2, source2, length2)
long = crossover(fastMA, slowMA)
short = crossunder(fastMA, slowMA)
/////////////// Plotting ///////////////
checkColor() => fastMA > slowMA
colCheck = checkColor() ? color.lime : color.red
p1 = plot(fastMA, color = colCheck, linewidth=1)
p2 = plot(slowMA, color = colCheck, linewidth=1)
fill(p1, p2, color = checkColor() ? color.lime : color.red)
bgcolor(long ? color.lime : short ? color.red : na, transp=20)
/////////////// Execution ///////////////
if testPeriod()
strategy.entry("Long", strategy.long, when=long)
strategy.entry("Short", strategy.short, when=short)