트리플 SMA 자동 추적 전략

저자:차오장, 날짜: 2024-01-26 15:05:58
태그:

img

전반적인 설명

트리플 SMA 전략은 트렌드 식별 및 엔트리를 위해 다른 기간의 세 가지 간단한 이동 평균 (SMA) 을 기반으로 트렌드를 따르는 전략입니다. 트렌드에서 인하 시 트렌드를 자동으로 추적하고 포지션을 추가 할 수 있습니다.

전략 논리

이 전략은 200~400~600주기 SMA를 포함한 다른 기간의 3개의 SMA를 주요 트렌드 지표로 사용한다. 가격이 3개의 SMA보다 높을 때 상승 추세를 나타내고, 하락 추세를 나타낸다.

엔트리에 대한 전략은 클로즈 가격과 스톡 클로즈 오시일레이터의 사용을 결합합니다. 가격은 삼중 SMAs 방향과 일치 할 때만 신호가 생성됩니다. 스톡 클로즈는 과잉 구매 / 과잉 판매 수준을 식별하고 95 이상의 경로를 넘을 때 긴 신호를 주고 5 이하를 넘을 때 짧은 신호를 제공합니다.

스톱 로스는 가장 느린 SMA 아래의 가격 교차로 설정됩니다.

이 전략은 10배까지 피라미딩을 허용합니다. 3개의 수익 레벨이 1%, 2% 및 6%의 수익으로 내장되어 있습니다.

이점 분석

트리플 SMA 전략의 가장 큰 장점은 다른 기간의 세 개의 SMA를 결합함으로써 트렌드 방향과 강도를 더 잘 파악 할 수 있다는 것입니다. 단일 SMA 전략보다 잘못된 신호를 필터링하는 능력이 더 강합니다.

또한, 과잉 구매/ 과잉 판매 분석을 위해 StochClose를 통합하면 잠재적 인 트렌드 반전 지점에 대한 신호를 취하는 것을 피합니다.

가장 느린 SMA에 기반한 스톱 손실은 또한 전략의 트렌드를 타는 능력을 극대화하면서 조기 스톱 아웃을 최소화합니다.

피라미딩을 허용하면 전략이 지속적으로 트렌드에 참여할 수 있습니다.

위험 분석

이 전략의 주요 위험은 삼중 SMAs가 모든 잘못된 신호를 완전히 필터링하지 못할 수 있다는 것입니다. 가격이 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)




더 많은