Chiến lược theo dõi xu hướng khung thời gian đa dạng dựa trên Đám mây Ichimoku, MACD và Stochastic


Ngày tạo: 2024-02-05 10:30:45 sửa đổi lần cuối: 2024-02-05 10:30:45
sao chép: 2 Số nhấp chuột: 768
1
tập trung vào
1617
Người theo dõi

Chiến lược theo dõi xu hướng khung thời gian đa dạng dựa trên Đám mây Ichimoku, MACD và Stochastic

Tổng quan

Chiến lược này kết hợp nhiều chỉ số như biểu đồ đám mây Ichimoku, trung bình di chuyển, MACD, Stochastic và ATR để nhận diện và theo dõi xu hướng trong nhiều khung thời gian. Sau khi nhận được tín hiệu xu hướng có xác suất cao, sử dụng phương pháp dừng lỗ chu kỳ ATR để kiểm soát rủi ro.

Nguyên tắc chiến lược

  1. Đồ họa đám mây Ichimoku để xác định hướng xu hướng đường dài giữa. Các đường xoay và đường chuẩn đi qua đường đám mây trên giá CLOSE là tín hiệu đa đầu và dưới là tín hiệu đầu không.

  2. MACD đánh giá xu hướng đường ngắn và quá mua quá bán. Các đường tín hiệu trên đường MACD là tín hiệu đa đầu và dưới là tín hiệu trống.

  3. Stochastic KD đánh giá vùng mua quá bán quá. Trên đường K đi 20 là tín hiệu đa đầu, dưới đi 80 là tín hiệu trống đầu.

  4. Đường trung bình di chuyển đánh giá xu hướng trung hạn. Đường trung bình di chuyển trên giá đóng cửa là tín hiệu đa đầu, dưới là tín hiệu không đầu.

  5. Kết hợp nhiều tín hiệu chỉ số trên, lọc một số tín hiệu giả, tạo ra tín hiệu xu hướng liên tục có xác suất cao.

  6. Xây dựng giá dừng lỗ dựa trên ATR. Kiểm soát rủi ro bằng cách sử dụng một số lần ATR nhất định làm điểm dừng lỗ và điểm dừng.

Lợi thế chiến lược

  1. Nhiều khung thời gian nhận ra xu hướng, tăng độ chính xác tín hiệu.

  2. Công nghệ lọc kết hợp chỉ số được sử dụng rộng rãi, lọc hiệu quả các tín hiệu giả.

  3. ATR dừng lỗ theo chu kỳ, kiểm soát tối đa tổn thất đơn lẻ.

  4. Có thể tùy chỉnh mức độ nghiêm ngặt của điều kiện nhập học để đáp ứng các sở thích rủi ro khác nhau.

Rủi ro chiến lược

  1. Theo dõi xu hướng, không thể nhận ra sự đảo ngược của sự kiện bất ngờ.

  2. ATR có thể được lý tưởng hóa quá nhiều và khó có thể sao chép hoàn toàn trên đĩa cứng.

  3. Thiết lập tham số không chính xác có thể dẫn đến tần số giao dịch quá cao hoặc nhận dạng tín hiệu không chính xác.

  4. Cần điều chỉnh các tham số để tìm sự cân bằng, thích ứng với các giống và môi trường thị trường khác nhau.

Hướng tối ưu hóa chiến lược

  1. Thêm các thuật toán học máy để giúp xác định các điểm thay đổi xu hướng.

  2. Tối ưu hóa tham số nhân ATR, các giống khác nhau có thể thiết lập nhân khác nhau.

  3. Kết hợp với các yếu tố khác như biến đổi khối lượng giao dịch, tăng độ chính xác của tín hiệu đột phá.

  4. Các tham số được tối ưu hóa liên tục dựa trên kết quả phản hồi để tìm ra sự kết hợp tham số tốt nhất.

Tóm tắt

Chiến lược này sử dụng nhiều chỉ số như Ichimoku Cloud Graph, MACD, Stochastic để xác định xu hướng trên nhiều khung thời gian, trong khi nắm bắt xu hướng và tránh bị mắc kẹt trong các sự kiện bất ngờ. ATR là một chiến lược theo dõi xu hướng đáng khuyên.

Mã nguồn chiến lược
/*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)

//}