This strategy uses the slope of linear regression to identify different market regimes (bullish or bearish). By calculating the linear regression slope of closing prices over a defined period, it measures the direction and strength of the market trend. When the slope is above a certain threshold, the market is considered bullish, and the strategy enters a long position. When the slope is below a negative threshold, the market is considered bearish, and the strategy enters a short position. The strategy closes positions when the price crosses the Simple Moving Average (SMA), signaling a potential reversal or change in trend.
The core principle of this strategy is to use the slope of linear regression to identify market regimes. By performing linear regression on the closing prices over a specific period, a best-fit line is obtained. The slope of this line reflects the overall trend direction and strength of the prices during that period. A positive slope indicates an upward trend, with a larger slope indicating a stronger uptrend. A negative slope indicates a downward trend, with a smaller slope indicating a stronger downtrend. By setting slope thresholds, the strategy determines whether the market is bullish or bearish and makes corresponding trading decisions.
The Dynamic Market Regime Identification Strategy based on linear regression slope determines market regimes by calculating the linear regression slope of prices and makes corresponding trading decisions. The strategy has clear logic, simple calculations, and can effectively capture the main market trends. However, it may generate frequent trades in choppy markets and is sensitive to parameter selection. Through parameter optimization, trend filtering, stop loss and take profit, and multi-timeframe analysis, the stability and profitability of the strategy can be further improved.
/*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)