Stratégie Supertrend dynamique adaptative à la volatilité en plusieurs étapes

ATR SMA STD TP
Date de création: 2024-11-29 16:57:19 Dernière modification: 2024-11-29 16:57:19
Copier: 0 Nombre de clics: 439
1
Suivre
1617
Abonnés

Stratégie Supertrend dynamique adaptative à la volatilité en plusieurs étapes

Aperçu

La stratégie d’hypertrend dynamique auto-adaptative à la volatilité en plusieurs étapes est un système de trading innovant qui combine les indicateurs du canal de Vegas et du SuperTrend. La particularité de cette stratégie réside dans sa capacité à s’adapter dynamiquement à la volatilité du marché, ainsi que dans l’utilisation d’un mécanisme de freinage en plusieurs étapes pour optimiser le rapport risque/rendement. La stratégie offre un signal de trading plus précis en combinant l’analyse de la volatilité du canal de Vegas avec la fonction de suivi des tendances de SuperTrend, qui ajuste automatiquement ses paramètres lorsque les conditions du marché changent.

Principe de stratégie

La stratégie fonctionne sur trois composantes principales: le calcul du canal de Vegas, la détection des tendances et le système de freinage en plusieurs étapes. Le canal de Vegas utilise des moyennes mobiles simples (SMA) et des écarts standards (STD) pour définir la portée des fluctuations des prix. L’indicateur SuperTrend détermine la direction de la tendance en fonction des valeurs d’ATR ajustées.

Avantages stratégiques

  1. Adaptabilité dynamique: les stratégies peuvent s’adapter automatiquement aux différentes conditions du marché en ajustant les facteurs de volatilité.
  2. Gestion des risques: un mécanisme de freinage en plusieurs étapes fournit une solution systématique pour obtenir des résultats rentables.
  3. Personnalisabilité: offre plusieurs options de paramètres pour répondre à différents styles de négociation.
  4. Une couverture complète des marchés: le support pour les transactions bidirectionnelles multi-channels.
  5. Les commentaires visuels: fournissent une interface graphique claire pour faciliter l’analyse et la prise de décision.

Risque stratégique

  1. Sensitivité des paramètres: les différentes combinaisons de paramètres peuvent entraîner des différences importantes dans les performances de la stratégie.
  2. Le retard: l’indicateur basé sur les moyennes mobiles est en retard.
  3. Le risque de fausse percée: un faux signal peut être généré sur le marché horizontal.
  4. Les paramètres d’arrêt sont mis en balance: un arrêt prématuré risque de manquer la tendance, un arrêt tardif risque de perdre des bénéfices.

Orientation de l’optimisation de la stratégie

  1. L’introduction de filtres d’environnement de marché, qui permettent d’ajuster les paramètres de la stratégie en fonction des différentes conditions du marché.
  2. L’augmentation de l’analyse du trafic et de la fiabilité du signal.
  3. Développer des mécanismes d’arrêt adaptatifs pour ajuster les niveaux d’arrêt en fonction des fluctuations du marché.
  4. Intégrer d’autres indicateurs techniques pour fournir une confirmation du signal.
  5. Gestion dynamique des positions et adaptation de la taille des transactions en fonction des risques du marché.

Résumer

La stratégie de surtrend dynamique auto-adaptative à la volatilité à plusieurs étapes représente une méthode de trading quantitative avancée qui offre aux traders un système de trading complet en combinant plusieurs indicateurs techniques et un mécanisme de freinage innovant. Sa capacité d’adaptation dynamique et ses fonctions de gestion des risques le rendent particulièrement adapté pour fonctionner dans différents environnements de marché et offre une bonne marge d’extensibilité et d’optimisation.

Code source de la stratégie
/*backtest
start: 2024-10-01 00:00:00
end: 2024-10-31 23:59:59
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Multi-Step Vegas SuperTrend - strategy [presentTrading]", shorttitle="Multi-Step Vegas SuperTrend - strategy [presentTrading]", overlay=true, precision=3, commission_value=0.1, commission_type=strategy.commission.percent, slippage=1, currency=currency.USD)

// Input settings allow the user to customize the strategy's parameters.
tradeDirectionChoice = input.string(title="Trade Direction", defval="Both", options=["Long", "Short", "Both"]) // Option to select the trading direction
atrPeriod = input(10, "ATR Period for SuperTrend") // Length of the ATR for volatility measurement
vegasWindow = input(100, "Vegas Window Length") // Length of the moving average for the Vegas Channel
superTrendMultiplier = input(5, "SuperTrend Multiplier Base") // Base multiplier for the SuperTrend calculation
volatilityAdjustment = input.float(5, "Volatility Adjustment Factor") // Factor to adjust the SuperTrend sensitivity to the Vegas Channel width

// User inputs for take profit settings
useTakeProfit = input.bool(true, title="Use Take Profit", group="Take Profit Settings")
takeProfitPercent1 = input.float(3.0, title="Take Profit % Step 1", group="Take Profit Settings")
takeProfitPercent2 = input.float(6.0, title="Take Profit % Step 2", group="Take Profit Settings")
takeProfitPercent3 = input.float(12.0, title="Take Profit % Step 3", group="Take Profit Settings")
takeProfitPercent4 = input.float(21.0, title="Take Profit % Step 4", group="Take Profit Settings")

takeProfitAmount1 = input.float(25, title="Take Profit Amount % Step 1", group="Take Profit Settings")
takeProfitAmount2 = input.float(20, title="Take Profit Amount % Step 2", group="Take Profit Settings")
takeProfitAmount3 = input.float(10, title="Take Profit Amount % Step 3", group="Take Profit Settings")
takeProfitAmount4 = input.float(15, title="Take Profit Amount % Step 4", group="Take Profit Settings")

numberOfSteps = input.int(4, title="Number of Take Profit Steps", minval=1, maxval=4, group="Take Profit Settings")

// Calculate the Vegas Channel using a simple moving average and standard deviation.
vegasMovingAverage = ta.sma(close, vegasWindow)
vegasChannelStdDev = ta.stdev(close, vegasWindow)
vegasChannelUpper = vegasMovingAverage + vegasChannelStdDev
vegasChannelLower = vegasMovingAverage - vegasChannelStdDev

// Adjust the SuperTrend multiplier based on the width of the Vegas Channel.
channelVolatilityWidth = vegasChannelUpper - vegasChannelLower
adjustedMultiplier = superTrendMultiplier + volatilityAdjustment * (channelVolatilityWidth / vegasMovingAverage)

// Calculate the SuperTrend indicator values.
averageTrueRange = ta.atr(atrPeriod)
superTrendUpper = hlc3 - (adjustedMultiplier * averageTrueRange)
superTrendLower = hlc3 + (adjustedMultiplier * averageTrueRange)
var float superTrendPrevUpper = na
var float superTrendPrevLower = na
var int marketTrend = 1

// Update SuperTrend values and determine the current trend direction.
superTrendPrevUpper := nz(superTrendPrevUpper[1], superTrendUpper)
superTrendPrevLower := nz(superTrendPrevLower[1], superTrendLower)
marketTrend := close > superTrendPrevLower ? 1 : close < superTrendPrevUpper ? -1 : nz(marketTrend[1], 1)
superTrendUpper := marketTrend == 1 ? math.max(superTrendUpper, superTrendPrevUpper) : superTrendUpper
superTrendLower := marketTrend == -1 ? math.min(superTrendLower, superTrendPrevLower) : superTrendLower
superTrendPrevUpper := superTrendUpper
superTrendPrevLower := superTrendLower

// Enhanced Visualization
// Plot the SuperTrend and Vegas Channel for visual analysis.
plot(marketTrend == 1 ? superTrendUpper : na, "SuperTrend Upper", color=color.green, linewidth=2)
plot(marketTrend == -1 ? superTrendLower : na, "SuperTrend Lower", color=color.red, linewidth=2)
plot(vegasChannelUpper, "Vegas Upper", color=color.purple, linewidth=1)
plot(vegasChannelLower, "Vegas Lower", color=color.purple, linewidth=1)

// Apply a color to the price bars based on the current market trend.
barcolor(marketTrend == 1 ? color.green : marketTrend == -1 ? color.red : na)

// Detect trend direction changes and plot entry/exit signals.
trendShiftToBullish = marketTrend == 1 and marketTrend[1] == -1
trendShiftToBearish = marketTrend == -1 and marketTrend[1] == 1

plotshape(series=trendShiftToBullish, title="Enter Long", location=location.belowbar, color=color.green, style=shape.labelup, text="Buy")
plotshape(series=trendShiftToBearish, title="Enter Short", location=location.abovebar, color=color.red, style=shape.labeldown, text="Sell")

// Define conditions for entering long or short positions, and execute trades based on these conditions.
enterLongCondition = marketTrend == 1
enterShortCondition = marketTrend == -1

// Check trade direction choice before executing trade entries.
if enterLongCondition and (tradeDirectionChoice == "Long" or tradeDirectionChoice == "Both")
    strategy.entry("Long Position", strategy.long)

if enterShortCondition and (tradeDirectionChoice == "Short" or tradeDirectionChoice == "Both")
    strategy.entry("Short Position", strategy.short)

// Close all positions when the market trend changes.
if marketTrend != marketTrend[1]
    strategy.close_all()

// Multi-Stage Take Profit Logic
if (strategy.position_size > 0)
    entryPrice = strategy.opentrades.entry_price(strategy.opentrades - 1)
    if numberOfSteps >= 1
        strategy.exit("Take Profit 1", from_entry="Long Position", qty_percent=takeProfitAmount1, limit=entryPrice * (1 + takeProfitPercent1 / 100))
    if numberOfSteps >= 2
        strategy.exit("Take Profit 2", from_entry="Long Position", qty_percent=takeProfitAmount2, limit=entryPrice * (1 + takeProfitPercent2 / 100))
    if numberOfSteps >= 3
        strategy.exit("Take Profit 3", from_entry="Long Position", qty_percent=takeProfitAmount3, limit=entryPrice * (1 + takeProfitPercent3 / 100))
    if numberOfSteps >= 4
        strategy.exit("Take Profit 4", from_entry="Long Position", qty_percent=takeProfitAmount4, limit=entryPrice * (1 + takeProfitPercent4 / 100))

if (strategy.position_size < 0)
    entryPrice = strategy.opentrades.entry_price(strategy.opentrades - 1)
    if numberOfSteps >= 1
        strategy.exit("Take Profit 1", from_entry="Short Position", qty_percent=takeProfitAmount1, limit=entryPrice * (1 - takeProfitPercent1 / 100))
    if numberOfSteps >= 2
        strategy.exit("Take Profit 2", from_entry="Short Position", qty_percent=takeProfitAmount2, limit=entryPrice * (1 - takeProfitPercent2 / 100))
    if numberOfSteps >= 3
        strategy.exit("Take Profit 3", from_entry="Short Position", qty_percent=takeProfitAmount3, limit=entryPrice * (1 - takeProfitPercent3 / 100))
    if numberOfSteps >= 4
        strategy.exit("Take Profit 4", from_entry="Short Position", qty_percent=takeProfitAmount4, limit=entryPrice * (1 - takeProfitPercent4 / 100))