
Cette stratégie est un système de trading quantitatif qui combine l’indice de force relative (RSI) et la moyenne mobile (MA) pour identifier les tendances du marché et les opportunités de trading grâce à la synergie des deux indicateurs. Le système intègre également des filtres de volume et de volatilité pour augmenter la fiabilité des signaux de trading. L’idée principale de la stratégie est de déterminer la direction de la tendance grâce au croisement de la moyenne mobile rapide et de la moyenne mobile lente, et d’utiliser le RSI pour confirmer l’élan, formant ainsi finalement un cadre de décision de trading complet.
La stratégie adopte un mécanisme de confirmation du signal à deux niveaux :
Cette stratégie établit un système de trading relativement complet en utilisant de manière exhaustive des indicateurs de tendance et de momentum. Les avantages du système résident dans son mécanisme de confirmation du signal à plusieurs niveaux et dans son système de gestion des risques parfait, mais dans l’application réelle, il est nécessaire de prêter attention à l’impact de l’environnement du marché sur la performance de la stratégie et d’optimiser les paramètres en fonction des conditions réelles. Grâce à une amélioration et une optimisation continues, la stratégie devrait permettre de maintenir des performances stables dans différents environnements de marché.
/*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}]
*/
// © Boba2601
//@version=5
strategy("RSI-MA Synergy", overlay=true, margin_long=100, margin_short=100)
// === Налаштування індикаторів ===
length_rsi = input.int(14, title="RSI Period", group="Індикатори")
fastMALength = input.int(9, title="Fast MA Length", group="Індикатори")
slowMALength = input.int(21, title="Slow MA Length", group="Індикатори")
// === Налаштування стоп-лосу і тейк-профіту ===
useStopLossTakeProfit = input.bool(true, title="Використовувати стоп-лос і тейк-профіт", group="Стоп-лос і Тейк-профіт")
stopLossPercent = input.float(2.0, title="Стоп-лос (%)", minval=0.1, step=0.1, group="Стоп-лос і Тейк-профіт")
takeProfitPercent = input.float(4.0, title="Тейк-профіт (%)", minval=0.1, step=0.1, group="Стоп-лос і Тейк-профіт")
// === Налаштування об'єму та волатильності ===
useVolumeFilter = input.bool(false, title="Використовувати фільтр об'єму", group="Об'єм та Волатильність")
volumeThreshold = input.int(50000, title="Мінімальний об'єм", group="Об'єм та Волатильність")
useVolatilityFilter = input.bool(false, title="Використовувати фільтр волатильності", group="Об'єм та Волатильність")
atrLength = input.int(14, title="Період ATR для волатильності", group="Об'єм та Волатильність")
volatilityThreshold = input.float(1.5, title="Мінімальна волатильність (ATR)", step=0.1, group="Об'єм та Волатильність")
// === Розрахунок індикаторів ===
rsiValue = ta.rsi(close, length_rsi)
fastMA = ta.sma(close, fastMALength)
slowMA = ta.sma(close, slowMALength)
// === Розрахунок об'єму та волатильності ===
averageVolume = ta.sma(volume, 20)
atrValue = ta.atr(atrLength)
// === Умови входу в позицію ===
longCondition = ta.crossover(fastMA, slowMA) and rsiValue < 50
if useVolumeFilter
longCondition := longCondition and volume > volumeThreshold
if useVolatilityFilter
longCondition := longCondition and atrValue > volatilityThreshold
shortCondition = ta.crossunder(fastMA, slowMA) and rsiValue > 50
if useVolumeFilter
shortCondition := shortCondition and volume > volumeThreshold
if useVolatilityFilter
shortCondition := shortCondition and atrValue > volatilityThreshold
// === Логіка входу та виходу з позиції ===
if (longCondition)
strategy.entry("Long", strategy.long)
if (useStopLossTakeProfit)
stopLossPrice = close * (1 - stopLossPercent / 100)
takeProfitPrice = close * (1 + takeProfitPercent / 100)
strategy.exit("Exit Long", "Long", stop = stopLossPrice, limit = takeProfitPrice)
if (shortCondition)
strategy.entry("Short", strategy.short)
if (useStopLossTakeProfit)
stopLossPrice = close * (1 + stopLossPercent / 100)
takeProfitPrice = close * (1 - takeProfitPercent / 100)
strategy.exit("Exit Short", "Short", stop = stopLossPrice, limit = takeProfitPrice)
// === Закриття позицій за зворотнім сигналом ===
if (strategy.position_size > 0 and (ta.crossunder(fastMA, slowMA) or rsiValue > 50))
strategy.close("Long", comment="Закрито по сигналу")
if (strategy.position_size < 0 and (ta.crossover(fastMA, slowMA) or rsiValue < 50))
strategy.close("Short", comment="Закрито по сигналу")