MFI 및 MA 기반의 양적 역전 전략

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

img

전반적인 설명

이 전략은 MFI 지표를 활용하여 과잉 구매 및 과잉 판매 구역을 식별하고 MA와 결합하여 가격 반전 방향을 필터합니다. 주식, 외화, 상품 및 암호화 시장에서 잘 작동합니다.

전략 논리

이 전략은 시장에서 과잉 구매 및 과잉 판매 상황을 측정하기 위해 MFI 지표를 활용합니다. MFI가 과잉 판매 구역에 20 이하로 떨어지면 자산이 과부가가치되고 바닥이 형성되고 있음을 신호합니다. MFI가 과부가가치 영역에 80 이상 상승하면 자산이 과부가가치되어 있으며 곧 더 낮게 수정 될 가능성이 있으며 짧은 신호를 유발합니다.

거짓 반전을 피하기 위해 전략은 또한 MA 지표를 사용하여 트렌드 방향을 결정합니다. 거래 신호는 MFI 반전이 가격 경류 또는 MA 라인 이상으로 정렬 될 때만 생성됩니다.

구체적인 거래 논리는 다음과 같습니다.

  1. MFI가 20 이하로 넘어 지나치게 팔린 영역으로 들어가 마이너스 마이너스 라인을 넘어서 마이너스 마이너스 마이너스 라인을 닫으면 구매 신호가 생성됩니다.

  2. MFI가 80을 넘어서서 과잉 매입 구역으로 넘어갔고, 마이너스 마이너스 라인을 넘어서면 판매 신호가 발사됩니다.

이중 지표 확인을 통해 전략은 신뢰할 수 있는 입시 신호를 통해 반전 기회를 효과적으로 식별 할 수 있습니다.

장점

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

더 많은