트리플 SMA를 기반으로 한 자동 추적 전략


생성 날짜: 2024-01-26 15:05:58 마지막으로 수정됨: 2024-01-26 15:05:58
복사: 1 클릭수: 640
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

트리플 SMA를 기반으로 한 자동 추적 전략

개요

트리플 SMA 전략은 3개의 다른 주기의 간단한 이동 평균을 기반으로 트렌드 판단과 엔트리를 하는 전략이다. 그것은 트렌드를 자동으로 추적하고, 트렌드에서 회전을 이용하여 포지션을 구축한다.

전략 원칙

이 전략은 3개의 다른 주기 SMA를 주요 트렌드 판단 지표로 사용하며, 200주기, 400주기, 600주기 SMA를 포함한다. 가격이 3개의 SMA를 상회할 때 상향 추세로 판단되며, 반대로 상향 추세로 판단된다.

엔트리 지표로서, 전략은 클로즈 가격과 스토크 클로즈 진동기를 사용한다. 가격은 트리플 SMA의 방향과 일치할 때만 신호를 낸다. 스토크 클로즈 지표는 오버 또는 과매매를 판단하기 위해 사용되며, 스토크 클로즈가 95을 넘어서면 더 많이 하고, 5을 넘어서면 비어있다.

스톱 스탠더드는 가격이 가장 느린 SMA에 도달했을 때 스톱됩니다.

전략은 최대 10번의 상장할 수 있으며, 세 개의 다른 비율의 스톱을 설정하고 있다. 각각 1%, 2% 및 6%이다.

우위 분석

트리플 SMA 전략의 가장 큰 장점은 세 개의 다른 시기를 사용하는 SMA를 조합하여 트렌드의 방향과 강도를 더 잘 판단할 수 있다는 것입니다. 단일 SMA보다 가짜 신호를 필터링 할 수있는 능력이 있습니다.

또한, 스토크 클로즈 지표와 함께 과매매를 판단하는 것은 트렌드 반전점 근처에 진입하는 것을 피할 수 있으며, 이로 인해 잘못된 항목을 줄일 수 있다.

스톱 스탠더드는 간단하고 직접적이며, 가장 느린 사이클의 SMA를 스톱 라인으로 사용하여, 너무 일찍 스톱하는 것을 최대한 피할 수 있다.

또한, 이 전략은 트렌드를 지속적으로 추적하여 수익을 창출할 수 있습니다.

위험 분석

이 전략의 주요 위험은 세 개의 SMA가 모든 가짜 신호를 완전히 필터링 할 수 없다는 것입니다. 가격의 돌파구 후에 다시 회귀를 형성하지 않으면 손실이 발생할 수 있습니다. 이러한 상황은 일반적으로 중요한 지원 저항 근처에서 발생합니다.

또한, StochClose 지표 자체는 잘못된 신호를 생성하여 부적절한 엔트리를 초래할 수 있습니다. 이것은 일반적으로 가격의 흔들림 영역에서 발생합니다.

이러한 위험을 줄이기 위해, SMA의 주기를 적절히 조정할 수 있습니다. 또는 다른 지표를 추가하여 조합 판단, KDJ, MACD 등으로, 들어오는 신호 품질을 보장 할 수 있습니다.

최적화 방향

이 전략은 다음과 같은 부분에서 최적화될 수 있습니다.

  1. 특정 품종에 더 적합한 주기 변수를 찾기 위해 SMA의 주기 수를 늘리거나 조정합니다.

  2. KDJ, MACD 등과 같은 다른 지표를 추가하여 항목의 품질을 향상시킵니다.

  3. 시장의 변동 범위에 더 적합한 스티핑 스톱 스탠더드를 최적화

  4. 가축의 수와 비율을 최적화하여 더 적합한 가축 전략을 찾습니다.

  5. 다양한 품종의 변수를 테스트하여 더 많은 품종에 대한 정책 변수를 전체적으로 적용합니다.

요약하다

트리플 SMA 전략은 전체적으로 매우 실용적인 트렌드 추적 전략이다. 그것은 세 개의 다른 주기 SMA와 StochClose 지표를 조합하여 더 나은 트렌드 판단 효과를 달성하고, 잘못된 신호를 효과적으로 방지할 수 있다. 또한 적절한 포지션을 허용하여 항상 트렌드를 추적 할 수 있습니다.

전략 소스 코드
/*backtest
start: 2023-12-01 00:00:00
end: 2023-12-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
strategy(title="Tripla Sma with entries based on sma price closes ", shorttitle="TRIPLE SMA STRATEGY", overlay=true) ////resolution=""
len = input(200, minval=1, title="sma 1 length")
len1 = input(400, minval=1, title="sma 2 length")
len2 = input(600, minval=1, title="sma 3 length")
src = input(close, title="Source")
////////////////////////////////////////////
smma = 0.0
smma := na(smma[1]) ? sma(src, len) : (smma[1] * (len - 1) + src) / len

up = smma > smma [1]
down =smma < smma[1]
mycolor = up ? #64b5f6 : down ? #d32f2f : na
fastma = sma(hl2, 1)

fastplot = plot(fastma, color=#000000, transp=100, title='sma on candle')
slowplot = plot(smma, color=mycolor, transp=55, title='sma1')

////////////////////////////////////////////
smma1 = 0.0
smma1 := na(smma1[1]) ? sma(src, len1) : (smma1[1] * (len1 - 1) + src) / len1

up2 = smma1 > smma1 [1]
down2 =smma1 < smma1[1]

mycolor2 = up2 ? #64b5f6 : down2 ? #d32f2f : na
slowplot2 = plot(smma1, color=mycolor2, transp=45, title='sma2')

////////////////////////////////////////////
smma2 = 0.0
smma2 := na(smma2[1]) ? sma(src, len2) : (smma2[1] * (len2 - 1) + src) / len2

up3 = smma2 > smma2 [1]
down3 =smma2 < smma2[1]

mycolor3 = up3 ? #64b5f6 : down3 ? #d32f2f : na
slowplot3 = plot(smma2, color=mycolor3, transp=35, title='sma3')

////////////////////////////////////////////////////////////////////////////////////////
//Fill gaps
fillData = smma > fastma
fillData2 = smma < fastma

fillDtat = smma1 > smma
fillDtat2 = smma1 < smma

fillDat = smma2 > smma1
fillDat2 = smma2 < smma1


fillCol1 = fillData ? #ef5350 : fillData2 ? #64b5f6 : na
fillCol2 = fillDtat ? #ef5350 : fillDtat2 ? #64b5f6 : na
fillCol3 = fillDat ? #ef5350 : fillDat2 ? #64b5f6 : na


fill(slowplot, fastplot, color=fillCol1, transp=90, title="sma1 fill")
fill(slowplot, slowplot2, color=fillCol2, transp=80, title="sma2 fill")
fill(slowplot2, slowplot3, color=fillCol3, transp=60, title="sma3 fill")

uc = (close > smma) and (close > smma1)
dc = (close < smma) and (close < smma1)

barColor = uc ? #64b5f6 : dc ? #e91e63 : #b2b5be
barcolor(color=barColor)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//StochClose from @trendinvestpro 
periods = input(50, minval=1, title="length for the oscillator")
smooth = input(5, minval=1, title="oscillator smoothing")
hhc=highest(close,periods)
llc=lowest(close,periods)
StochClose = sma((close-llc)/(hhc-llc)*100, smooth)

shortline = input(95, minval=0, title="signal when oscillator crosses above")
longline = input(5, minval=0, title="signal when oscillator crosses below")

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
longs = close > smma2
shorts = close < smma2



long = longs == true and crossunder(StochClose, longline)
short = shorts == true and crossover(StochClose, shortline)

stoplong = close < smma and close < smma1 and close < smma2
stopshort = close > smma and close > smma1 and close > smma2

p1 = strategy.position_avg_price / 100 / syminfo.mintick

maxx = input(2500, title="max orders filled on a day", minval=0)
takeprofit1 = input(1, title="take profit level 1", minval=0)
takeprofit2 = input(2, title="take profit level 2", minval=0)
takeprofit3 = input(6, title="take profit level 3", minval=0)

takeprofitqt1 = input(30, title="take profit quantity first", minval=0)
takeprofitqt2 = input(30, title="take profit quantity second", minval=0)
takeprofitqt3 = input(30, title="take profit quantity third", minval=0)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////Strategy entries/////////////////////////////////////////////////////////////////////////////////////////
// strategy.risk.max_intraday_filled_orders(maxx)
strategy.entry("long", strategy.long, when=long)
strategy.exit("tpl1", "long", qty_percent = takeprofitqt1, profit = takeprofit1 * p1)
strategy.exit("tpl2", "long", qty_percent = takeprofitqt2, profit = takeprofit2 * p1)
strategy.exit("tpl3", "long", qty_percent = takeprofitqt3, profit = takeprofit3 * p1)
strategy.close("long", when=stoplong == true)


strategy.entry("short", strategy.short, when=short)
strategy.exit("tpl1", "short", qty_percent = takeprofitqt1, profit = takeprofit1 * p1)
strategy.exit("tpl2", "short", qty_percent = takeprofitqt2, profit = takeprofit2 * p1)
strategy.exit("tpl3", "short", qty_percent = takeprofitqt3, profit = takeprofit3 * p1)
strategy.close("short", when=stopshort == true)