Suivi des tendances Stratégie de rupture de l'EMA

Auteur:ChaoZhang est là., Date: 2024-01-12 14h23
Les étiquettes:

img

Résumé

Il s'agit d'une stratégie de suivi de tendance basée sur une moyenne mobile exponentielle (EMA). Il juge la direction de la tendance sur les délais mensuels, hebdomadaires et quotidiens et exécute des actions d'entrée et de sortie spécifiques sur le graphique quotidien.

La logique de la stratégie

Jugement de tendance

  1. Sur le graphique mensuel, le prix est supérieur à l'EMA à 8 jours et l'EMA à 8 jours est supérieur à l'EMA à 21 jours, ce qui indique une tendance haussière;
  2. Sur le graphique hebdomadaire, le prix est supérieur à l'EMA à 8 jours et l'EMA à 8 jours est supérieur à l'EMA à 21 jours, ce qui indique une tendance haussière;
  3. Sur le graphique quotidien, le prix est supérieur à l'EMA à 8 jours et l'EMA à 8 jours est supérieur à l'EMA à 21 jours, ce qui indique une tendance à la hausse;

Signal d'entrée

  1. Un recul est observé sur le graphique quotidien avec le point bas touchant l'EMA de 8 jours d'hier;
  2. Le retrait forme un motif Ring Low avec un bas bas et un bas bas bas;
  3. Le prix de clôture est supérieur au sommet de la journée précédente, ce qui constitue un signal d'inversion de tendance.

Signal de sortie

Définir les normes de prise de profit et de stop-loss pour la sortie.

Analyse des avantages

  1. Le jugement de la tendance sur trois délais améliore la précision;
  2. Le retrait vers l' EMA constitue un soutien et augmente la certitude de l' entrée;
  3. Le suivi des tendances a un potentiel de profit élevé;

Analyse des risques

  1. Des jugements incohérents sur des périodes peuvent provoquer de faux signaux;
  2. L'ampleur excessive du recul peut rendre la stratégie invalide;
  3. L'arrêt des pertes peut se produire lors d'accidents éclair.

Directions d'optimisation

  1. Ajouter MACD, RSI pour jugement supplémentaire;
  2. Optimiser les paramètres de l'EMA;
  3. Ajustez la fourchette de prise de profit et de stop loss en fonction de la volatilité.

Résumé

La stratégie a un très bon potentiel de profit lorsque la tendance est correctement jugée. Il faut faire attention à un jugement de tendance inexact et à un retrait excessif provoquant de faux signaux. Pendant ce temps, l'optimisation des paramètres de prise de profit et de stop-loss est essentielle pour améliorer davantage l'avantage.


/*backtest
start: 2023-01-11 00:00:00
end: 2024-01-11 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/
// © the_daily_trader

//@version=5
// ---------------------        Start of Code        ---------------------
strategy("Swing Trades Validator", overlay=true, margin_long=100, pyramiding = 0)

// Indicator Display Checks
TakeProfitPercent       = input.float(title="Profit Target %", defval=10, minval=1, step=0.05)
StopLossPercent         = input.float(title="Stop Loss %", defval=10, minval=1, step=0.05)
pullbackchoice          = input.bool(false, "Relaxed Entry Rules")

// EMAs
emaH            = ta.ema(close, 8)
emaHyest        = ta.ema(close[1], 8)
emaHyest1       = ta.ema(close[2], 8)
emaHyest2       = ta.ema(close[3], 8)
emaL            = ta.ema(close, 21)
emaLyest        = ta.ema(close[1], 21)
emaLyest1       = ta.ema(close[2], 21)
emaLyest2       = ta.ema(close[3], 21)
emaf            = ta.ema(close, 50)
emath           = ta.ema(close, 200)
emathhigh       = ta.ema(high, 200)
emathlow        = ta.ema(low, 200)
emaslowmonthly  = request.security(syminfo.tickerid, "M", emaL) // Monthly 21ema
emafastmonthly  = request.security(syminfo.tickerid, "M", emaH) // Monthly 8ema
emaslowweekly   = request.security(syminfo.tickerid, "W", emaL) // Weekly 21ema
emafastweekly   = request.security(syminfo.tickerid, "W", emaH) // Weekly 8ema
emaslowdaily    = request.security(syminfo.tickerid, "D", emaL) // Daily 21ema
emafastdaily    = request.security(syminfo.tickerid, "D", emaH) // Daily 8ema
emafdaily       = request.security(syminfo.tickerid, "D", emaf) // Daily 50ema
emathdaily      = request.security(syminfo.tickerid, "D", emath) // Daily ema
emathdailyhigh  = request.security(syminfo.tickerid, "D", emathhigh) // Daily ema High
emathdailylow   = request.security(syminfo.tickerid, "D", emathlow) // Daily ema Low
ema21yest       = request.security(syminfo.tickerid, "D", emaLyest) // Daily 21ema 1 day ago
ema21yest1      = request.security(syminfo.tickerid, "D", emaLyest1) // Daily 21ema 2 days ago
ema21yest2      = request.security(syminfo.tickerid, "D", emaLyest2) // Daily 21ema 3 days ago
ema8yest        = request.security(syminfo.tickerid, "D", emaHyest) // Daily 8ema 1 day ago
ema8yest1       = request.security(syminfo.tickerid, "D", emaHyest1) // Daily 8ema 2 days ago
ema8yest2       = request.security(syminfo.tickerid, "D", emaHyest2) // Daily 8ema 3 days ago


// Prices
monthopen       = request.security(syminfo.tickerid, 'M', open, barmerge.gaps_off, barmerge.lookahead_on)
monthclose      = request.security(syminfo.tickerid, 'M', close, barmerge.gaps_off, barmerge.lookahead_on)
weekopen        = request.security(syminfo.tickerid, 'W', open, barmerge.gaps_off, barmerge.lookahead_on)
weekclose       = request.security(syminfo.tickerid, 'W', close, barmerge.gaps_off, barmerge.lookahead_on)
dayopen         = request.security(syminfo.tickerid, 'D', open, barmerge.gaps_off, barmerge.lookahead_on)
dayclose        = request.security(syminfo.tickerid, 'D', close, barmerge.gaps_off, barmerge.lookahead_on)
threedayhigh    = request.security(syminfo.tickerid, 'D', high[3], barmerge.gaps_off, barmerge.lookahead_on)
twodayhigh      = request.security(syminfo.tickerid, 'D', high[2], barmerge.gaps_off, barmerge.lookahead_on)
yesthigh        = request.security(syminfo.tickerid, 'D', high[1], barmerge.gaps_off, barmerge.lookahead_on)
yestlow         = request.security(syminfo.tickerid, 'D', low[1], barmerge.gaps_off, barmerge.lookahead_on)

// Conditions 
monthlybullish          = emafastmonthly > emaslowmonthly
monthlybullishprice     = close > emafastmonthly
monthlybullishcandle    = monthclose > monthopen
weeklybullish           = emafastweekly > emaslowweekly
weeklybullishprice      = close > emafastweekly
weeklybullishcandle     = weekclose > weekopen
dailybullish1           = emafdaily > emathdaily
dailybullish2           = emafastdaily > emaslowdaily
dailybullishprice       = close > emafastdaily
dailybullishcandle      = dayclose > dayopen
ringlow                 = yestlow <= ema8yest
aggropullback           = twodayhigh < threedayhigh
pullback                = (pullbackchoice ? aggropullback : 0)
pullbackfailure         = dayclose > yesthigh and yesthigh < twodayhigh or pullback
emasetup                = ema8yest > ema21yest and ema8yest1 > ema21yest1 and ema8yest2 > ema21yest2

// Target Profit and Stop Loss Inputs
// Input parameters can be found at the beginning of the code
ProfitTarget        = (close * (TakeProfitPercent / 100)) / syminfo.mintick
StopLoss            = (close * (StopLossPercent / 100)) / syminfo.mintick

longCondition = monthlybullish and monthlybullishprice and weeklybullish and weeklybullishprice and dailybullish1 and dailybullish2 and dailybullishprice and monthlybullishcandle and weeklybullishcandle and dailybullishcandle and ringlow and pullbackfailure and emasetup

if (longCondition)
    strategy.entry("Long", strategy.long)
    strategy.exit ("Exit", "Long", profit = ProfitTarget, loss = StopLoss)
    // strategy.close("Long", qty_percent = 100)


// -----------xxxxxxxxxxx-------------    End of Code     -----------xxxxxxxxxxx---------------

Plus de