Stratégie de l'indicateur de volatilité de la bourse

Auteur:ChaoZhang est là., Date: 2023-12-06 14h29
Les étiquettes:

img

Résumé

La stratégie Triple SuperTrend et Stoch RSI est une stratégie de trading quantitative qui combine la tendance à plusieurs délais de l'indicateur SuperTrend et les signaux de surachat/survente de l'indicateur Stoch RSI. La stratégie utilise trois indicateurs SuperTrend avec des paramètres différents pour déterminer les tendances du marché et combine les signaux Stoch RSI pour filtrer les signaux de trading.

La logique de la stratégie

La logique de base de la stratégie Triple SuperTrend et Stoch RSI consiste à combiner les indicateurs SuperTrend avec différents paramètres et l'indicateur Stoch RSI pour le filtrage des signaux de trading afin d'améliorer la qualité des signaux et de réduire les faux signaux.

Premièrement, la stratégie adopte trois indicateurs de SuperTrend avec des paramètres variés pour déterminer la tendance majeure du marché. Les trois indicateurs de SuperTrend ont des paramètres allant de délais rapides à lents, afin de capturer les changements de tendance à différents niveaux. Lorsque les indicateurs de SuperTrend les plus rapides et les deuxièmes plus rapides donnent des signaux d'achat/vente simultanés, nous estimons au préalable que le signal a une certaine fiabilité.

Deuxièmement, l'indicateur Stoch RSI est introduit pour déterminer si le marché est extrêmement suracheté ou survendu lorsque le signal se produit. L'indicateur Stoch RSI combine les forces des indicateurs RSI et stochastiques, permettant des jugements efficaces sur les conditions de marché surachetées / survendues. Lorsque les signaux SuperTrend les plus rapides et les deuxièmes plus rapides s'alignent sur les signaux Stoch RSI, les signaux d'achat / vente finaux peuvent être déclenchés.

Grâce à la combinaison de multiples indicateurs et de délais, la stratégie Triple SuperTrend et Stoch RSI peut filtrer efficacement le bruit du marché, améliorer la fiabilité du signal et réduire les transactions incorrectes.

Les avantages de la stratégie

L'avantage le plus important de la stratégie Triple SuperTrend et Stoch RSI réside dans la combinaison efficace de plusieurs indicateurs et délais, ce qui présente les avantages suivants:

  1. La combinaison des trois indicateurs SuperTrend et Stoch RSI peut réduire considérablement le bruit et les faux signaux associés aux indicateurs individuels.

  2. En dépit de la diminution de la fréquence du signal, la proportion de signaux rentables voit une amélioration significative.

  3. Convient pour les marchés en tendance. Le filtrage multi-temporel facilite la capture des tendances à moyen et long terme, s'adaptant bien aux environnements de marché en tendance.

  4. L'optimisation facile pour une meilleure performance. Les indicateurs triples permettent des possibilités plus larges d'optimisation des paramètres.

  5. Paramètres personnalisables, adaptés à votre style de trading, qui peuvent être librement ajustés pour mieux convenir à votre style de trading.

Risques liés à la stratégie

Il existe également certains risques associés à la stratégie Triple SuperTrend et Stoch RSI:

  1. Réduction de la fréquence du signal: le mécanisme de filtrage multicouche réduit considérablement la fréquence de négociation de la stratégie.

  2. La nature conservatrice rend la stratégie susceptible de manquer certaines opportunités rentables.

  3. Une plus grande dépendance par rapport aux paramètres, plus d'indicateurs et plus de difficultés à optimiser.

  4. La combinaison de plusieurs délais limite également la flexibilité de la stratégie.

Pour faire face à ces risques, des mesures d'optimisation telles que l'ajustement des paramètres des indicateurs et l'introduction d'indicateurs supplémentaires peuvent être adoptées afin de renforcer le contrôle des risques tout en améliorant la qualité de la rentabilité.

Directions d'optimisation

Il est encore possible d'optimiser davantage la stratégie Triple SuperTrend et Stoch RSI:

  1. Ajustez les paramètres de l'indicateur pour obtenir la meilleure combinaison.

  2. Introduisez un stop loss/take profit pour un meilleur contrôle des risques.

  3. Incorporer davantage d'indicateurs pour la validation du signal, par exemple des indicateurs de volume.

  4. Mettre en place des capacités d'adaptation pour optimiser automatiquement les paramètres en fonction de l'évolution de la dynamique du marché.

  5. Combiner des algorithmes d'apprentissage automatique pour la prédiction des performances, évaluer la précision du signal.

Avec une optimisation continue, la stratégie Triple SuperTrend et Stoch RSI peut évoluer vers un système de trading stable et efficace, fournissant un alpha considérable.

Conclusion

La stratégie Triple SuperTrend et Stoch RSI combine avec succès l'analyse de plusieurs délais et le jugement de surachat/survente dans une stratégie de trading unique. Elle conserve les deux avantages du suivi de tendance et du filtrage des indicateurs, améliorant les signaux rentables tout en diminuant les faux signaux. Bien que les risques et l'espace d'optimisation existent encore, sa rentabilité et sa stabilité peuvent être encore améliorées grâce à l'ajustement des paramètres et à l'optimisation de la stratégie.


/*backtest
start: 2022-11-29 00:00:00
end: 2023-04-17 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © M3RZI

//@version=4
strategy("3x Supertrend and Stoch RSI", overlay = true, max_bars_back = 1000)

//INPUTS
STATRLENGTH1 = input(10, title = "Fast Supertrend ATR Length", type = input.integer, group = "SUPERTREND SETTINGS")
STATRMULT1 = input(1, title = "Fast Supertrend ATR Multiplier", type = input.float, group = "SUPERTREND SETTINGS")
STATRLENGTH2 = input(11, title = "Medium Supertrend ATR Length", type = input.integer, group = "SUPERTREND SETTINGS")
STATRMULT2 = input(2, title = "Medium Supertrend ATR Multiplier", type = input.float, group = "SUPERTREND SETTINGS")
STATRLENGTH3 = input(12, title = "Slow Supertrend ATR Length", type = input.integer, group = "SUPERTREND SETTINGS")
STATRMULT3 = input(3, title = "Slow Supertrend ATR Multiplier", type = input.float, group = "SUPERTREND SETTINGS")

stochK = input(3, title = "K (Stochastic Fast)", type = input.integer, group = "STOCHASTIC RSI SETTINGS")
stochD = input(3, title = "D (Signal Line)", type = input.integer, group = "STOCHASTIC RSI SETTINGS")
rsiLength = input(14, title = "RSI Length", type = input.integer, group = "STOCHASTIC RSI SETTINGS")
stochLength = input(14, title = "Stochastic Length", type = input.integer, group = "STOCHASTIC RSI SETTINGS")
rsiSource = input(close, title = "RSI Source", type = input.source, group = "STOCHASTIC RSI SETTINGS")
stochRestrictions = input(false, title = "Restrict crosses to overbought/oversold territory", type = input.bool, group = "STOCHASTIC RSI SETTINGS")
overboughtLine = input(80, title = "Stochastic  RSI Upper Band", type = input.integer, group = "STOCHASTIC RSI SETTINGS")
oversoldLine = input(20, title = "Stochastic RSI Lower Band", type = input.integer, group = "STOCHASTIC RSI SETTINGS")

EMALength  = input(200, title = "EMA Length", type = input.integer, group = "EMA SETTINGS")

SLStrategy = input("ATR Based", title = "Stop Loss Strategy", options = ["ATR Based"],type = input.string, group = "POSITION EXIT SETTINGS")
SLATRLength = input(14, title = "Stop Loss ATR Length", type = input.integer, group = "POSITION EXIT SETTINGS")
SLATRMult = input(2.7, title = "Stop Loss ATR Multiplier", type = input.float, group = "POSITION EXIT SETTINGS")
TPStrategy = input("ATR Based", title = "Take Profit Strategy", options = ["ATR Based"],type = input.string, group = "POSITION EXIT SETTINGS")
TPATRLength = input(14, title = "Take Profit ATR Length", type = input.integer, group = "POSITION EXIT SETTINGS")
TPATRMult = input(1.6, title = "Take Profit ATR Multiplier", type = input.float, group = "POSITION EXIT SETTINGS")

//SUPERTRENDS
[superTrend1,dir1] = supertrend(STATRMULT1,STATRLENGTH1)
[superTrend2,dir2] = supertrend(STATRMULT2,STATRLENGTH2)
[superTrend3,dir3] = supertrend(STATRMULT3,STATRLENGTH3)

directionST1 = dir1 == 1 and dir1[1] == 1 ? false : dir1 == -1 and dir1[1] == -1 ? true : na
directionST2 = dir2 == 1 and dir2[1] == 1 ? false : dir2 == -1 and dir2[1] == -1 ? true : na
directionST3 = dir3 == 1 and dir3[1] == 1 ? false : dir3 == -1 and dir3[1] == -1 ? true : na

//STOCH RSI
rsi = rsi(rsiSource, rsiLength)
k = sma(stoch(rsi, rsi, rsi, stochLength), stochK)
d = sma(k, stochD)

//EMA
ema = ema(close,EMALength)

//CONDITIONS LONG AND SHORT

var long = false
var longCondition = false
var short = false
var shortCondition = false
var drawing = false
var TP = 0.0
var SL = 0.0
var middle = 0.0
var initial = 0

stopSize = atr(SLATRLength) * SLATRMult
profitSize = atr(TPATRLength) * TPATRMult
longStop = close - stopSize
longProfit = close + profitSize
current = close
shortStop = close + stopSize
shortProfit = close - profitSize
barInitial = bar_index

if  stochRestrictions
    longCondition := close > ema and ((directionST1 == true and directionST2 == true)  or (directionST2 == true and directionST3 == true)) and crossover(k,d) and k < oversoldLine and not long and not drawing
    shortCondition := close < ema and ((directionST1 == false and directionST2 == false)  or (directionST2 == false and directionST3 == false)) and crossunder(k,d) and k > overboughtLine and not short and not drawing
else
    longCondition := close > ema and ((directionST1 == true and directionST2 == true)  or (directionST2 == true and directionST3 == true)) and crossover(k,d) and not long and not drawing
    shortCondition := close < ema and ((directionST1 == false and directionST2 == false)  or (directionST2 == false and directionST3 == false)) and crossunder(k,d) and not short and not drawing

if longCondition
    long := true
    short := false
    drawing := true
    TP := longProfit
    middle := current
    SL := longStop
    initial := barInitial
    strategy.entry("Long", strategy.long, 10)
    strategy.exit("Long exit","Long", limit = TP, stop = SL)
    alert("Long signal Supertrend \n Profit:"+tostring(TP)+"\Curret price:"+tostring(close)+"\Stop:"+tostring(SL),alert.freq_once_per_bar_close)
    //label.new(bar_index,low,text = "Long\nTP:"+tostring(TP)+"\nSL:"+tostring(SL)+"\nAbierto:"+tostring(current), yloc = yloc.belowbar, textcolor = color.white, color = color.green, size = size.small,  style = label.style_label_up)

if shortCondition
    short := true
    long := false
    drawing := true
    TP := shortProfit
    middle := current
    SL := shortStop
    initial := barInitial
    strategy.entry("Short", strategy.short, 10)
    strategy.exit("Short exit","Short",limit = TP , stop = SL)
    alert("Short signal Supertrend \n Profit:"+tostring(TP)+"\Curret price:"+tostring(close)+"\Stop:"+tostring(SL),alert.freq_once_per_bar_close)
    //label.new(bar_index,high,text = "Short\nTP:"+tostring(TP)+"\nSL:"+tostring(SL)+"\nAbierto:"+tostring(current), yloc = yloc.abovebar, textcolor = color.white, color = color.red, size = size.small,  style = label.style_label_down)

if long and (high[1] >= TP or low[1] <= SL)
    drawing := false
    long := false
    if high[1] >= TP
        label.new(bar_index[int((bar_index - initial)/2)],TP, text = "Win (Long)", textcolor = color.white, color = color.green, size = size.small, style = label.style_label_down)
    else
        label.new(bar_index[int((bar_index - initial)/2)],SL, text = "Lose (Long)", textcolor = color.white, color = color.red, size = size.small, style = label.style_label_up)

if short and (low[1] <= TP or high[1] >= SL)
    drawing :=  false
    short := false
    if low[1] <= TP
        label.new(bar_index[int((bar_index - initial)/2)],TP, text = "Win (short)", textcolor = color.white, color = color.green, size = size.small, style = label.style_label_up)
    else
        label.new(bar_index[int((bar_index - initial)/2)],SL, text = "Lose (short)", textcolor = color.white, color = color.red, size = size.small, style = label.style_label_down)

//STRATEGY
//strategy.entry("buy", strategy.long, 10, when = longCondition)
//strategy.exit("bracket", "buy",  10, limit = TP, stop = SL)
//strategy.entry("short", strategy.long, 10, when = shortCondition)
//strategy.exit("bracket", "short",  10, limit = TP, stop = SL)

//DRAWING
plotshape(longCondition, title = "Long Signal", location=location.belowbar, style=shape.labelup, color=color.green, textcolor=color.white, size=size.small, text="Long")
plotshape(shortCondition, title = "Short Signal", location=location.abovebar, style=shape.labeldown, color=color.red, textcolor=color.white, size=size.small, text="Short")
profitLine = plot(drawing and drawing[1] ? TP : na, title = "Take profit", color = color.green, style = plot.style_linebr)
currentLine =plot(drawing and drawing[1]  ? middle : na, title = "Middle Line", color = color.white, style = plot.style_linebr)
lossLine = plot(drawing and drawing[1]  ? SL : na, title = "Stop Loss", color = color.red, style = plot.style_linebr)
fill(currentLine,profitLine, title = "Profit Background" ,color = color.new(color.green,75))
fill(currentLine,lossLine, title = "Loss Background" ,color = color.new(color.red,75))
plot(superTrend1, title = "Fast Supertrend", color = dir1 == 1 and dir1[1] == 1 ? color.red : dir1 == -1 and dir1[1] == -1 ? color.green : na)
plot(superTrend2, title = "Medium Supertrend", color = dir2 == 1 and dir2[1] == 1 ? color.red : dir2 == -1 and dir2[1] == -1 ? color.green : na)
plot(superTrend3, title = "Slow Supertrend", color = dir3 == 1 and dir3[1] == 1 ? color.red : dir3 == -1 and dir3[1] == -1 ? color.green : na)
plot(ema, title = "EMA",color = color.yellow)
//plot(k, color = color.blue)
//plot(d, color = color.orange)
//h1 = hline(80)
//h2 = hline(20)
//fill(h1,h2, color = color.new(color.purple,60))




Plus de