
Tên chính sách: Chính sách MACD tuyến tính theo động lực
Tóm tắt: Đây là một chiến lược định lượng sử dụng hồi quy tuyến tính để dự đoán giá cổ phiếu và kết hợp với chỉ số MACD. Nó sử dụng hồi quy tuyến tính để phân tích giá cả và khối lượng giao dịch lịch sử để dự đoán xu hướng giá trong tương lai.
Nguyên tắc chiến lược:
Phân tích lợi thế: Đây là một chiến lược kết hợp giữa dự đoán thống kê và đánh giá chỉ số kỹ thuật. Nó sử dụng sự hồi phục tuyến tính để đưa ra dự đoán giá, tránh phỏng đoán chủ quan. Đồng thời, chỉ số MACD có thể đánh giá hiệu quả đường đi của thị trường và nắm bắt cơ hội chính xác.
Phân tích rủi ro: Sự hồi phục tuyến tính chỉ phụ thuộc vào dữ liệu lịch sử, không nhạy cảm với các sự kiện bất ngờ như tin tức về lợi nhuận lớn và lỗ hổng, có thể tạo ra tín hiệu sai. Ngoài ra, cài đặt tham số như độ dài chu kỳ hồi phục cũng có thể ảnh hưởng đến hiệu suất chiến lược. Chúng tôi đề nghị sử dụng giá dự báo mịn vwma để giảm tác động của đường cong đối với chiến lược.
Định hướng tối ưu hóa: Chúng tôi nghĩ rằng chiến lược này có thể được tối ưu hóa trong một số khía cạnh:
Tóm lại: Chiến lược này có lợi thế như: logic dự đoán rõ ràng, rủi ro có thể kiểm soát được, không gian tối ưu hóa rộng rãi. Chúng tôi tin rằng, thông qua tối ưu hóa và lặp đi lặp lại liên tục, hiệu suất của nó sẽ ngày càng tốt hơn. Nó cung cấp cho chúng tôi những suy nghĩ về giao dịch định lượng sử dụng phương pháp dự đoán khoa học, đáng để chúng tôi nghiên cứu và áp dụng sâu hơn.
/*backtest
start: 2023-12-07 00:00:00
end: 2023-12-14 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/
// © stocktechbot
//@version=5
strategy("Linear On MACD", overlay=true, margin_long=100, margin_short=100)
fast_length = input(title="Fast Length", defval=12)
slow_length = input(title="Slow Length", defval=26)
tolerance = input.string(title="Risk tolerance", defval = "LOW", options=["LOW", "HIGH"])
chng = 0
obv = ta.cum(math.sign(ta.change(close)) * volume)
if close < close[1] and (open < close)
chng := 1
else if close > close[1]
chng := 1
else
chng := -1
obvalt = ta.cum(math.sign(chng) * volume)
//src = input(title="Source", defval=close)
src = obvalt
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"])
// 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
//hline(0, "Zero Line", color=color.new(#787B86, 50))
//plot(hist, title="Histogram", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below)))
//plot(macd, title="MACD", color=col_macd)
//plot(signal, title="Signal", color=col_signal)
[macdLine, signalLine, histLine] = ta.macd(close, 12, 26, 9)
//Linear Regression
vol = volume
// Function to calculate linear regression
linregs(y, x, len) =>
ybar = math.sum(y, len)/len
xbar = math.sum(x, len)/len
b = math.sum((x - xbar)*(y - ybar),len)/math.sum((x - xbar)*(x - xbar),len)
a = ybar - b*xbar
[a, b]
// Historical stock price data
price = close
// Length of linear regression
len = input(defval = 21, title = 'Lookback')
// Calculate linear regression for stock price based on volume
[a, b] = linregs(price, vol, len)
// Predicted stock price based on volume
predicted_price = a + b*vol
// Check if predicted price is between open and close
is_between = open < predicted_price and predicted_price < close
// Plot predicted stock price
plot(predicted_price, color=color.rgb(218, 27, 132), linewidth=2, title="Predicted Stock Price")
plot(ta.vwma(predicted_price,len), color=color.rgb(199, 43, 64), linewidth=2, title="Predicted Stock Price")
//BUY Signal
lincrossunder = close > predicted_price
macdrise = ta.rising(macd,2)
//macdvollong = ta.crossover(macd, signal)
//macdlong = ta.crossover(macdLine, signalLine)
macdvollong = macd > signal
macdlong = macdLine > signalLine
longCondition=false
if macdlong and macdvollong and is_between and ta.rising(predicted_price,1)
longCondition := true
if (longCondition)
strategy.entry("My Long Entry Id", strategy.long)
//Sell Signal
lincrossover = close < predicted_price
macdfall = ta.falling(macd,1)
macdsell = macd < signal
shortCondition = false
risklevel = predicted_price
if (tolerance == "HIGH")
risklevel := ta.vwma(predicted_price,len)
if macdfall and macdsell and (macdLine < signalLine) and (close < risklevel)
shortCondition := true
if (shortCondition)
strategy.entry("My Short Entry Id", strategy.short)