
전략 이름: 동력 구동형 선형 MACD 전략
개요: 이것은 선형 회귀를 사용하여 주식 가격을 예측하고 MACD 지표와 결합한 양적 전략입니다. 그것은 선형 회귀를 사용하여 역사적 가격과 거래량을 분석하여 미래의 가격 추세를 예측합니다. 수익 기회가 발생하면 MACD 지표와 결합하여 진입 시기를 판단합니다.
전략적 원칙:
우위 분석: 이것은 통계적 예측과 기술 지표 판단을 결합한 전략이다. 그것은 선형적 회귀를 사용하여 가격 예측을 하고 주관적 추측을 피한다. 동시에, MACD 지표는 시장의 구매력 방향을 효과적으로 판단하고 기회를 정확하게 포착한다. 전체적으로 이것은 체계화 된 수준이 높으며, 예측이 정확하고, 위험이 통제 가능한 전략이다.
위험 분석: 선형 회귀는 역사적인 데이터에만 의존하며, 중요한 이익과 공백 소식과 같은 급격한 사건에 민감하지 않으며, 잘못된 신호를 일으킬 수 있습니다. 또한, 회귀 주기의 길이와 같은 변수 설정도 전략의 성능에 영향을 미칩니다. 우리는 곡선 흔들림이 전략에 미치는 영향을 줄이기 위해vwma 평형 예측 가격을 채택하는 것을 권장합니다.
최적화 방향: 우리는 이 전략이 다음과 같은 부분에서 최적화 될 수 있다고 생각합니다.
결론: 이 전략은 선형 회귀 예측 가격과 MACD 지표 판단을 통해 체계화된 정량 거래 전략을 형성한다. 그것은 예측 논리 명확, 위험 제어, 최적화 공간 폭 등의 장점을 가지고 있다. 우리는 지속적인 최적화 및 반복을 통해 그 성능이 점점 더 우수해질 것이라고 믿는다. 그것은 우리에게 과학적 예측 방법을 사용하여 정량 거래를하는 생각을 제공하며, 우리의 깊은 연구와 응용에 가치가 있다.
/*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)