PSAR, MACD 및 RSI를 기반으로 한 다중 시간 프레임 양적 거래 전략

저자:차오장, 날짜: 2023-12-27 16:12:57
태그:

img

전반적인 설명

이 전략은 Parabolic SAR, MACD 및 RSI 지표를 결합하여 여러 시간 프레임에 걸쳐 자동화 된 긴 및 짧은 거래를 구현합니다. 주식 및 원자재 제품의 내일 거래에 주로 적합합니다.

전략 원칙

  1. PSAR 지표는 가격 방향 및 트렌드 반전 지점을 결정하는 데 사용됩니다. 떨어지는 점들은 상승하는 점들이 하락하는 신호이며, 떨어지는 점들은 상승하는 점입니다.

  2. MACD 지표는 가격 동력을 판단합니다. MACD 라인이 SIGNAL 라인 위에 상향으로 넘어가면 상승 신호이며, 하향으로 넘어가면 하락 신호입니다.

  3. RSI 지표는 과잉 구매 및 과잉 판매 조건을 판단합니다. 임계 이상의 RSI는 상승하고 아래는 하락합니다.

  4. 위의 세 가지 지표의 신호를 결합하여 최종 장기/단기 결정을 만듭니다.

  5. 적응적으로 Chop Index 지표를 사용 하 여 융합 시장을 필터링 하 고 을 피 하기 위해.

  6. 리버스 피라미드 포지션 사이징을 사용하여 위험 및 수익 목표를 동적으로 관리합니다.

장점

  1. 트렌드, 모멘텀 및 오시레이터를 판단하는 여러 지표의 조합은 정확성을 향상시킵니다.

  2. 시장 조건에 적응하여 융합 시장을 필터링하여 함정에 빠지지 않도록 합니다.

  3. 역 피라미드 포지션 사이징을 통해 역동적인 위험 및 이익 관리를 통해 적응적 인 중지 및 제한.

  4. 다양한 제품과 시장 환경에 맞게 조정 가능한 매개 변수와 함께 매우 사용자 정의 가능합니다.

  5. 여러 시간 프레임을 지원하고, 단기 내일 또는 중장기 포지셔널 거래를 위해 유연합니다.

위험 분석

  1. 긴/단결 결정은 부적절한 경우 오류를 일으킬 수 있는 매개 변수 설정에 달려 있습니다.

  2. 추세에 반대되는 결정을 이끌어내는 잘못된 신호의 가능성.

  3. 부적절한 스톱 로스 설정과 수익 취득 설정은 손실을 증가시키거나 이익을 줄일 수 있습니다.

  4. 빈번한 모니터링과 매개 변수 조정이 필요해서 인적 개입 비용이 높습니다.

최적화 방향

  1. 매개 변수 설정 및 신호 효율을 평가하기 위해 모델 검증 모듈을 추가합니다.

  2. 자동 매개 변수 및 모델 최적화를 위한 기계 학습 모듈을 늘려

  3. 더 많은 데이터 소스를 섭취하여 기능 공간을 풍부하게 만들고 결정을 개선합니다.

  4. 인간의 개입을 줄이기 위해 자동화된 모니터링 및 유지보수 시스템을 개발합니다.

  5. 역 테스트와 시뮬레이션 평가를 추가하여 전략 성능을 검증합니다.

결론

이 전략은 여러 기술적 지표 규칙 기반 시스템을 결합하여 자동화 된 양적 거래를 실현합니다. 큰 최적화 공간과 유연성으로 라이브 트레이딩에 더 잘 서비스를 제공하기 위해 매개 변수 조정, 기능 확장 및 기계 학습 개선에 적합합니다.


/*backtest
start: 2022-12-20 00:00:00
end: 2023-12-26 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © vikris

//@version=4
strategy("[VJ]Phoenix Force of PSAR +MACD +RSI", overlay=true, calc_on_every_tick = false,pyramiding=0)

// ********** Strategy inputs - Start **********

// Used for intraday handling
// Session value should be from market start to the time you want to square-off 
// your intraday strategy
// Important: The end time should be at least 2 minutes before the intraday
// square-off time set by your broker
var i_marketSession = input(title="Market session", type=input.session, 
     defval="0915-1455", confirm=true)

// Make inputs that set the take profit % (optional)
longProfitPerc = input(title="Long Take Profit (%)",
     type=input.float, minval=0.0, step=0.1, defval=3) * 0.01

shortProfitPerc = input(title="Short Take Profit (%)",
     type=input.float, minval=0.0, step=0.1, defval=3) * 0.01
     
// Set stop loss level with input options (optional)
longLossPerc = input(title="Long Stop Loss (%)",
     type=input.float, minval=0.0, step=0.1, defval=3) * 0.01

shortLossPerc = input(title="Short Stop Loss (%)",
     type=input.float, minval=0.0, step=0.1, defval=3) * 0.01    


// ********** Strategy inputs - End **********


// ********** Supporting functions - Start **********

// A function to check whether the bar or period is in intraday session
barInSession(sess) => time(timeframe.period, sess) != 0



// Figure out take profit price
longExitPrice  = strategy.position_avg_price * (1 + longProfitPerc)
shortExitPrice = strategy.position_avg_price * (1 - shortProfitPerc)

// Determine stop loss price
longStopPrice  = strategy.position_avg_price * (1 - longLossPerc)
shortStopPrice = strategy.position_avg_price * (1 + shortLossPerc)


// ********** Supporting functions - End **********


// ********** Strategy - Start **********
// See if intraday session is active
bool intradaySession = barInSession(i_marketSession)

// Trade only if intraday session is active

//=================Strategy logic goes in here===========================
 
psar = sar(0.02,0.02,0.2)
c1a = close > psar
c1v = close < psar

malen = input(50, title="MA Length")
mm200 = sma(close, malen)
c2a = close > mm200
c2v = close < mm200

fast = input(12, title="MACD Fast EMA Length")
slow = input(26, title="MACD Slow EMA Length")
[macd,signal,hist] = macd(close, fast,slow, 9)
c3a = macd >= 0
c3v = macd <= 0

rsilen = input(7, title="RSI Length")
th = input(50, title="RSI Threshold")
rsi14 = rsi(close, rsilen)
c4a = rsi14 >= th
c4v = rsi14 <= th

chopi = input(7, title="Chop Index lenght")
ci = 100 * log10(sum(atr(1), chopi) / (highest(chopi) - lowest(chopi))) / log10(chopi)

buy = c1a and c2a and c3a and c4a ? 1 : 0
sell = c1v and c2v and c3v and c4v ? -1 : 0


//Final Long/Short Condition
longCondition = buy==1 and ci <50
shortCondition = sell==-1 and ci <50 
 
//Long Strategy - buy condition and exits with Take profit and SL
if (longCondition and intradaySession)
    stop_level = longStopPrice
    profit_level = longExitPrice
    strategy.entry("My Long Entry Id", strategy.long)
    strategy.exit("TP/SL", "My Long Entry Id", stop=stop_level, limit=profit_level)


//Short Strategy - sell condition and exits with Take profit and SL
if (shortCondition and intradaySession)
    stop_level = shortStopPrice
    profit_level = shortExitPrice
    strategy.entry("My Short Entry Id", strategy.short)
    strategy.exit("TP/SL", "My Short Entry Id", stop=stop_level, limit=profit_level)
 
 
// Square-off position (when session is over and position is open)
squareOff = (not intradaySession) and (strategy.position_size != 0)
strategy.close_all(when = squareOff, comment = "Square-off")

// ********** Strategy - End **********

더 많은