
이 전략은 선형 회귀와 변동률 지표를 사용하여 시장의 다양한 상태를 식별하고, 구매 또는 판매 조건이 충족되면 대응하는 다단계 또는 공석 포지션을 설정합니다. 동시에, 이 전략은 시장 상황에 따라 변수를 최적화하고 조정하여 다양한 시장 환경에 맞게 조정할 수 있습니다. 전략은 지수 이동 평균을 거래 신호를 확인하는 부가적인 지표로도 사용합니다.
이 전략은 선형적 회귀와 변동률 지표를 통해 시장 상태를 식별하고, EMA를 확인 지표로 사용하여, 적응력이 강한, 논리적으로 명확한 거래 전략을 구축한다. 전략의 장점은 추세와 변동성을 결합하고, 변수 최적화를 허용하며, 다양한 시장 환경에 적합하다. 그러나 전략에는 변수 선택, 격동 시장 및 블랙 사건과 같은 위험이 존재하며, 실제 응용에서 지속적인 최적화와 개선이 필요합니다. 풍부한 신호 소스, 최적화 변수 선택, 위험 제어 조치 개선 등과 같은 측면에서 전략 개선이 가능하여 안정성과 수익성을 향상시킬 수 있다.
/*backtest
start: 2023-05-22 00:00:00
end: 2024-05-27 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_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("Regime de Mercado com Regressão e Volatilidade Otimizado", overlay=true)
// Parâmetros para otimização
upperThreshold = input.float(1.0, title="Upper Threshold")
lowerThreshold = input.float(-1.0, title="Lower Threshold")
length = input.int(50, title="Length", minval=1)
// Indicadores de volatilidade
atrLength = input.int(14, title="ATR Length")
atrMult = input.float(2.0, title="ATR Multiplier")
atr = ta.atr(atrLength)
volatility = atr * atrMult
// Calculando a regressão linear usando função incorporada
intercept = ta.linreg(close, length, 0)
slope = ta.linreg(close, length, 1) - ta.linreg(close, length, 0)
// Sinal de compra e venda
buySignal = slope > upperThreshold and close > intercept + volatility
sellSignal = slope < lowerThreshold and close < intercept - volatility
// Entrando e saindo das posições
if (buySignal)
strategy.entry("Buy", strategy.long)
if (sellSignal)
strategy.entry("Sell", strategy.short)
// Indicadores adicionais para confirmação
emaFastLength = input.int(10, title="EMA Fast Length")
emaSlowLength = input.int(50, title="EMA Slow Length")
emaFast = ta.ema(close, emaFastLength)
emaSlow = ta.ema(close, emaSlowLength)
// Confirmando sinais com EMAs
if (buySignal and emaFast > emaSlow)
strategy.entry("Buy Confirmed", strategy.long)
if (sellSignal and emaFast < emaSlow)
strategy.entry("Sell Confirmed", strategy.short)
// Exibindo informações no gráfico
plot(slope, title="Slope", color=color.blue)
plot(intercept, title="Intercept", color=color.red)
plot(volatility, title="Volatility", color=color.green)
hline(upperThreshold, "Upper Threshold", color=color.green, linestyle=hline.style_dotted)
hline(lowerThreshold, "Lower Threshold", color=color.red, linestyle=hline.style_dotted)