MFI와 MA를 기반으로 한 양적 역전 전략


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

MFI와 MA를 기반으로 한 양적 역전 전략

개요

이 전략은 MFI 지표를 사용하여 과매매 지역을 식별하고 MA 필터링과 결합하여 가격 역향 방향을 판단하는 단선 거래 전략이다. 주식, 외환, 상품 및 암호화폐와 같은 시장에서 효과적일 수 있다.

전략 원칙

전략은 MFI 지표를 사용하여 시장의 과매매 현상을 판단한다. MFI가 20 이하의 과매매 영역에 진입했을 때, 하위 영역을 나타내고, 가치가 과소평가되어, 부진을 나타냅니다. MFI가 80 이상의 과매매 영역에 진입했을 때, 상위 영역을 나타내고, 자산이 과대평가되어, 부진을 나타냅니다.

가짜 반전을 필터하기 위해, 전략은 MA 지표가 가격 트렌드 방향을 판단하는 것도 도입했다. MFI 반전이 동시에, 가격이 MA 평균선 위에 서거나 아래로 떨어질 때만 거래 신호를 생성한다.

거래 논리는 다음과 같습니다.

  1. MFI가 20 이하를 넘어서 초매구역에 진입하면서 마이너스 마이너스 (MA) 평균선에서 매수 신호를 발생시킨다.
  2. MFI 상반기 80을 넘어서서 초고가구에 진입했고, 마이너스 마이너스 (MA) 를 넘어서 매각 신호를 내놓았다.

이렇게 하면, 이중 지표 필터링을 통해 역전 기회를 효과적으로 식별할 수 있으며, 진출 신호는 더 신뢰할 수 있다.

전략적 이점

  1. 이중 지표 확인, 가짜 돌파를 방지, 신호 신뢰도 높다
  2. 오버 바이 오버 셀 영역 반전을 이용하는 것은 고전적이고 효과적인 거래 기술입니다.
  3. 트렌드 필터링과 결합하여 신호를 더 정확하고 신뢰할 수 있도록 합니다.
  4. 다양한 시장에 적용 가능하고, 유연하다

전략적 위험

  1. 시장이 장기적으로 상승하거나 하락할 수 있으며, 이로 인해 손실이 발생할 수 있습니다.
  2. 시스템적 위험에 주의를 기울여 극단적인 상황이 잘못된 전환점을 가져오지 않도록 해야 합니다.
  3. 거래 빈도가 높을 수 있으며, 거래 비용 통제에 주의해야 합니다.

어떻게 대처해야 할까요?

  1. 적절한 휴식 범위, 전략에 더 많은 여유
  2. 포지션을 확대할 때 더 큰 차트에 주의를 기울여 시스템적 위험을 판단하십시오.
  3. 최적화 매개 변수, 무의미한 거래 감소

전략 최적화 방향

  1. 거래 품종 특성에 맞는 MA 변수를 최적화
  2. 오버 구매 오버 판매 매개 변수를 최적화하여 다양한 시장 정서에 적응합니다.
  3. 수익을 통제할 수 있는 포지션 관리 장치를 추가합니다.

요약하다

이 전략은 고전적인 분석 방법과 현대적인 양적 기술을 통합하여 엄격한 이중 지표 필터링을 통해 다양한 품종에서 강력한 적응력을 보여주며, 추천할 만한 일반 단선 전략이다.

전략 소스 코드
/*backtest
start: 2023-12-19 00:00:00
end: 2023-12-26 00:00:00
period: 1m
basePeriod: 1m
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]Thor for MFI", 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=1) * 0.01

shortProfitPerc = input(title="Short Take Profit (%)",
     type=input.float, minval=0.0, step=0.1, defval=1) * 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=0.5) * 0.01

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

i_MFI = input(3, title="MFI Length")
OB=input(100, title="Overbought Level")
OS=input(0, title="Oversold Level")
barsizeThreshold=input(.5, step=.05, minval=.1, maxval=1, title="Bar Body Size, 1=No Wicks")
i_MAFilter = input(true, title="Use MA Trend Filter")
i_MALen = input(80, title="MA Length")
// ********** 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 = true

// Trade only if intraday session is active

//=================Strategy logic goes in here===========================
 

MFI=mfi(close,i_MFI)
barsize=high-low
barbodysize=close>open?(open-close)*-1:(open-close)
shortwicksbar=barbodysize>barsize*barsizeThreshold
SMA=sma(close, i_MALen)
MAFilter=close > SMA



BUY = MFI[1] == OB and close > open and shortwicksbar and (i_MAFilter ? MAFilter : true)

SELL = MFI[1] == OS and close < open and shortwicksbar and (i_MAFilter ? not MAFilter : true) 

//Final Long/Short Condition
longCondition = BUY
shortCondition = SELL
 
//Long Strategy - buy condition and exits with Take profit and SL
if (longCondition and intradaySession)
    stop_level = longStopPrice
    profit_level = longExitPrice
    strategy.entry("Buy", strategy.long)
    strategy.exit("TP/SL", "Buy", 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("Sell", strategy.short)
    strategy.exit("TP/SL", "Sell", 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 **********