
이 전략은 선형 회귀의 기울기를 사용하여 시장의 다른 상태를 식별합니다. (승승 또는 하락). 수시 가격의 수시 회귀의 기울기를 계산하여 시장 추세의 방향과 강도를 측정 할 수 있습니다. 경사가 특정 하락보다 크면 시장은 낙관적이라고 간주되며 전략은 다단계 위치에 들어갑니다. 경사가 부정적인 하락보다 작으면 시장은 하락으로 간주되며 전략은 공백 위치에 들어갑니다.
이 전략의 핵심 원칙은 시장 상태를 식별하기 위해 선형 회귀의 기울기를 사용하는 것입니다. 종전 가격에 대한 선형 회귀를 수행함으로써 최적의 조화 직선을 얻을 수 있습니다. 이 직선의 기울기는 해당 기간 동안의 가격의 전반적인 경향의 방향과 강도를 반영합니다.
선형 회귀 기울기를 기반으로 한 동적 시장 상태 인식 전략은 가격의 선형 회귀 기울기를 계산하여 시장 상태를 판단하고 그에 따른 거래 결정을 내립니다. 이 전략의 논리는 명확하고 계산이 간단하며 시장의 주요 추세를 효과적으로 포착 할 수 있습니다. 그러나 불안한 시장에서 거래가 자주 발생할 수 있으며 파라미터 선택에 민감합니다. 파라미터 최적화, 트렌드 필터링, 스톱 손실 스톱 및 다중 시간 프레임 분석과 같은 방법을 통해 전략의 안정성과 수익성을 더욱 향상시킬 수 있습니다.
/*backtest
start: 2023-05-22 00:00:00
end: 2024-05-27 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Binance","currency":"BTC_USDT"}]
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © tmalvao
//@version=5
strategy("Minha estratégia", overlay=true, margin_long=100, margin_short=100)
// Função para calcular o slope (inclinação) com base na média móvel simples (SMA)
slope_length = input(20, title="Slope Length")
sma_length = input(50, title="SMA Length")
slope_threshold = input.float(0.1, title="Slope Threshold")
sma = ta.sma(close, sma_length)
// Calculando o slope (inclinação)
var float slope = na
if (not na(close[slope_length - 1]))
slope := (close - close[slope_length]) / slope_length
// Identificação dos regimes de mercado com base no slope
bullish_market = slope > slope_threshold
bearish_market = slope < -slope_threshold
// Condições de entrada e saída para mercados bullish e bearish
if (bullish_market)
strategy.entry("Long", strategy.long)
if (bearish_market)
strategy.entry("Short", strategy.short)
// Saída das posições
exit_condition = ta.crossover(close, sma) or ta.crossunder(close, sma)
if (exit_condition)
strategy.close("Long")
strategy.close("Short")
// Exibir a inclinação em uma janela separada
slope_plot = plot(slope, title="Slope", color=color.blue)
hline(0, "Zero Line", color=color.gray)