Hanyue - Stratégie de trading de suivi de tendance basée sur plusieurs EMA, ATR et RSI

EMA ATR RSI
Date de création: 2024-05-14 16:37:52 Dernière modification: 2024-05-14 16:37:52
Copier: 1 Nombre de clics: 601
1
Suivre
1617
Abonnés

Hanyue - Stratégie de trading de suivi de tendance basée sur plusieurs EMA, ATR et RSI

Aperçu

La stratégie utilise les moyennes mobiles de l’indicateur (EMA) pour juger de la tendance du marché et combine les indices de force et de faiblesse (RSI) et l’amplitude réelle moyenne (ATR) pour déterminer le point d’entrée et le point d’arrêt. La stratégie déclenche un signal d’ouverture de stockage lorsque le prix franchit le canal formé par les trois EMA et que le RSI franchit également sa moyenne mobile.

Principe de stratégie

  1. Calculer les EMA pour trois périodes différentes (courte, moyenne et longue) afin de juger de la tendance générale du marché.
  2. L’indicateur RSI est utilisé pour vérifier la force et la durabilité d’une tendance, indiquant une modification de la tendance lorsque le RSI dépasse sa moyenne mobile.
  3. Combinez la relation entre le prix et le canal EMA et le signal RSI pour générer un signal de stockage: lorsque le prix franchit le canal EMA et que le RSI franchit sa moyenne mobile, le stockage est ouvert dans la direction de la tendance.
  4. L’ATR est utilisé pour déterminer la taille de la position et le seuil de stop-loss, et pour contrôler le seuil de risque de chaque transaction.
  5. Le stop-loss est placé en fonction du risque de gain par défaut (par exemple, 1.5:1) pour assurer la rentabilité de la stratégie.

Analyse de la prédominance

  1. Simple et efficace: la stratégie utilise seulement quelques indicateurs techniques courants, la logique est claire, facile à comprendre et à mettre en œuvre.
  2. Suivre la tendance: grâce à la combinaison des canaux EMA et RSI, la stratégie est capable de traiter en fonction de la tendance du marché et de capturer des fluctuations de prix plus importantes.
  3. Contrôle des risques: l’ATR est utilisé pour fixer des stop-loss et contrôler la taille des positions, limitant ainsi efficacement le seuil de risque de chaque transaction.
  4. Flexibilité: les paramètres de la stratégie (par exemple, les cycles EMA, les cycles RSI, les multiples ATR, etc.) peuvent être ajustés en fonction des différents marchés et styles de négociation pour optimiser la performance.

Analyse des risques

  1. Optimisation des paramètres: la performance d’une stratégie dépend en grande partie de la sélection des paramètres. Une mauvaise configuration des paramètres peut entraîner l’échec ou une mauvaise performance de la stratégie.
  2. Risques de marché: les stratégies peuvent subir des pertes plus importantes dans des événements imprévus ou des situations extrêmes, en particulier lors d’un renversement de tendance ou d’un choc.
  3. Sur-simulation: une sur-simulation des données historiques dans le processus d’optimisation des paramètres peut entraîner une mauvaise performance de la stratégie dans les transactions réelles.

Le chemin à parcourir

  1. Paramètres dynamiques: paramètres stratégiques qui permettent d’ajuster la dynamique en fonction de l’évolution des conditions du marché, par exemple en utilisant des cycles plus longs d’EMA lorsque la tendance est évidente et des cycles plus courts lorsque le marché est en tremblement.
  2. Combinaison avec d’autres indicateurs: l’introduction d’autres indicateurs techniques (tels que la bande de Brin, le MACD, etc.) pour améliorer la fiabilité et l’exactitude du signal d’ouverture.
  3. Ajouter l’émotion du marché: combiner des indicateurs de l’émotion du marché (comme l’indice de la peur et de la cupidité) pour ajuster la stratégie de gestion des marges de risque et des réserves.
  4. Analyse des tendances et des signaux du marché sur différentes périodes afin d’obtenir une vue plus complète du marché et de prendre des décisions commerciales plus stables.

Résumé

La stratégie utilise le canal EMA pour juger de la tendance du marché, le RSI pour confirmer la force de la tendance et l’ATR pour contrôler le risque. L’avantage de la stratégie réside dans sa simplicité et son adaptabilité, permettant de traiter la tendance en fonction des différentes conditions du marché. Cependant, la présentation de la stratégie dépend en grande partie du choix des paramètres, un paramétrage inapproprié peut entraîner l’inefficacité ou une mauvaise performance de la stratégie.

Code source de la stratégie
/*backtest
start: 2024-04-01 00:00:00
end: 2024-04-30 23:59:59
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/
// © hatnxkld

//@version=4
strategy("Win ha", overlay=true)

ss2 = input("0300-1700", title = "Khung thời gian")

t2 = time(timeframe.period,ss2)
c2 = #cacae6

bgcolor(t2 ? c2 : na, transp = 70)


//3ema
emangan=input(title="Ema ngắn", defval = 12)
ngan=ema(close, emangan)
a= plot(ngan, title="EMA ngắn", color=color.yellow)
ematb=input(title="Ema trung bình", defval = 100)
tb=ema(close, ematb)
b= plot(tb, title="EMA trung bình", color=color.blue)
//emadai=input(title="Ema dai", defval = 288)
//dai=ema(close,emadai)
//c= plot(dai, title="EMA dai", color=color.red)




// nhập hệ số nhân ATR
i=input(title="Hệ số nhân với ATR", defval=1.25)

// RSI
rsi=rsi(close, emangan)
marsi=sma(rsi, emangan)

// Kênh keltler
//heso=input(defval=1, title="Hệ số Kênh Keltler")
//atr=atr(emangan)
//tren=ngan+atr*heso
//d=plot(tren, title="Kênh trên", color=color.white)
//duoi=ngan-atr*heso
//e=plot(duoi, title="Kênh dưới", color=color.white)
//fill(d,e, color=color.rgb(48, 58, 53))

ban = ( close[1]>open[1] and (high[1]-close[1])>(close[1]-low[1]) and open>close and close<low[1]   ) 


//or (    open[1] > close[1] and (high[1]-open[1])>(open[1]-low[1]) and (open[1]-close[1])>(close[1]-low[1]) and open>close and close <low[1]     )   )  //and time(timeframe.period,"2200-1300")
//and (close[1]-open[1])>(open[1]-low[1]) 
//high > ngan and close < ngan and ngan<tb and 
// and time(timeframe.period,"1000-2300")
bgcolor(color = ban ? color.rgb(235, 106, 123) : na)
//bgcolor(color.rgb(82, 255, 154),transp = 100, offset = 1, show_last = 2)
//and time(timeframe.period,"2300-1500") and ((open>ngan and close<ngan) or (open>tren and close<tren))
plotshape(ban , style=shape.arrowdown, location=location.abovebar, color=#ff00ff, size=size.tiny, textcolor=color.rgb(255, 59, 213))
alertcondition(ban, "Ban", "Ban")

mua=  (  open[1]>close[1] and (close[1]-low[1])>(high[1]-close[1]) and close > open and close > high[1]  )  //and time(timeframe.period,"2200-1300")


//or  (  close[1]>open[1] and (open[1]-low[1]) > (high[1]-open[1]) and (close[1]-open[1])>(high[1]-close[1]) and close>open and close>high[1]      ) )
//and (open[1]-close[1])>(high[1]-open[1])
//low < ngan and close > ngan and ngan>tb and
//or  (  close[1]>open[1] and (open[1]-low[1]) > (high[1]-open[1]) and (close[1]-open[1])>(high[1]-close[1]) and close>open and close>high[1]      )

// and time(timeframe.period,"1000-2300")
bgcolor(color= mua? color.rgb(108, 231, 139):na)
//and time(timeframe.period,"2300-1500") and ((open<ngan and close>ngan)or (open<duoi and close>duoi) )
plotshape(mua , style=shape.arrowup, location=location.belowbar, color=#00ff6a, size=size.tiny, textcolor=color.rgb(83, 253, 60))
alertcondition(mua , "Mua", "Mua")


//len1 = ban==true and (high-low)>2*atr
//plotshape(len1 , style=shape.flag, location=location.abovebar, color=#ff00ff, size=size.tiny, title="Sell Signal", text="Xuong 1", textcolor=color.rgb(255, 59, 213))

//bann= ban==true and rsi < marsi and marsi[2]>marsi[1]
//plotshape(bann , style=shape.labeldown, location=location.abovebar, color=#ff00ff, size=size.tiny, title="Sell Signal", text="BAN 2", textcolor=color.rgb(240, 234, 239))

//bannn = mua==true and rsi>marsi and marsi[2]<marsi[1]
//plotshape(bannn , style=shape.labelup, location=location.belowbar, color=#00ff6a, size=size.tiny, title="Buy Signal", text="Mua 2", textcolor=color.rgb(237, 241, 236))

//a1= ban==true and (high - low)<atr 
//plotshape(a1 , style=shape.xcross, location=location.bottom, color=#00ff6a, size=size.tiny, title="Sell", text="<atr", textcolor=color.rgb(240, 95, 76))

//a2 = ban ==true and (high - low)>atr and (high - low)<(2*atr) 
//plotshape(a2 , style=shape.xcross, location=location.bottom, color=#00ff6a, size=size.tiny, title="Sell", text="<2atr", textcolor=color.rgb(237, 241, 236))

//a3= ban==true and (high - low)>(2*atr) 
//plotshape(a3 , style=shape.xcross, location=location.bottom, color=#00ff6a, size=size.tiny, title="Sell", text=">2atr", textcolor=color.rgb(234, 252, 74))


//b1= mua==true and (high - low)<atr 
//plotshape(b1 , style=shape.xcross, location=location.bottom, color=#00ff6a, size=size.tiny, title="Buy", text="<atr", textcolor=color.rgb(237, 241, 236))

//b2 = mua ==true and (high - low)>atr and (high - low)<(2*atr) 
//plotshape(b2 , style=shape.xcross, location=location.bottom, color=#00ff6a, size=size.tiny, title="Buy", text="<2atr", textcolor=color.rgb(237, 241, 236))

//b3= mua==true and (high - low)>(2*atr) 
//plotshape(b3 , style=shape.xcross, location=location.bottom, color=#00ff6a, size=size.tiny, title="Buy", text=">2atr", textcolor=color.rgb(237, 241, 236))

// Đặt SL TP ENTRY
risk= input(title="Rủi ro % per Trade", defval=0.5)
rr= input(title="RR", defval=1.5)
onlylong= input(defval=false)
onlyshort=input(defval=false)

stlong = mua and strategy.position_size<=0 ? low[1]:na
stoplong= fixnan(stlong)

stshort = ban and strategy.position_size>=0 ? high[1]:na
stopshort= fixnan(stshort)

enlong = mua and strategy.position_size<=0 ? close:na
entrylong =fixnan(enlong)

enshort = ban and strategy.position_size>=0 ? close:na
entryshort = fixnan(enshort)

amountL = risk/100* strategy.initial_capital / (entrylong - stoplong)
amountS = risk/100* strategy.initial_capital / (stopshort - entryshort)

TPlong= mua and strategy.position_size<=0? entrylong + (entrylong -stoplong)*rr:na
takeprofitlong =fixnan(TPlong)
TPshort = ban and strategy.position_size>=0? entryshort - (stopshort - entryshort)*rr:na 
takeprofitshort = fixnan(TPshort)

strategy.entry("Long", strategy.long , when = enlong and not onlyshort, qty= amountL )
strategy.exit("exitL", "Long", stop = stoplong, limit= takeprofitlong)

strategy.entry("Short", strategy.short , when = enshort and not onlylong, qty= amountS )
strategy.exit("exitS", "Short", stop = stopshort, limit= takeprofitshort)