이치모쿠 클라우드, MACD 및 스토카스틱 기반의 멀티 타임프레임 트렌드 추적 전략

저자:차오장, 날짜: 2024-02-05 10:30:45
태그:

img

전반적인 설명

이 전략은 이치모쿠 클라우드, 이동평균, MACD, 스토카스틱 및 ATR 지표를 통합하여 여러 시간 프레임에서 트렌드를 식별하고 추적합니다. ATR 기반의 스톱 로스를 채택하고 높은 확률 트렌드 신호를 얻은 후 리스크 통제를 위해 수익 방법을 사용합니다.

전략 논리

  1. 이치모쿠 클라우드는 중장기 트렌드 방향을 판단합니다. 이치모쿠의 전환선과 기준선 위의 CLOSE 가격이 상승 신호이며, 그 아래를 넘는 것은 하락 신호입니다.

  2. MACD는 단기 트렌드와 과잉 구매/ 과잉 판매 상황을 판단합니다. MACD 신호 라인의 위를 가로지르는 MACD 히스토그램은 상승 신호이며 아래를 가로지르는 것은 하락 신호입니다.

  3. 스토카스틱 KD는 과잉 구매/ 과잉 판매 구역을 판단합니다. K 라인의 20을 넘는 것은 상승 신호이고, 80을 넘는 것은 하락 신호입니다.

  4. 이동 평균은 중장기 트렌드를 판단합니다. MA 이상의 가격의 닫는 것은 상승 신호이고, 아래로 넘어가는 것은 하락 신호입니다.

  5. 위의 지표의 신호를 통합하여 일부 잘못된 신호를 필터링하여 높은 확률의 지속 가능한 트렌드 신호를 형성합니다.

  6. ATR을 사용하여 스톱 로스 및 취익 가격을 계산합니다. ATR의 특정 배수를 스톱 로스 및 취익 비트로 사용하여 위험을 제어합니다.

장점

  1. 신호의 정확성을 높이기 위해 여러 시간 프레임에 걸쳐 추세를 파악합니다.

  2. 거짓 신호를 효과적으로 필터링하기 위해 표시기 조합을 광범위하게 사용하십시오.

  3. ATR에 기반한 스톱 로스 & 노프트 취득

  4. 입국 조건의 조정 가능한 엄격성은 다양한 위험 욕구를 충족시킵니다.

위험성

  1. 자연을 따르는 경향은 블랙 스완 사건으로 인한 반전을 감지하지 못합니다.

  2. 이상적인 ATR 스톱 로스는 실시간 거래에서 완전히 복제하기 어렵습니다.

  3. 부적절한 매개 변수 설정은 과도한 거래 또는 신호 정확도가 충분하지 않을 수 있습니다.

  4. 다른 제품과 시장 환경에 맞게 매개 변수를 조정하는 것이 필요합니다.

개선 영역

  1. 트렌드 전환점을 판단하는 데 도움이 되는 기계 학습을 도입합니다.

  2. 각기 다른 제품에 대한 ATR 곱셈 매개 변수 값을 최적화합니다.

  3. 돌파 신호의 정확성을 향상시키기 위해 볼륨 변화와 같은 다른 요소를 포함합니다.

  4. 역 테스트 결과를 기반으로 매개 변수를 최적화해 최고의 매개 변수 조합을 찾으세요

요약

이 전략은 이치모쿠 클라우드, MACD, 스토카스틱 등을 활용하여 멀티 타임프레임 트렌드 식별을 통해 트렌드를 포착하고 블랙 스완 이벤트에 함락되는 것을 피합니다. ATR 기반의 스톱 로스 & 트레이프 수익은 거래 손실 당 효과적으로 제한됩니다. 더 많은 보조 판단과 기계 학습 방법이 도입됨에 따라이 전략은 추가 최적화 잠재력을 가지고 있습니다.


/*backtest
start: 2024-01-05 00:00:00
end: 2024-02-04 00:00:00
period: 4h
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/
// © FXFUNDINGMATE

//@version=4
strategy(title="FXFUNDINGMATE TREND INDICATOR", overlay=true)

//Ichimoku Cloud
conversionPeriods = input(9, minval=1, title="Conversion Line Length")
basePeriods = input(26, minval=1, title="Base Line Length")
laggingSpan2Periods = input(52, minval=1, title="Lagging Span 2 Length")
displacement = input(26, minval=1, title="Displacement")
donchian(len) => avg(lowest(len), highest(len))
conversionLine = donchian(conversionPeriods)
baseLine = donchian(basePeriods)
leadLine1 = avg(conversionLine, baseLine)[displacement - 1]
leadLine2 = donchian(laggingSpan2Periods)[displacement - 1]


//macd
fast_length = input(title="Fast Length", type=input.integer, defval=12)
slow_length = input(title="Slow Length", type=input.integer, defval=26)
src = input(title="Source", type=input.source, defval=close)
signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9)
sma_source = input(title="Simple MA (Oscillator)", type=input.bool, defval=false)
sma_signal = input(title="Simple MA (Signal Line)", type=input.bool, defval=false)

fast_ma = sma_source ? sma(src, fast_length) : ema(src, fast_length)
slow_ma = sma_source ? sma(src, slow_length) : ema(src, slow_length)
macd = fast_ma - slow_ma
signal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length)
hist = macd - signal


//kd
periodK = input(5, title="%K Length", minval=1)
smoothK = input(3, title="%K Smoothing", minval=1)
periodD = input(3, title="%D Smoothing", minval=1)
k = sma(stoch(close, high, low, periodK), smoothK)
d = sma(k, periodD)


//atr
atrlength = input(title="Atr Length", defval=8, minval=1)
SMulti = input(title="Stop loss multi Atr", defval=1.0)
TMulti = input(title="Take profit multi Atr", defval=1.0)
smoothing = input(title="Smoothing", defval="RMA", options=["RMA", "SMA", "EMA", "WMA"])
ma_function(source, length) =>
	if smoothing == "RMA"
		rma(source, length)
	else
		if smoothing == "SMA"
			sma(source, length)
		else
			if smoothing == "EMA"
				ema(source, length)
			else
				wma(source, length)
atr = ma_function(tr(true), atrlength)


operation_type = input(defval = "Both", title = "Position side", options = ["Long", "Short", "Both"])
operation = operation_type == "Long" ? 1 : operation_type == "Short" ? 2 : 3
showlines = input(true,  title="Show sl&tp lines")

// MA
sma_len = input(100, title="MA Length", type=input.integer)
sma = sma(close, sma_len)

longCond = crossover(k, 20) and macd > 0 and close > sma and close > leadLine1 and close > leadLine2
shortCond = crossunder(k, 80)  and macd < 0 and close < sma and close < leadLine1 and close < leadLine2

entry_price  = float(0.0) //set float
entry_price := strategy.position_size != 0 or longCond or shortCond ? strategy.position_avg_price : entry_price[1]
entry_atr = valuewhen(longCond or shortCond, atr,0)
short_stop_level     = float(0.0)   //set float
short_profit_level   = float(0.0)   //set float
long_stop_level      = float(0.0)   //set float
long_profit_level    = float(0.0)   //set float
short_stop_level    := entry_price + SMulti * entry_atr
short_profit_level  := entry_price - TMulti * entry_atr
long_stop_level     := entry_price - SMulti * entry_atr
long_profit_level   := entry_price + TMulti * entry_atr


//  Strategy Backtest Limiting Algorithm
i_startTime = input(defval = timestamp("1 Jan 2020 00:00 +0000"), title = "Backtesting Start Time", type = input.time)
i_endTime = input(defval = timestamp("31 Dec 2025 23:59 +0000"), title = "Backtesting End Time", type = input.time)
timeCond = true

if (operation == 1 or operation == 3)
    strategy.entry("long" , strategy.long , when=longCond and timeCond, alert_message = "Long")
    strategy.exit("SL/TP", from_entry = "long" , limit = long_profit_level , stop = long_stop_level , alert_message = "Long exit")

if (operation == 2 or operation == 3)
    strategy.entry("short", strategy.short, when=shortCond and timeCond, alert_message="Short")
    strategy.exit("SL/TP", from_entry = "short", limit = short_profit_level , stop = short_stop_level , alert_message = "Short exit")
    
if time > i_endTime  
    strategy.close_all(comment = "close all", alert_message = "close all")
    
plot(showlines and strategy.position_size <= 0 ? na : long_stop_level,    color=color.red,  style=plot.style_linebr, linewidth = 2)
plot(showlines and strategy.position_size <= 0 ? na : long_profit_level,  color=color.lime, style=plot.style_linebr, linewidth = 2)
plot(showlines and strategy.position_size >= 0 ? na : short_stop_level,   color=color.red,  style=plot.style_linebr, linewidth = 2)
plot(showlines and strategy.position_size >= 0 ? na : short_profit_level, color=color.lime, style=plot.style_linebr, linewidth = 2)

//}



더 많은