Stratégie de dynamique de renversement moyenne

Auteur:ChaoZhang est là., Date: 2023-11-15 17h40 et 59 min
Les étiquettes:

img

Résumé

La stratégie de momentum de réversion moyenne est une stratégie de trading de tendance qui suit les moyennes de prix à court terme.

La logique de la stratégie

La stratégie calcule d'abord la ligne de réversion moyenne et l'écart type du prix. Puis, combinée avec les valeurs seuil fixées par les paramètres seuil supérieur et seuil inférieur, elle calcule si le prix dépasse la plage d'un écart type de la ligne de réversion moyenne. Si oui, un signal de trading est généré.

Pour les signaux longs, le prix doit être inférieur à la ligne de réversion moyenne d'un écart type, le prix de clôture est inférieur à la SMA de la période LENGTH et supérieur à la SMA TREND, si ces trois conditions sont remplies, une position longue sera ouverte.

Pour les signaux courts, le prix doit être supérieur à la ligne de réversion moyenne d'un écart type, le prix de clôture est supérieur à la SMA de la période LENGTH et inférieur à la SMA TREND, si ces trois conditions sont remplies, une position courte sera ouverte.

La stratégie combine également la cible de profit en pourcentage et le pourcentage d'arrêt de perte pour la prise de profit et la gestion des arrêts de perte.

La méthode de sortie peut choisir entre un croisement de moyenne mobile ou un croisement de régression linéaire.

Grâce à la combinaison du trading bidirectionnel, du filtrage des tendances, de la prise de profit et du stop loss, etc., il réalise le jugement et le suivi des tendances du marché à moyen terme.

Les avantages

  1. L'indicateur de réversion moyenne peut évaluer efficacement l'écart du prix par rapport au centre de valeur.

  2. L'indicateur de dynamique SMA peut filtrer le bruit du marché à court terme.

  3. Le trading bidirectionnel peut saisir pleinement les opportunités de tendance dans toutes les directions.

  4. Le mécanisme de prise de profit et de stop loss peut contrôler efficacement les risques.

  5. Les méthodes de sortie sélectionnables peuvent être flexibles pour s'adapter aux conditions du marché.

  6. Une stratégie de trading de tendance complète qui capte mieux les tendances à moyen terme.

Les risques

  1. L'indicateur de renversement moyen est sensible aux paramètres, des paramètres de seuil incorrects peuvent provoquer de faux signaux.

  2. Dans des conditions de marché volatiles, le stop loss peut être déclenché trop fréquemment.

  3. Dans les tendances latérales, la fréquence des transactions peut être trop élevée, ce qui augmente les coûts des transactions et les risques de glissement.

  4. Lorsque l'instrument de négociation ne dispose pas d'une liquidité suffisante, le contrôle du glissement peut être sous-optimal.

  5. Le trading bidirectionnel comporte des risques plus élevés, une gestion prudente de l'argent est requise.

Ces risques peuvent être maîtrisés par l'optimisation des paramètres, l'ajustement du stop loss, la gestion de l'argent, etc.

Directions d'optimisation

  1. Optimiser les paramètres des indicateurs de réversion moyenne et de dynamique pour mieux s'adapter aux différents instruments de négociation.

  2. Ajouter des indicateurs d'identification des tendances pour améliorer la capacité de reconnaissance des tendances.

  3. Optimiser la stratégie de stop loss pour mieux s'adapter aux fluctuations importantes du marché.

  4. Ajouter des modules de dimensionnement des positions pour ajuster la taille des positions en fonction des conditions du marché.

  5. Ajouter plus de modules de gestion des risques, tels que le contrôle du tirage maximal, le contrôle de la courbe des capitaux propres, etc.

  6. Considérez la combinaison de méthodes d'apprentissage automatique pour optimiser automatiquement les paramètres de stratégie.

Résumé

En résumé, la stratégie de momentum de réversion moyenne capture les tendances de réversion moyenne à moyen terme grâce à une conception d'indicateur simple et efficace. La stratégie a une forte adaptabilité et une polyvalence, mais présente également certains risques. En optimisant en continu et en la combinant avec d'autres stratégies, de meilleures performances peuvent être obtenues. Dans l'ensemble, la stratégie est assez complète et constitue une méthode de trading de tendance à considérer.


/*backtest
start: 2023-10-15 00:00:00
end: 2023-11-14 00:00:00
period: 1h
basePeriod: 15m
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/
// © GlobalMarketSignals

//@version=4
strategy("GMS: Mean Reversion Strategy", overlay=true)

LongShort       = input(title="Long Only or Short Only or Both?", type=input.string, defval="Both", options=["Both", "Long Only", "Short Only"])
Lookback        = input(title="Length", type=input.integer, defval=10, minval=0)
LThr1           = input(title="Upper threshold", type=input.float, defval=1, minval=0)
LThr            = input(title="Lower threshold", type=input.float, defval=-1, maxval=0)
src             = input(title="Source", type=input.source, defval=close)
LongShort2      = input(title="Linear Regression Exit or Moving Average Exit?", type=input.string, defval="MA", options=["LR", "MA"])
SMAlenL         = input(title="MA/LR Exit Length", type = input.integer ,defval=10)
SMALen2         = input(title="Trend SMA Length", type = input.integer ,defval=200)
AboveBelow      = input(title="Above or Below Trend SMA?", type=input.string, defval="Above", options=["Above", "Below", "Don't Include"])
PTbutton        = input(title="Profit Target On/Off", type=input.bool, defval=true)
ProfitTarget    = input(title="Profit Target %", type=input.float, defval=1, step=0.1, minval=0)
SLbutton        = input(title="Stop Loss On/Off", type=input.bool, defval=true)
StopLoss        = input(title="Stop Loss %", type=input.float, defval=-1, step=0.1, maxval=0)

x               = (src-linreg(src,Lookback,0))/(stdev(src,Lookback))

plot(linreg(src,Lookback,0))

//PROFIT TARGET & STOPLOSS

if PTbutton == true and SLbutton == true
    strategy.exit("EXIT", profit=((close*(ProfitTarget*0.01))/syminfo.mintick), loss=((close*(StopLoss*-0.01))/syminfo.mintick))
else
    if PTbutton == true and SLbutton == false
        strategy.exit("PT EXIT", profit=((close*(ProfitTarget*0.01))/syminfo.mintick))
    else
        if PTbutton == false and SLbutton == true
            strategy.exit("SL EXIT", loss=((close*(StopLoss*-0.01))/syminfo.mintick))
        else    
            strategy.cancel("PT EXIT")


////////////////////////
//MOVING AVERAGE EXIT//
//////////////////////

if LongShort=="Long Only" and AboveBelow=="Above" and LongShort2 =="MA"
    strategy.entry("LONG", true, when = x<LThr and close<sma(close,SMAlenL) and close>sma(close,SMALen2))
    strategy.close("LONG", when = close>sma(close,SMAlenL))

if LongShort=="Long Only" and AboveBelow=="Below" and LongShort2 =="MA"
    strategy.entry("LONG", true, when = x<LThr and close<sma(close,SMAlenL) and close<sma(close,SMALen2))
    strategy.close("LONG", when = close>sma(close,SMAlenL))

if LongShort=="Long Only" and AboveBelow=="Don't Include" and LongShort2 =="MA"
    strategy.entry("LONG", true, when = x<LThr and close<sma(close,SMAlenL) )
    strategy.close("LONG", when = close>sma(close,SMAlenL))
    
///////    
    
if LongShort=="Short Only" and AboveBelow=="Above" and LongShort2 =="MA"
    strategy.entry("SHORT", false, when = x>LThr1 and close>sma(close,SMAlenL) and close>sma(close,SMALen2))
    strategy.close("SHORT", when = close<sma(close,SMAlenL))

if LongShort=="Short Only" and AboveBelow=="Below" and LongShort2 =="MA"
    strategy.entry("SHORT", false, when = x>LThr1 and close>sma(close,SMAlenL)   and close<sma(close,SMALen2))
    strategy.close("SHORT", when = close<sma(close,SMAlenL))

if LongShort=="Short Only" and AboveBelow=="Don't Include" and LongShort2 =="MA"
    strategy.entry("SHORT", false, when = x>LThr1  and close>sma(close,SMAlenL)  )
    strategy.close("SHORT", when = close<sma(close,SMAlenL))
    
//////

if LongShort=="Both" and AboveBelow=="Above" and LongShort2 =="MA"
    strategy.entry("LONG", true, when = x<LThr and close<sma(close,SMAlenL) and close>sma(close,SMALen2))
    strategy.close("LONG", when = close>sma(close,SMAlenL))

if LongShort=="Both" and AboveBelow=="Below" and LongShort2 =="MA"
    strategy.entry("LONG", true, when = x<LThr and close<sma(close,SMAlenL) and close<sma(close,SMALen2))
    strategy.close("LONG", when = close>sma(close,SMAlenL))

if LongShort=="Both" and AboveBelow=="Don't Include" and LongShort2 =="MA"
    strategy.entry("LONG", true, when = x<LThr and close<sma(close,SMAlenL) )
    strategy.close("LONG", when = close>sma(close,SMAlenL))
    
///////    
    
if LongShort=="Both" and AboveBelow=="Above" and LongShort2 =="MA"
    strategy.entry("SHORT", false, when = x>LThr1 and close>sma(close,SMAlenL) and close>sma(close,SMALen2))
    strategy.close("SHORT", when = close<sma(close,SMAlenL))

if LongShort=="Both" and AboveBelow=="Below" and LongShort2 =="MA"
    strategy.entry("SHORT", false, when = x>LThr1 and close>sma(close,SMAlenL) and close<sma(close,SMALen2))
    strategy.close("SHORT", when = close<sma(close,SMAlenL))

if LongShort=="Both" and AboveBelow=="Don't Include" and LongShort2 =="MA"
    strategy.entry("SHORT", false, when = x>LThr1 and close>sma(close,SMAlenL) )
    strategy.close("SHORT", when = close<sma(close,SMAlenL))
    
/////////////////
//LIN REG EXIT//
///////////////

if LongShort=="Long Only" and AboveBelow=="Above" and LongShort2 =="LR"
    strategy.entry("LONG", true, when = x<LThr and close<linreg(close,SMAlenL,0) and close>sma(close,SMALen2))
    strategy.close("LONG", when = close>linreg(close,SMAlenL,0))

if LongShort=="Long Only" and AboveBelow=="Below" and LongShort2 =="LR"
    strategy.entry("LONG", true, when = x<LThr and close<linreg(close,SMAlenL,0) and close<sma(close,SMALen2))
    strategy.close("LONG", when = close>linreg(close,SMAlenL,0))

if LongShort=="Long Only" and AboveBelow=="Don't Include" and LongShort2 =="LR"
    strategy.entry("LONG", true, when = x<LThr and close<linreg(close,SMAlenL,0) )
    strategy.close("LONG", when = close>linreg(close,SMAlenL,0))
    
///////    
    
if LongShort=="Short Only" and AboveBelow=="Above" and LongShort2 =="LR"
    strategy.entry("SHORT", false, when = x>LThr1 and close>linreg(close,SMAlenL,0) and close>sma(close,SMALen2))
    strategy.close("SHORT", when = close<linreg(close,SMAlenL,0))

if LongShort=="Short Only" and AboveBelow=="Below" and LongShort2 =="LR"
    strategy.entry("SHORT", false, when = x>LThr1 and close>linreg(close,SMAlenL,0)   and close<sma(close,SMALen2))
    strategy.close("SHORT", when = close<linreg(close,SMAlenL,0))

if LongShort=="Short Only" and AboveBelow=="Don't Include" and LongShort2 =="LR"
    strategy.entry("SHORT", false, when = x>LThr1  and close>linreg(close,SMAlenL,0)  )
    strategy.close("SHORT", when = close<linreg(close,SMAlenL,0))
    
//////

if LongShort=="Both" and AboveBelow=="Above" and LongShort2 =="LR"
    strategy.entry("LONG", true, when = x<LThr and close<linreg(close,SMAlenL,0) and close>sma(close,SMALen2))
    strategy.close("LONG", when = close>linreg(close,SMAlenL,0))

if LongShort=="Both" and AboveBelow=="Below" and LongShort2 =="LR"
    strategy.entry("LONG", true, when = x<LThr and close<linreg(close,SMAlenL,0) and close<sma(close,SMALen2))
    strategy.close("LONG", when = close>linreg(close,SMAlenL,0))

if LongShort=="Both" and AboveBelow=="Don't Include" and LongShort2 =="LR"
    strategy.entry("LONG", true, when = x<LThr and close<linreg(close,SMAlenL,0) )
    strategy.close("LONG", when = close>linreg(close,SMAlenL,0))
    
///////    
    
if LongShort=="Both" and AboveBelow=="Above" and LongShort2 =="LR"
    strategy.entry("SHORT", false, when = x>LThr1 and close>linreg(close,SMAlenL,0) and close>sma(close,SMALen2))
    strategy.close("SHORT", when = close<linreg(close,SMAlenL,0))

if LongShort=="Both" and AboveBelow=="Below" and LongShort2 =="LR"
    strategy.entry("SHORT", false, when = x>LThr1 and close>linreg(close,SMAlenL,0) and close<sma(close,SMALen2))
    strategy.close("SHORT", when = close<linreg(close,SMAlenL,0))

if LongShort=="Both" and AboveBelow=="Don't Include" and LongShort2 =="LR"
    strategy.entry("SHORT", false, when = x>LThr1 and close>linreg(close,SMAlenL,0) )
    strategy.close("SHORT", when = close<linreg(close,SMAlenL,0))






Plus de