그라디언트 MACD 양성 전략

저자:차오장, 날짜: 2023-12-19 16:14:50
태그:

img

전반적인 설명

이 전략은 가격선을 매끄럽게하기 위해 하이킨-아시 촛불을 계산하고 MACD 지표를 결합하여 거래 신호를 생성하여 중장기 트렌드를 추적하는 양적 전략을 구현합니다.

전략 논리

  1. 하이킨-아시 오픈, 클로즈, 하이크와 로우 가격을 계산하여 하이킨-아시 촛불을 그래프화하고 순탄한 가격 추세를 나타냅니다.

  2. MACD 매개 변수를 설정합니다. 빠른 길이 12, 느린 길이 26, 신호 길이 9.

  3. DEA 느린 라인, DEA 빠른 라인, MACD 히스토그램을 계산합니다.

  4. MACD 히스토그램이 0을 넘을 때 장거리; 0을 넘을 때 단거리

  5. 연간, 월간 및 일간 필터를 추가하여 특정 시간 범위로 거래를 제한합니다.

이점 분석

  1. 하이킨-아시 촛불들은 시장 소음을 효과적으로 필터링하여 트렌드를 식별합니다.

  2. MACD는 명확한 트렌드 거래 신호를 제공합니다.

  3. 하이킨-아시와 MACD를 결합하면 신호 품질과 수익성이 향상됩니다.

  4. 시간 필터는 역사적인 성과에 기반한 거래 일정을 최적화하는 데 도움이 됩니다.

위험 분석

  1. 트렌드 반전 때 큰 손실이 발생할 가능성

  2. 잘못된 MACD 매개 변수는 지나치게 쓸모없는 신호를 생성할 수 있습니다.

  3. 딱딱한 시간 필터는 좋은 거래 기회를 놓칠 수 있습니다.

대책:

  1. 손실을 제한하기 위해 Stop Loss/Take Profit를 설정합니다.

  2. MACD 매개 변수를 최적화하여 최적의 조합을 결정합니다.

  3. 지역 추세를 파악하기 위해 지표를 추가합니다.

최적화 방향

  1. 다양한 매개 변수 조합을 테스트하여 최적을 찾습니다.

  2. 트레일링 스톱 로스 같은 스톱 로스 메커니즘을 추가합니다.

  3. EMA, KDJ와 같은 지표를 추가하여 역전점을 결정합니다.

  4. 분리를 피하기 위해 부피 지표를 추가합니다.

요약

이 전략은 하이킨-아시 촛불로 가격 동작을 부드럽게 하고, 트렌드를 따르는 양성 전략을 구현하기 위해 MACD 트레이딩뷰 지표로 트렌드 방향과 진입 신호를 결정한다. 일반 MACD 전략과 비교하면, 더 명확한 트렌드 식별을 위해 약간의 잡음을 필터한다. 매개 변수 최적화, 스톱 로스 및 콤보 지표의 추가 향상으로 안정성과 수익성이 향상될 수 있다.


/*backtest
start: 2023-11-18 00:00:00
end: 2023-12-18 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
strategy("MACD ASHI BARS .v1 ", overlay=false,default_qty_type = strategy.percent_of_equity, default_qty_value = 100,commission_type=strategy.commission.percent,commission_value=0.1,slippage=1)

// Calculation HA Values 
haopen  = 0.0
haclose = (open + high + low + close) / 4
haopen := na(haopen[1]) ? (open + close) / 2 : (haopen[1] + haclose[1]) / 2
hahigh  = max(high, max(haopen, haclose))
halow   = min(low,  min(haopen, haclose))

// HA colors
hacolor = haclose > haopen ? color.green : color.red
src=haclose



fastmacd = input(12,title='MACD Fast  Line Length')
slowmacd = input(26,title='MACD Slow Line Length')
signalmacd = input(9,title='Signal Line Length')

macdslowline1 = sma(src,slowmacd)
macdslowline2 = sma(macdslowline1,slowmacd)
DEMAslow = ((2 * macdslowline1) - macdslowline2 )

macdfastline1 = sma(src,fastmacd)
macdfastline2 = sma(macdfastline1,fastmacd)
DEMAfast = ((2 * macdfastline1) - macdfastline2)

MACDLine = (DEMAfast - DEMAslow)

SignalLine = sma(MACDLine, signalmacd)

delta = MACDLine-SignalLine




swap1 = delta>0?color.green:color.red



plot(delta,color=swap1,style=plot.style_columns,title='Histo',histbase=0,transp=20)
p1 = plot(MACDLine,color=color.blue,title='MACD Line')
p2 = plot(SignalLine,color=color.red,title='Signal')
fill(p1, p2, color=color.blue)
hline(0)



yearfrom = input(2020)
yearuntil =input(2042)
monthfrom =input(1)
monthuntil =input(12)
dayfrom=input(1)
dayuntil=input(31)







if ( crossover(delta,0)  and   year >= yearfrom and year <= yearuntil and month>=monthfrom and month <=monthuntil and dayofmonth>=dayfrom and dayofmonth < dayuntil) 
    strategy.entry("MMAL", strategy.long, stop=close, oca_name="TREND",  comment="AL")
    
else
    strategy.cancel(id="MMAL")


if (  crossunder(delta,0) and  year >= yearfrom and year <= yearuntil and month>=monthfrom and month <=monthuntil and dayofmonth>=dayfrom and dayofmonth < dayuntil ) 

    strategy.entry("MMSAT", strategy.short,stop=close, oca_name="TREND",  comment="SAT")
else
    strategy.cancel(id="MMSAT")
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    


더 많은