Intraday 전략에 따른 MACD 트렌드

저자:차오장, 날짜: 2023-12-19 11:16:44
태그:

img

전반적인 설명

MACD 트렌드 포워딩 인트라데이 전략은 이동 평균, MACD 지표 및 윌리엄스 지표를 결합한 인트라데이 거래 전략이다. 단기 가격 움직임의 트렌드 특성을 파악하는 것을 목표로 긴 및 짧은 포지션에 대한 입출 기준을 형성하기 위해 세 가지 지표의 다른 조합을 사용합니다.

전략 논리

이 전략의 주요 거래 논리는 몇 가지 측면에 기반합니다.

  1. 가격이 기하급수적 이동 평균 (EMA) 라인을 넘어서면 장거리, 그 아래로 넘어가면 단거리

  2. MACD 빠른 라인이 느린 라인 위에 있을 때 긴 라인, 아래가 되면 짧은 라인.

  3. 윌리엄 지표의 빠른 MA 라인이 느린 MA 라인의 위에 있을 때 길게 이동하고, 그 반대의 경우

  4. 이 세 가지 시나리오의 조합을 입시 조건으로 사용하십시오.

  5. 역전 신호로 출구

전반적인 트렌드 방향과 MACD를 단기 추진력으로 결합함으로써, 이 전략은 수익을 위한 괜찮은 입구 지점에서의 가격 트렌드 움직임을 포착할 수 있다. 윌리엄스 지표는 또한 과잉 구매/ 과잉 판매 수준을 측정함으로써 잘못된 브레이크오프를 피하는 데 도움이 된다.

장점

이 다중 지표 조합 구조는 다음과 같은 주요 가장자리로 전형적인 단기 트렌드를 전략에 따라 만듭니다.

  1. 거짓 신호를 줄이기 위해 세차 교차 검증

  2. 주요 트렌드를 나타내는 EMA, 단기 동력을 나타내는 MACD

  3. 윌리엄스 지표는 휘발성 이동 중에 상단이나 바닥 낚시를 피합니다.

  4. 리버스 콤보는 위험 통제가 출구와 일치하도록 보장합니다.

위험성

이 전략에는 다음과 같은 큰 위험이 있습니다.

  1. 복잡한 구조로 매개 변수를 조정하는 것은 어려운 일입니다.

  2. 빈번한 단기 거래는 더 높은 거래 비용을 초래할 수 있습니다.

  3. 진정한 트렌드 반전 포인트를 감지하지 못하면 손실이 발생할 수 있습니다.

주요 완화 방법은 매개 변수 최적화와 스톱 로스입니다. 이윤 조합을 극대화하고 최대 단일 거래 손실을 제어하기 위해서입니다.

더 나은 기회

전략 강화의 주요 측면:

  1. 최적의 세트를 위해 더 많은 매개 변수 조합을 테스트합니다.

  2. 입력 검증을 위해 볼륨과 같은 더 많은 데이터 피드를 추가합니다.

  3. 리스크 통제를 강화하기 위해 동적 또는 후속 스톱 로스를 사용해야 합니다.

  4. 진정한 역전을 감지하기 위해 기계 학습을 통합합니다.

결론

이 내일 전략을 따르는 MACD 추세는 단기 트렌드를 식별하고 위험을 관리하기위한 지표를 효과적으로 결합합니다. 조정 매개 변수에 대한 추가 개선, 스톱 로스 수준을 설정하고 더 많은 데이터 피드를 통합하면 전략 승률과 수익성을 높일 수 있습니다. 개념은 전략 발전을 위해 연구 할 가치가 있습니다.


/*backtest
start: 2023-11-18 00:00:00
end: 2023-12-18 00:00:00
period: 1h
basePeriod: 15m
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/
// © platsn

//@version=5
strategy("MACD Willy Strategy", overlay=true, pyramiding=1, initial_capital=10000) 

// ******************** Trade Period **************************************
startY = input(title='Start Year', defval=2011, group = "Trading window")
startM = input.int(title='Start Month', defval=1, minval=1, maxval=12, group = "Trading window")
startD = input.int(title='Start Day', defval=1, minval=1, maxval=31, group = "Trading window")
finishY = input(title='Finish Year', defval=2050, group = "Trading window")
finishM = input.int(title='Finish Month', defval=12, minval=1, maxval=12, group = "Trading window")
finishD = input.int(title='Finish Day', defval=31, minval=1, maxval=31, group = "Trading window")
timestart = timestamp(startY, startM, startD, 00, 00)
timefinish = timestamp(finishY, finishM, finishD, 23, 59)
// t1 = time(timeframe.period, "0945-1545:23456") 
// window = time >= timestart and time <= timefinish and t1 ? true : false 
// t2 = time(timeframe.period, "0930-1555:23456")
// window2 = time >= timestart and time <= timefinish and t2 ? true : false 

leverage = input.float(1, title="Leverage (if applicable)", step=0.1, group = "Trading Options")
reinvest = input.bool(defval=false,title="Reinvest profit", group = "Trading Options")
reinvest_percent = input.float(defval=20, title = "Reinvest percentage", group="Trading Options")
// entry_lookback = input.int(defval=10, title="Lookback period for entry condition", group = "Trading Options")

// -------------------------------------------- Data Source --------------------------------------------

src = input(title="Source", defval=close)

// ***************************************************************************************************** Daily ATR *****************************************************
atrlen = input.int(14, minval=1, title="ATR period", group = "Daily ATR")
iPercent = input.float(5, minval=1, maxval=100, step=0.1, title="% ATR to use for SL / PT", group = "Daily ATR")
 
percentage = iPercent * 0.01
datr = request.security(syminfo.tickerid, "1D", ta.rma(ta.tr, atrlen))
datrp = datr * percentage

// plot(datr,"Daily ATR")
// plot(datrp, "Daily % ATR")

//*********************************************************** VIX volatility index ****************************************

VIX = request.security("BTC_USDT:swap", timeframe.period, close)
vix_thres = input.float(20.0, "VIX Threshold for entry", step=0.5, group="VIX Volatility Index")

// ************************************************ Volume ******************************************************

vol_len = input(50, 'Volume MA Period')
avg_vol = ta.sma(volume, vol_len)

//-------------------------------------------------------- Moving Average ------------------------------------

emalen1 = input.int(200, minval=1, title='EMA', group= "Moving Averages")
ema1 = ta.ema(src, emalen1)

// ------------------------------------------ MACD ------------------------------------------
// Getting inputs
fast_length = input(title="Fast Length", defval=12)
slow_length = input(title="Slow Length", defval=26)
signal_length = input.int(title="Signal Smoothing",  minval = 1, maxval = 50, defval = 9)
sma_source = input.string(title="Oscillator MA Type",  defval="EMA", options=["SMA", "EMA"])
sma_signal = input.string(title="Signal Line MA Type", defval="EMA", options=["SMA", "EMA"])
// Plot colors
col_macd = input(#2962FF, "MACD Line  ", group="Color Settings", inline="MACD")
col_signal = input(#FF6D00, "Signal Line  ", group="Color Settings", inline="Signal")
col_grow_above = input(#26A69A, "Above   Grow", group="Histogram", inline="Above")
col_fall_above = input(#B2DFDB, "Fall", group="Histogram", inline="Above")
col_grow_below = input(#FFCDD2, "Below Grow", group="Histogram", inline="Below")
col_fall_below = input(#FF5252, "Fall", group="Histogram", inline="Below")
// Calculating
fast_ma = sma_source == "SMA" ? ta.sma(src, fast_length) : ta.ema(src, fast_length)
slow_ma = sma_source == "SMA" ? ta.sma(src, slow_length) : ta.ema(src, slow_length)
macd = fast_ma - slow_ma
signal = sma_signal == "SMA" ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length)
hist = macd - signal

// ---------------------------------------- William %R --------------------------------------
w_length = input.int(defval=34, minval=1)
w_upper = ta.highest(w_length)
w_lower = ta.lowest(w_length)

w_output = 100 * (close - w_upper) / (w_upper - w_lower)

fast_period = input(defval=5, title='Smoothed %R Length')
slow_period = input(defval=13, title='Slow EMA Length')

w_fast_ma = ta.wma(w_output,fast_period)
w_slow_ma = ta.ema(w_output,slow_period)



// ------------------------------------------------ Entry Conditions ----------------------------------------

L_entry1 = close > ema1 and hist > 0 and w_fast_ma > w_slow_ma 
S_entry1 = close < ema1 and hist < 0 and w_fast_ma < w_slow_ma 

// -------------------------------------------------- Entry -----------------------------------------------
strategy.initial_capital = 50000
profit = strategy.netprofit
trade_amount = math.floor(strategy.initial_capital*leverage / close) 

if strategy.netprofit > 0 and reinvest
    trade_amount := math.floor((strategy.initial_capital+(profit*reinvest_percent*0.01))*leverage / close) 
else
    trade_amount := math.floor(strategy.initial_capital*leverage/ close) 


if L_entry1 //and window
    strategy.entry("Long", strategy.long, trade_amount)

if S_entry1 //and window
    strategy.entry("Short", strategy.short, trade_amount)

// --------------------------------------------------- Exit Conditions -------------------------------------

L_exit1 = hist < 0 and w_fast_ma < w_slow_ma and w_fast_ma < -20
S_exit1 = hist > 0 and w_fast_ma > w_slow_ma and w_fast_ma > -80

// ----------------------------------------------------- Exit ---------------------------------------------

if L_exit1 //and window2
    strategy.close("Long")
    
if S_exit1 //and window2
    strategy.close("Short")

// if time(timeframe.period, "1530-1600:23456")
//     strategy.close_all()

더 많은