양적 동력 트렌드 거래 전략

저자:차오장, 날짜: 2023-09-14 20:38:49
태그:

이 문서에서는 동력 트렌드 분석을 기반으로 한 양적 거래 전략을 자세히 설명합니다. 이동 평균, MACD 및 RSI와 같은 지표를 합성하여 가격 동력을 파악하고 중장기 트렌드 기회를 포착합니다.

I. 전략 논리

주요 판단 지표는 다음과 같습니다.

  1. EMA는 다양한 기간에 걸쳐 동향을 측정합니다.

  2. MACD가 단기 동력 변화를 감지합니다.

  3. RSI는 과잉 구매/ 과잉 판매 수준을 확인합니다.

  4. 스톱 로스 및 이윤 취득 계산을 위한 ATR

이 지표들을 결합하여 무역 진출의 경향의 시작을 알리는 지속적이고 강한 파장을 식별합니다.

단기 EMA가 자주 변동할 때, 시장은 범위로 판단됩니다. 장기 EMA가 깨지면 거래가 수행됩니다.

MACD는 추진력의 강도를 판단하고, RSI는 상위와 하위 추격을 피합니다. ATR은 거래당 스톱 로스를 설정하고, 수익을 취하여 위험을 제어합니다.

II. 전략의 장점

가장 큰 장점은 중장기 동향의 시작을 효과적으로 식별 할 수있는 지표의 상호 보완성입니다.

또 다른 장점은 트렌드 수익을 차단하고 위험을 관리하는 스톱 로스 및 리프트를 취하는 것입니다.

마지막으로, 단계적 EMA 기간은 다른 추진력 수준에서 부드러운 트렌드 엔트리를 허용합니다.

III. 잠재적 위험

그러나 이 전략은 다음과 같은 위험을 가지고 있습니다.

첫째, 추세 탐지가 지연되어 놓친 기회로 이어질 수 있습니다.

둘째, 너무 단단하게 정지하면 조기에 정지될 위험이 있습니다.

마지막으로, 마감 압박은 심리적 준비가 필요합니다.

IV. 요약

요약하자면, 이 기사는 동력 트렌드 분석을 기반으로 한 양적 전략을 설명했습니다. 트렌드 방향을 결정하기 위해 이동 평균, MACD 및 RSI와 같은 지표를 합성합니다. 적절한 매개 변수 조정으로 위험을 제어하고 안정적인 이익을 얻을 수 있습니다. 그러나 지표 지연과 같은 위험은 주의해야합니다.


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

//@version=3
strategy("QuantCat Mom Finder Strateg (1H)", overlay=true)

//Series to sum the amount of crosses in EMA for sideways trend/noise filtering
//can change EMA lengths, can change to SMA's/WMA's e.t.c

lookback_value = 60
minMA = 20
midMA = 40
maxMA = 60

ema25_crossover = (crossover(close, ema(close, minMA))) == true ? 1 : 0
ema25_crossover_sum = sum(ema25_crossover, lookback_value) ///potentially change lookback value to alter results

ema50_crossover = (crossover(close, ema(close, midMA))) == true ? 1 : 0
ema50_crossover_sum = sum(ema50_crossover, lookback_value) ///potentially change lookback value to alter results

ema75_crossover = (crossover(close, ema(close, maxMA))) == true ? 1 : 0
ema75_crossover_sum = sum(ema75_crossover, lookback_value) ///potentially change lookback value to alter results

ema25_crossunder = (crossunder(close, ema(close, minMA))) == true ? 1 : 0
ema25_crossunder_sum = sum(ema25_crossunder, lookback_value) ///potentially change lookback value to alter results

ema50_crossunder = (crossunder(close, ema(close, midMA))) == true ? 1 : 0
ema50_crossunder_sum = sum(ema50_crossunder, lookback_value) ///potentially change lookback value to alter results

ema75_crossunder = (crossunder(close, ema(close, maxMA))) == true ? 1 : 0
ema75_crossunder_sum = sum(ema75_crossunder, lookback_value) ///potentially change lookback value to alter results4


//Boolean series declaration
//can change amount of times crossed over the EMA verification to stop sideways trend filtering (3)

maxNoCross=2

macdmidlinebull=-0.5
macdmidlinebear=0.5
[macdLine, signalLine, histLine] = macd(close, 12, 26, 9)

//---------------
//Series Creation

bullishMacd = (macdLine > signalLine) and (macdLine > macdmidlinebull) ? true : false

bearishMacd = (macdLine < signalLine) and (macdLine < macdmidlinebear) ? true : false

bullRsiMin = 50 //53 initial values
bullRsiMax = 60 //61
bearRsiMin = 40 //39
bearRsiMax = 50 //47

basicBullCross25bool = ((ema25_crossover_sum < ema50_crossover_sum) 
     and (ema25_crossover_sum < ema75_crossover_sum) 
     and (ema25_crossover_sum < maxNoCross) 
     and crossover(close, ema(close, minMA)) and (rsi(close, 14) > bullRsiMin)
     and (rsi(close, 14) < bullRsiMax) and (bullishMacd == true)) ? true : false
  
basicBullCross50bool = ((ema50_crossover_sum < ema25_crossover_sum) 
     and (ema50_crossover_sum < ema75_crossover_sum) 
     and (ema50_crossover_sum < maxNoCross) 
     and crossover(close, ema(close, midMA)) and (rsi(close, 14) > bullRsiMin)
     and (basicBullCross25bool == false) 
     and (rsi(close, 14) < bullRsiMax) and (bullishMacd == true)) ? true : false
  
basicBullCross75bool = ((ema75_crossover_sum < ema25_crossover_sum) 
     and (ema75_crossover_sum < ema50_crossover_sum) 
     and (ema75_crossover_sum < maxNoCross) 
     and crossover(close, ema(close, maxMA)) and (rsi(close, 14) > bullRsiMin)
     and (basicBullCross25bool == false) and (basicBullCross50bool == false)
     and (rsi(close, 14) < bullRsiMax) and (bullishMacd == true)) ? true : false
     
basicBearCross25bool = ((ema25_crossunder_sum < ema50_crossunder_sum) 
     and (ema25_crossunder_sum < ema75_crossunder_sum) 
     and (ema25_crossunder_sum < maxNoCross) 
     and crossunder(close, ema(close, minMA)) and (rsi(close, 14) <bearRsiMax)
     and (rsi(close, 14) > bearRsiMin) and (bearishMacd == true)) ? true : false
  
basicBearCross50bool = ((ema50_crossunder_sum < ema25_crossunder_sum) 
     and (ema50_crossunder_sum < ema75_crossover_sum) 
     and (ema50_crossunder_sum < maxNoCross) 
     and crossunder(close, ema(close, midMA)) and (rsi(close, 14) < bearRsiMax)
     and (basicBearCross25bool == false) 
     and (rsi(close, 14) > bearRsiMin) and (bearishMacd == true)) ? true : false
  
basicBearCross75bool = ((ema75_crossunder_sum < ema25_crossunder_sum) 
     and (ema75_crossunder_sum < ema50_crossunder_sum) 
     and (ema75_crossunder_sum < maxNoCross) 
     and crossunder(close, ema(close, maxMA)) and (rsi(close, 14) < bearRsiMax)
     and (basicBearCross25bool == false) and (basicBearCross50bool == false)
     and (rsi(close, 14) > bearRsiMin) and (bearishMacd == true)) ? true : false

//STRATEGY
//can change lookback input on ATR

atrLkb = input(14, minval=1, title='ATR Stop Period')
atrRes = input("D",  title='ATR Resolution')
atr = security(syminfo.tickerid, atrRes, atr(atrLkb))


longCondition = (basicBullCross25bool or basicBullCross50bool or basicBullCross75bool) == true
if (longCondition)
    strategy.entry("Long", strategy.long)

shortCondition = (basicBearCross25bool or basicBearCross50bool or basicBearCross75bool) == true
if (shortCondition)
    strategy.entry("Short", strategy.short)
    
   
// Calc ATR Stops
// can change atr multiplier to affect stop distance/tp distance, and change "close" to ema values- could try ema 50

stopMult = 0.6 //0.6 is optimal

longStop = na
longStop :=  shortCondition ? na : longCondition and strategy.position_size <=0 ? close - (atr * stopMult) : longStop[1] 
shortStop = na
shortStop := longCondition ? na : shortCondition and strategy.position_size >=0 ? close + (atr * stopMult) : shortStop[1]

//Calc ATR Target

targetMult = 2.2 //2.2 is optimal for crypto x/btc pairs

longTarget = na
longTarget :=  shortCondition ? na : longCondition and strategy.position_size <=0 ? close + (atr*targetMult) : longTarget[1]
shortTarget = na
shortTarget := longCondition ? na : shortCondition and strategy.position_size >=0 ? close - (atr*targetMult) : shortTarget[1]

// Place the exits

strategy.exit("Long ATR Stop", "Long", stop=longStop, limit=longTarget)
strategy.exit("Short ATR Stop", "Short", stop=shortStop, limit=shortTarget)

//Bar color series

longColour = longCondition ? lime : na
shortColour = shortCondition ? red : na
    
// Plot the stoplosses and targets

plot(longStop, style=linebr, color=red, linewidth=2,     title='Long ATR Stop')
plot(shortStop, style=linebr, color=red, linewidth=2,  title='Short ATR Stop')
plot(longTarget, style=linebr, linewidth=2, color=lime,  title='Long ATR Target')
plot(shortTarget, linewidth=2, style=linebr, color=lime,  title='Long ATR Target')

barcolor(color=longColour)
barcolor(color=shortColour)

alertcondition(((basicBullCross25bool or basicBullCross50bool or basicBullCross75bool)==true), title='Long Entry', message='Bullish Momentum Change!')
alertcondition(((basicBearCross25bool or basicBearCross50bool or basicBearCross75bool)==true), title='Short Entry', message='Bearish Momentum Change!')

더 많은