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


생성 날짜: 2023-12-27 16:12:57 마지막으로 수정됨: 2023-12-27 16:12:57
복사: 0 클릭수: 657
avatar of ChaoZhang ChaoZhang
1
집중하다
1623
수행원

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

개요

이 전략은 Parabolic SAR, MACD, 그리고 RSI의 세 가지 지표를 조합하여 여러 시간 프레임에 걸쳐 자동화된 다중 헤드 거래를 구현합니다. 이 전략은 주식 및 상품 품종의 일일 거래에 주로 적용됩니다.

전략 원칙

  1. PSAR 지표는 가격 방향과 트렌드 반전 지점을 판단하는 데 사용됩니다. 점수가 내려갈 때 다목 신호, 점수가 올라갈 때 공수 신호입니다.

  2. MACD 지표는 가격 움직임을 판단한다. MACD 라인과 SIGNAL 라인이 상향으로 돌파하면 다중 신호이며, 하향으로 돌파하면 공백 신호이다.

  3. RSI 지표는 과매매 현상을 판단한다. RSI가 경량보다 높으면 다면 신호이며, 경량보다 낮으면 공백 신호이다.

  4. 위 세 가지 지표의 신호를 종합하여 최종 다공개 결정을 내립니다.

  5. 자율적으로 CHOP 인덱스를 사용하여 통합 시장을 필터링하여 whipsaws를 피하십시오.

  6. 리버스 피라미드 (reverse pyramid) 가치의 원칙을 적용하여 스톱로스 (stop loss) 와 스톱 포스트 (stop stop) 를 설정하여 위험과 수익을 동적으로 관리한다.

전략적 이점

  1. 다중 지표 포지션은 트렌드, 동력, 과매매 특성을 종합적으로 판단하여 의사 결정의 정확성을 향상시킵니다.

  2. 시장의 특성에 적응하고, CHOP Index 지표 필터링을 통해 시장의 통합을 방지합니다.

  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 **********