
Esta estratégia é um sistema de negociação adaptável que integra vários indicadores de análise técnica e alterna entre diferentes estratégias de negociação identificando dinamicamente as condições de mercado. O sistema é baseado principalmente em três indicadores técnicos: média móvel (MA), bandas de Bollinger (BB) e índice de força relativa (RSI), e seleciona automaticamente o método de negociação mais adequado de acordo com as tendências do mercado e flutuações de intervalo. A estratégia adota soluções diferenciadas de gerenciamento de risco para mercados de tendência e variação, definindo diferentes parâmetros de take-profit e stop-loss.
A estratégia usa as médias móveis de 50 e 20 períodos para determinar tendências de mercado e combina os indicadores Bandas de Bollinger e RSI para identificar áreas de sobrecompra e sobrevenda. Em um mercado de tendências, o sistema negocia principalmente com base na relação entre o preço e a média móvel lenta e no cruzamento das linhas rápidas e lentas; em um mercado de intervalo, ele negocia principalmente com base nos rompimentos dos limites da Banda de Bollinger e nos sinais de sobrecompra e sobrevenda do RSI. . O sistema ajusta automaticamente o nível de take-profit de acordo com o ambiente de mercado. Um take-profit de 6% é usado para mercados de tendência e um take-profit de 4% é usado para mercados de intervalo. Um stop-loss de 2% é usado uniformemente para controlar riscos.
Esta estratégia integra vários indicadores técnicos clássicos para construir um sistema de negociação adaptável que pode se adaptar a diferentes ambientes de mercado. Mantendo a operação simples, o sistema realiza a identificação dinâmica do status do mercado e a troca automática de estratégias de negociação, além de ser altamente prático. Por meio de configurações diferenciadas de take-profit e stop-loss, a estratégia mantém boa lucratividade e controla os riscos. No futuro, a estabilidade e a confiabilidade da estratégia podem ser melhoradas ainda mais com a introdução de mais indicadores técnicos e a otimização de mecanismos de ajuste de parâmetros.
/*backtest
start: 2024-01-17 00:00:00
end: 2025-01-16 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT","balance":49999}]
*/
//@version=6
strategy("Supply & Demand Test 1 - Enhanced", overlay=true)
// Inputs
ma_length = input.int(50, title="50-period Moving Average Length", minval=1)
ma_length_fast = input.int(20, title="20-period Moving Average Length", minval=1)
bb_length = input.int(20, title="Bollinger Bands Length", minval=1)
bb_std_dev = input.float(2.0, title="Bollinger Bands Std Dev", step=0.1)
rsi_length = input.int(14, title="RSI Length", minval=1)
stop_loss_percent = input.float(0.02, title="Stop Loss Percent", step=0.001, minval=0.001)
take_profit_trend = input.float(0.06, title="Take Profit Percent (Trend)", step=0.001, minval=0.001)
take_profit_range = input.float(0.04, title="Take Profit Percent (Range)", step=0.001, minval=0.001)
// Moving Averages
ma_slow = ta.sma(close, ma_length)
ma_fast = ta.sma(close, ma_length_fast)
// Bollinger Bands
bb_basis = ta.sma(close, bb_length)
bb_dev = ta.stdev(close, bb_length)
bb_upper = bb_basis + bb_std_dev * bb_dev
bb_lower = bb_basis - bb_std_dev * bb_dev
// RSI
rsi = ta.rsi(close, rsi_length)
// Market Conditions
is_trending_up = close > ma_slow
is_trending_down = close < ma_slow
is_range_bound = not (is_trending_up or is_trending_down)
// Entry Conditions
long_trend_entry = is_trending_up and close >= ma_slow * 1.02
short_trend_entry = is_trending_down and close <= ma_slow * 0.98
long_ma_crossover = ta.crossover(ma_fast, ma_slow)
short_ma_crossover = ta.crossunder(ma_fast, ma_slow)
long_range_entry = is_range_bound and close <= bb_lower * 0.97
short_range_entry = is_range_bound and close >= bb_upper * 1.03
long_rsi_entry = is_range_bound and rsi < 30
short_rsi_entry = is_range_bound and rsi > 70
// Entry and Exit Logic
if long_trend_entry
strategy.entry("Long Trend", strategy.long)
strategy.exit("Exit Long Trend", from_entry="Long Trend", stop=close * (1 - stop_loss_percent), limit=close * (1 + take_profit_trend))
alert("Entered Long Trend", alert.freq_once_per_bar)
if short_trend_entry
strategy.entry("Short Trend", strategy.short)
strategy.exit("Exit Short Trend", from_entry="Short Trend", stop=close * (1 + stop_loss_percent), limit=close * (1 - take_profit_trend))
alert("Entered Short Trend", alert.freq_once_per_bar)
if long_ma_crossover
strategy.entry("Long MA Crossover", strategy.long)
strategy.exit("Exit Long MA Crossover", from_entry="Long MA Crossover", stop=close * (1 - stop_loss_percent), limit=close * (1 + take_profit_trend))
alert("Entered Long MA Crossover", alert.freq_once_per_bar)
if short_ma_crossover
strategy.entry("Short MA Crossover", strategy.short)
strategy.exit("Exit Short MA Crossover", from_entry="Short MA Crossover", stop=close * (1 + stop_loss_percent), limit=close * (1 - take_profit_trend))
alert("Entered Short MA Crossover", alert.freq_once_per_bar)
if long_range_entry
strategy.entry("Long Range", strategy.long)
strategy.exit("Exit Long Range", from_entry="Long Range", stop=close * (1 - stop_loss_percent), limit=close * (1 + take_profit_range))
alert("Entered Long Range", alert.freq_once_per_bar)
if short_range_entry
strategy.entry("Short Range", strategy.short)
strategy.exit("Exit Short Range", from_entry="Short Range", stop=close * (1 + stop_loss_percent), limit=close * (1 - take_profit_range))
alert("Entered Short Range", alert.freq_once_per_bar)
if long_rsi_entry
strategy.entry("Long RSI", strategy.long)
strategy.exit("Exit Long RSI", from_entry="Long RSI", stop=close * (1 - stop_loss_percent), limit=close * (1 + take_profit_range))
alert("Entered Long RSI", alert.freq_once_per_bar)
if short_rsi_entry
strategy.entry("Short RSI", strategy.short)
strategy.exit("Exit Short RSI", from_entry="Short RSI", stop=close * (1 + stop_loss_percent), limit=close * (1 - take_profit_range))
alert("Entered Short RSI", alert.freq_once_per_bar)
// Plotting
plot(ma_slow, color=color.blue, title="50-period MA")
plot(ma_fast, color=color.orange, title="20-period MA")
plot(bb_upper, color=color.red, title="Bollinger Upper")
plot(bb_lower, color=color.green, title="Bollinger Lower")
plot(bb_basis, color=color.gray, title="Bollinger Basis")
hline(70, "Overbought (RSI)", color=color.red, linestyle=hline.style_dotted)
hline(30, "Oversold (RSI)", color=color.green, linestyle=hline.style_dotted)