
평선 회귀 거래 전략은 주가 가격의 선형 회귀선과 평선의 교차를 계산하여 구매 및 판매 신호를 결정한다. 이 전략은 평선 및 선형 회귀 분석을 결합하여 주가 추세를 고려하고 통계학적 특성을 고려하여 주가 역점을 효과적으로 판단하여 낮은 매출을 달성 할 수 있습니다.
이 전략은 우선 n일 주가 가격의 선형 회귀선과 m일 평균선 을 계산한다. 선형 회귀선은 주가 가격의 장기적인 통계적 추세를 반영하고, 평균선은 주가 가격의 단기적인 움직임을 반영한다.
평균선 위를 가로질러 선형 회귀선이 되면, 주가 상승 동력이 강화되어 구매 신호가 발생한다. 평균선 아래를 가로질러 선형 회귀선이 되면, 주가 상승 동력이 약해져 판매 신호가 발생한다.
특히, 전략은 다음과 같은 단계를 통해 거래 신호를 판단합니다.
n일 주가 선형 회귀선을 계산
선형 회귀 선의 m일 간단한 이동 평균 LRMA를 계산
주식 가격을 계산하는 m일 지수 이동 평균
에마에 LRMA를 부착하면 longEntry를 생성합니다.
LRMA를 통과할 때, longExit를 생성하여 판매합니다.
그리고, 대가 판단과 함께 대가 시장이 황소 시장일 때만 구매 신호를 고려해야 합니다.
신호에 따라 거래합니다.
평균선과 회귀선의 교차를 통해 매매 시기를 판단하여, 가짜 브레이크를 효과적으로 필터링하고 반전점을 포착하여, 낮은 매매와 높은 매매를 달성한다.
주의해야 할 변수 조정, 적절히 확대 평균선 및 회귀선 주기 변수, 거래 빈도를 낮추기. Stop Loss 전략의 합리적인 설정 위험 제어. 대가 판단 규칙을 최적화하고 정확도를 높여라.
이 전략은 다음과 같은 부분에서 최적화될 수 있습니다.
평균선 지표 최적화: 무게중심 이동 평균과 같은 다른 유형의 평균선을 시도하여 해당 주식에 적합한 최적의 평균선을 찾습니다.
회귀선 최적화: 회귀선 계산 주기를 조정하여 이 주식의 장기적인 추세를 가장 잘 반영하는 주기적 변수를 찾습니다.
대가 판단 최적화: 다양한 대가 판단 지표를 테스트하여 전략에 가장 적합한 대가 신호를 찾습니다.
매개 변수 최적화: 다양한 매개 변수 조합을 통해 반복적으로 재검토하여 최적의 매개 변수 구성을 찾는다.
손해 차단 전략 최적화: 다양한 손해 차단 방법을 테스트하고, 위험을 제어하기 위해 최적의 손해 차단 논리를 설정한다.
거래 비용 최적화: 거래 비용을 줄이기 위해 다양한 거래 수수료 모드에 따라 거래 빈도를 조정하십시오.
이러한 몇 가지 최적화를 통해 전략의 안정성과 수익률을 더욱 높일 수 있습니다.
이 평선 회귀 거래 전략은 평선 분석과 선형 회귀 분석을 통합하여 주가 반전점을 효과적으로 식별하여 저가 고가 판매를 안내 할 수 있습니다. 전략은 간단하고 신뢰할 수 있으며 중장선 옵션 거래에 적합합니다. 매개 변수 최적화 및 위험 제어를 통해 전략의 안정성을 더욱 향상시킬 수 있습니다. 이 전략은 주식 시장 분석에 대한 실행 가능한 기술 거래 프로그램을 제공합니다.
/*backtest
start: 2022-10-18 00:00:00
end: 2023-10-24 00:00:00
period: 1d
basePeriod: 1h
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/
// © lazy_capitalist
//@version=5
strategy('Linear Regression MA', overlay=true, initial_capital=10000)
datesGroup = "Date Info"
startMonth = input.int(defval = 1, title = "Start Month", minval = 1, maxval = 12, group=datesGroup)
startDay = input.int(defval = 1, title = "Start Day", minval = 1, maxval = 31, group=datesGroup)
startYear = input.int(defval = 2022, title = "Start Year", minval = 1970, group=datesGroup)
averagesGroup = "Averages"
lrLineInput = input.int(title="Linear Regression Line", defval=55, minval = 1, group=averagesGroup)
lrMAInput = input.int(title="Linear Regression MA", defval=55, minval = 1, group=averagesGroup)
emaInput = input.int(title="EMA Length", defval=55, minval = 1, group=averagesGroup)
tradesGroup = "Execute Trades"
executeLongInput = input.bool(title="Execute Long Trades", defval=true)
executeShortInput = input.bool(title="Execute Short Trades", defval=true)
executeStopLoss = input.bool(title="Execute Stop Loss", defval=true)
fourHrSMAExpr = ta.sma(close, 200)
fourHrMA = request.security(symbol=syminfo.tickerid, timeframe="240", expression=fourHrSMAExpr)
bullish = close > fourHrMA ? true : false
maxProfitInput = input.float( title="Max Profit (%)", defval=10.0, minval=0.0) * 0.01
stopLossPercentageInput = input.float( title="Stop Loss (%)", defval=1.75, minval=0.0) * 0.01
start = timestamp(startYear, startMonth, startDay, 00, 00) // backtest start window
window() => time >= start ? true : false // create function "within window of time"
showDate = input(defval = true, title = "Show Date Range")
lrLine = ta.linreg(close, lrLineInput, 0)
lrMA = ta.sma(lrLine, lrMAInput)
ema = ta.ema(close, emaInput)
longEntry = ema < lrMA
longExit = lrMA < ema
shortEntry = lrMA < ema
shortExit = ema < lrMA
maxProfitLong = strategy.opentrades.entry_price(0) * (1 + maxProfitInput)
maxProfitShort = strategy.opentrades.entry_price(0) * (1 - maxProfitInput)
stopLossPriceShort = strategy.position_avg_price * (1 + stopLossPercentageInput)
stopLossPriceLong = strategy.position_avg_price * (1 - stopLossPercentageInput)
if(executeLongInput and bullish)
strategy.entry( id="long_entry", direction=strategy.long, when=longEntry and window(), qty=10, comment="long_entry")
strategy.close( id="long_entry", when=longExit, comment="long_exit")
// strategy.close( id="long_entry", when=maxProfitLong <= close, comment="long_exit_mp")
if(executeShortInput and not bullish)
strategy.entry( id="short_entry", direction=strategy.short, when=shortEntry and window(), qty=10, comment="short_entry")
strategy.close( id="short_entry", when=shortExit, comment="short_exit")
// strategy.close( id="short_entry", when=maxProfitShort <= close, comment="short_exit_mp")
if(strategy.position_size > 0 and executeStopLoss)
strategy.exit( id="long_entry", stop=stopLossPriceLong, comment="exit_long_SL")
strategy.exit( id="short_entry", stop=stopLossPriceShort, comment="exit_short_SL")
// plot(series=lrLine, color=color.green)
plot(series=lrMA, color=color.red)
plot(series=ema, color=color.blue)