This Pine Script strategy is based on the Relative Strength Index (RSI) and the standard deviation (DEV) of price volatility. It determines entry points by comparing the price with upper and lower bands, while using RSI as an auxiliary filtering indicator. It generates long entry signals when the price breaks above the lower band and RSI is below the oversold threshold, and short entry signals when the price breaks below the upper band and RSI is above the overbought threshold. The strategy closes long positions when the price breaks below the exit lower band or RSI exceeds the overbought threshold, and closes short positions when the price breaks above the exit upper band or RSI falls below the oversold threshold. This strategy can dynamically adjust according to market volatility conditions, cutting losses in time during high volatility and holding positions for profit during low volatility. It is a quantitative trading strategy that can adapt to different market states.
This strategy combines volatility channels and the Relative Strength Index to make entry and exit decisions based on price fluctuations while referencing the RSI indicator. It can better capture short-term trends and cut losses and take profits in a timely manner. However, the strategy’s performance is relatively sensitive to parameter settings and needs to be optimized for different market environments and underlying assets. At the same time, consider introducing other indicators to assist in judging market trends in order to fully leverage the advantages of this strategy. Overall, this strategy has a clear idea, rigorous logic, and is a good quantitative trading strategy.
/*backtest start: 2024-05-20 00:00:00 end: 2024-05-27 00:00:00 period: 1h basePeriod: 15m 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("Estratégia de Desvio Padrão com RSI", overlay=true, margin_long=100, margin_short=100) // Parâmetros length = input.int(20, title="Período do Desvio Padrão") thresholdEntry = input.float(1.5, title="Limite de Entrada") thresholdExit = input.float(0.5, title="Limite de Saída") rsiLength = input.int(14, title="Período do RSI") rsiOverbought = input.int(70, title="RSI Overbought") rsiOversold = input.int(30, title="RSI Oversold") // Cálculo do Desvio Padrão price = close stdDev = ta.stdev(price, length) // Média Móvel Simples sma = ta.sma(price, length) // Limites baseados no Desvio Padrão upperLimit = sma + thresholdEntry * stdDev lowerLimit = sma - thresholdEntry * stdDev exitUpperLimit = sma + thresholdExit * stdDev exitLowerLimit = sma - thresholdExit * stdDev // Cálculo do RSI rsi = ta.rsi(price, rsiLength) // Condições de Entrada com RSI longCondition = ta.crossover(price, lowerLimit) and rsi < rsiOversold shortCondition = ta.crossunder(price, upperLimit) and rsi > rsiOverbought // Condições de Saída com RSI exitLongCondition = ta.crossunder(price, exitLowerLimit) or rsi > rsiOverbought exitShortCondition = ta.crossover(price, exitUpperLimit) or rsi < rsiOversold // Plotar Linhas plot(upperLimit, color=color.red, title="Limite Superior") plot(lowerLimit, color=color.green, title="Limite Inferior") plot(exitUpperLimit, color=color.orange, title="Limite de Saída Superior") plot(exitLowerLimit, color=color.blue, title="Limite de Saída Inferior") plot(sma, color=color.gray, title="SMA") hline(rsiOverbought, "RSI Overbought", color=color.red) hline(rsiOversold, "RSI Oversold", color=color.green) plot(rsi, title="RSI", color=color.purple) // Estratégia de Trade if (longCondition) strategy.entry("Long", strategy.long) if (shortCondition) strategy.entry("Short", strategy.short) if (exitLongCondition) strategy.close("Long") if (exitShortCondition) strategy.close("Short")