Indice combiné de convergence moyenne exponentielle triple et de force relative Tableau de 1 minute Stratégie de négociation quantitative de crypto-monnaie

Auteur:ChaoZhang est là., Date: 2024-03-29 11:16:10 Je vous en prie.
Les étiquettes:

img

Résumé

Cette stratégie combine les méthodes Triple Exponential Moving Average Convergence Divergence (Triple MACD) et Relative Strength Index (RSI), spécialement conçues pour la négociation quantitative sur le marché des crypto-monnaies sur un laps de temps de 1 minute. L'idée principale derrière la stratégie est de capturer les changements de dynamique haussière et baissière en utilisant les indicateurs MACD avec différents paramètres de période, tout en utilisant l'indicateur RSI pour confirmer la force de la tendance. En faisant la moyenne des trois signaux MACD, le bruit peut être efficacement lissé, améliorant la fiabilité des signaux de trading.

Principes de stratégie

La stratégie utilise trois indicateurs MACD avec des paramètres différents: des périodes de ligne rapide de 5/13/34 et des périodes de ligne lente de 8/21/144. Elle calcule la différence entre eux pour obtenir les valeurs MACD. Ces trois valeurs MACD sont ensuite moyennées, et l'histogramme MACD final est dérivé en soustrayant la valeur du signal (EMA de la période N de MACD) de la moyenne MACD. Simultanément, un indicateur RSI de 14 périodes est calculé pour aider à déterminer la force de la tendance. Un signal long est généré lorsque l'histogramme MACD moyen passe de négatif à positif, le RSI est inférieur à 55, et il y a un alignement haussier. Inversement, un signal de fermeture est déclenché lorsque l'histogramme MACD moyen passe de positif à négatif, le RSI est supérieur à 45, et il y a une stratégie d'alignement.

Analyse des avantages

  1. La combinaison d'indicateurs MACD à plusieurs périodes reflète objectivement les changements de tendance sur le marché à différentes échelles de temps, ce qui améliore la précision de l'identification des tendances.
  2. L'intégration du MACD avec l'indicateur RSI crée des conditions d'entrée et de sortie strictes, ce qui contribue à améliorer la rentabilité de la stratégie et à contrôler le prélèvement.
  3. La moyenne des signaux MACD élimine efficacement les faux signaux causés par des oscillations fréquentes de l'indicateur, ce qui rend les signaux de trading plus fiables.
  4. L'utilisation de la régression linéaire pour déterminer les marchés en évolution permet d'éviter d'entrer dans des transactions pendant les marchés oscillants lorsque la tendance n'est pas claire, ce qui réduit les transactions perdantes.
  5. Dans le marché des crypto-monnaies qui évolue rapidement, une stratégie de négociation quantitative de niveau 1 minute est mieux placée pour saisir rapidement les opportunités de négociation découlant des fluctuations du marché.

Analyse des risques

  1. La stratégie fonctionne mieux sur les marchés à tendance unidirectionnelle. Si le marché reste dans un état d'oscillation de large portée pendant une période prolongée, les signaux de trading peuvent souvent devenir invalides.
  2. En raison de la forte volatilité du marché des crypto-monnaies, des fluctuations anormales extrêmes à court terme peuvent entraîner des retraits importants.
  3. La sélection des paramètres de la stratégie a un impact clair sur la rentabilité globale. Des paramètres incorrects peuvent entraîner l'échec de la stratégie. Par conséquent, une optimisation suffisante des paramètres et une vérification des tests antérieurs pour différents instruments de négociation sont nécessaires avant la négociation en direct.

Directions d'optimisation

  1. Il convient d'envisager l'introduction d'indicateurs liés à la volatilité des prix, tels que l'ATR, pour filtrer les signaux d'entrée et réduire les pertes potentielles causées par des fluctuations anormales du marché.
  2. En plus de la régression linéaire, d'autres méthodes telles que les niveaux de support et de résistance, les canaux de bandes de Bollinger, etc., peuvent être explorées pour améliorer davantage la précision de l'identification des marchés à fourchette.
  3. Dans les marchés de tendance, introduisez un stop-loss pour optimiser les points de sortie, maximisant le profit de chaque transaction.
  4. Compte tenu des différences caractéristiques entre les différents instruments de négociation, établir des paramètres de stratégie différents pour les différents instruments afin d'améliorer l'adaptabilité et la stabilité de la stratégie globale.

Résumé

Cette stratégie combine habilement le triple MACD avec l'indicateur RSI et utilise des techniques de régression linéaire pour identifier les marchés de gamme, formant un ensemble complet de stratégies de trading quantitatives à haute fréquence. Les conditions d'entrée et de sortie strictes et l'application de signaux MACD moyens contribuent à améliorer la précision des transactions et le contrôle du retrait. Bien que la stratégie fonctionne mieux sur les marchés de tendance unidirectionnelle, des mesures telles que l'introduction de filtres de volatilité, l'optimisation des méthodes d'identification des marchés de gamme, la définition de stop-loss et l'établissement de paramètres indépendants pour différents instruments peuvent encore améliorer l'adaptabilité et la robustesse de la stratégie.


/*backtest
start: 2023-03-23 00:00:00
end: 2024-03-28 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy(title="TrippleMACD", shorttitle="TrippleMACD + RSI strategy", format=format.price, precision=4, overlay=true)

// RSI 
ma(source, length, type) =>
    switch type
        "SMA" => ta.sma(source, length)
        "Bollinger Bands" => ta.sma(source, length)
        "EMA" => ta.ema(source, length)
        "SMMA (RMA)" => ta.rma(source, length)
        "WMA" => ta.wma(source, length)
        "VWMA" => ta.vwma(source, length)

rsiLengthInput = input.int(14, minval=1, title="RSI Length", group="RSI Settings")
rsiSourceInput = input.source(close, "Source", group="RSI Settings")
maTypeInput = input.string("SMA", title="MA Type", options=["SMA", "Bollinger Bands", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="MA Settings")
maLengthInput = input.int(14, title="MA Length", group="MA Settings")
bbMultInput = input.float(2.0, minval=0.001, maxval=50, title="BB StdDev", group="MA Settings")
showDivergence = input.bool(false, title="Show Divergence", group="RSI Settings")

up = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)
down = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
rsiMA = ma(rsi, maLengthInput, maTypeInput)
isBB = maTypeInput == "Bollinger Bands"

bbUpperBand = plot(isBB ? rsiMA + ta.stdev(rsi, maLengthInput) * bbMultInput : na, title = "Upper Bollinger Band", color=color.green)
bbLowerBand = plot(isBB ? rsiMA - ta.stdev(rsi, maLengthInput) * bbMultInput : na, title = "Lower Bollinger Band", color=color.green)

// Divergence
lookbackRight = 5
lookbackLeft = 5
rangeUpper = 60
rangeLower = 5
bearColor = color.red
bullColor = color.green
textColor = color.white
noneColor = color.new(color.white, 100)

plFound = na(ta.pivotlow(rsi, lookbackLeft, lookbackRight)) ? false : true
phFound = na(ta.pivothigh(rsi, lookbackLeft, lookbackRight)) ? false : true
_inRange(cond) =>
	bars = ta.barssince(cond == true)
	rangeLower <= bars and bars <= rangeUpper

//------------------------------------------------------------------------------
// Regular Bullish
// rsi: Higher Low

rsiHL = rsi[lookbackRight] > ta.valuewhen(plFound, rsi[lookbackRight], 1) and _inRange(plFound[1])

// Price: Lower Low

priceLL = low[lookbackRight] < ta.valuewhen(plFound, low[lookbackRight], 1)
bullCondAlert = priceLL and rsiHL and plFound
bullCond = showDivergence and bullCondAlert

// rsi: Lower High

rsiLH = rsi[lookbackRight] < ta.valuewhen(phFound, rsi[lookbackRight], 1) and _inRange(phFound[1])

// Price: Higher High

priceHH = high[lookbackRight] > ta.valuewhen(phFound, high[lookbackRight], 1)

bearCondAlert = priceHH and rsiLH and phFound
bearCond = showDivergence and bearCondAlert

// Getting inputs
stopLuse          = input(1.040)
fast_length = input(title = "Fast Length", defval = 5)
slow_length = input(title = "Slow Length", defval = 8)
fast_length2 = input(title = "Fast Length2", defval = 13)
slow_length2 = input(title = "Slow Length2", defval = 21)
fast_length3 = input(title = "Fast Length3", defval = 34)
slow_length3 = input(title = "Slow Length3", defval = 144)
fast_length4 = input(title = "Fast Length3", defval = 68)
slow_length4 = input(title = "Slow Length3", defval = 288)
src = input(title = "Source", defval = close)
signal_length2 = input.int(title="Signal Smoothing", minval = 1, maxval = 200, defval = 11)
signal_length = input.int(title = "Signal Smoothing",  minval = 1, maxval = 50, defval = 9)
sma_source = input.string(title = "Oscillator MA Type",  defval = "EMA", options = ["SMA", "EMA"])
sma_signal = input.string(title = "Signal Line MA Type", defval = "EMA", options = ["SMA", "EMA"])
// Calculating
fast_ma = sma_source == "SMA" ? ta.sma(src, fast_length) : ta.ema(src, fast_length)
slow_ma = sma_source == "SMA" ? ta.sma(src, slow_length) : ta.ema(src, slow_length)

fast_ma2 = sma_source == "SMA2" ? ta.sma(src, fast_length2) : ta.ema(src, fast_length2)
slow_ma2 = sma_source == "SMA2" ? ta.sma(src, slow_length2) : ta.ema(src, slow_length2)

fast_ma3 = sma_source == "SMA3" ? ta.sma(src, fast_length3) : ta.ema(src, fast_length3)
slow_ma3 = sma_source == "SMA3" ? ta.sma(src, slow_length3) : ta.ema(src, slow_length3)

fast_ma4 = sma_source == "SMA3" ? ta.sma(src, fast_length3) : ta.ema(src, fast_length3)
slow_ma4 = sma_source == "SMA3" ? ta.sma(src, slow_length3) : ta.ema(src, slow_length3)

macd = fast_ma - slow_ma
macd2 = fast_ma2 - slow_ma2
macd3 = fast_ma3 - slow_ma3
macd4 = fast_ma4 - slow_ma4

signal = sma_signal == "SMA" ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length)
signal2 = sma_signal == "SMA" ? ta.sma(macd2, signal_length) : ta.ema(macd2, signal_length)
signal3 = sma_signal == "SMA" ? ta.sma(macd3, signal_length) : ta.ema(macd3, signal_length)
signal4 = sma_signal == "SMA" ? ta.sma(macd4, signal_length) : ta.ema(macd4, signal_length)
//hist = (macd + macd2 + macd3)/1 - (signal + signal2 + signal3)/1
hist = (macd + macd2 + macd3 + macd4)/4 - (signal + signal2 + signal3 + signal4)/4
signal5 = (signal + signal2 + signal3)/3

sma_signal2 = input.bool(title="Simple MA (Signal Line)", defval=true)

lin_reg = input.bool(title="Lin Reg", defval=true)
linreg_length = input.int(title="Linear Regression Length", minval = 1, maxval = 200, defval = 11)

bopen = lin_reg ? ta.linreg(open, linreg_length, 0) : open
bhigh = lin_reg ? ta.linreg(high, linreg_length, 0) : high
blow = lin_reg ? ta.linreg(low, linreg_length, 0) : low
bclose = lin_reg ? ta.linreg(close, linreg_length, 0) : close

shadow = (bhigh - bclose) + (bopen - blow)
body = bclose - bopen
perc = (shadow/body)
cond2 = perc >=2 and bclose+bclose[1]/2 > bopen+bopen[1]/2

r = bopen < bclose

//signal5 = sma_signal2 ? ta.sma(bclose, signal_length) : ta.ema(bclose, signal_length)
plotcandle(r ? bopen : na, r ? bhigh : na, r ? blow: na, r ? bclose : na, title="LinReg Candles", color= color.green, wickcolor=color.green, bordercolor=color.green, editable= true)
plotcandle(r ? na : bopen, r ? na : bhigh, r ? na : blow, r ? na : bclose, title="LinReg Candles", color=color.red, wickcolor=color.red, bordercolor=color.red, editable= true)
//alertcondition(hist[1] >= 0 and hist < 0, title = 'Rising to falling', message = 'The MACD histogram switched from a rising to falling state')
//alertcondition(hist[1] <= 0 and hist > 0, title = 'Falling to rising', message = 'The MACD histogram switched from a falling to rising state')

green = hist >= 0 ? (hist[1] < hist ? "G" : "GL") : (hist[1] < hist ? "RL" : "R")
Buy = green == "G" and green[1] != "G" and green[1] != "GL" and bopen < bclose and rsi < 55.0 //and not cond2
//StopBuy = (green == "R" or green == "RL" or green == "RL") and bopen > bclose and bopen[1] < bclose[1]
StopBuy = bopen > bclose and bopen[1] < bclose[1] and (green == "G" or green == "GL" or green == "R") and bopen[2] < bclose[2] and bopen[3] < bclose[3]
hists = close[3] < close[2] and close[2] < close[1]
//Buy = green == "RL" and hist[0] > -0.07 and hist[0] < 0.00 and rsi < 55.0 and hists
//StopBuy = green == "GL" or green == "R"
alertcondition(Buy, "Long","Покупка в лонг")
alertcondition(StopBuy, "StopLong","Закрытие сделки")

//hline(0, "Zero Line", color = color.new(#787B86, 50))
plot(hist + (close - (close * 0.03)), title = "Histogram", style = plot.style_line, color = (hist >= 0 ? (hist[1] < hist ? #26A69A : #B2DFDB) : (hist[1] < hist ? #FFCDD2 : #FF5252)))
plotshape(Buy ? low : na, 'Buy', shape.labelup, location.belowbar , color=color.new(#0abe40, 50), size=size.small, offset=0)
plotshape(StopBuy ? low : na, 'Buy', shape.cross, location.abovebar , color=color.new(#be0a0a, 50), size=size.small, offset=0)
plot(macd4  + (close - (close * 0.01)),   title = "MACD",   color = #2962FF)
plot(signal5 + (close - (close * 0.01)), title = "Signal", color = #FF6D00)

plotchar(cond2 , char='↓', color = color.rgb(0, 230, 119), text = "-")

if (Buy)
    strategy.entry("long", strategy.long)

// if (startShortTrade)
//     strategy.entry("short", strategy.short)

profitTarget = strategy.position_avg_price * stopLuse
strategy.exit("Take Profit", "long", limit=profitTarget)
// strategy.exit("Take Profit", "short", limit=profitTarget)

Plus de