Bidirektionale Long- und Short-Handelsstrategien basierend auf MACD und RSI


Erstellungsdatum: 2023-10-09 15:33:17 zuletzt geändert: 2023-10-09 15:33:17
Kopie: 0 Klicks: 701
1
konzentrieren Sie sich auf
1617
Anhänger

Überblick

Diese Strategie kombiniert MACD und RSI, um bei unklaren Trends zu handeln und gleichzeitig mehr Short-Trade zu tätigen, um zusätzliche Gewinne zu erzielen.

Strategieprinzip

  1. Berechnen Sie die schnelle EMA (Line 12) und die langsame EMA (Line 26)
  2. Berechnung der MACD-Konvergenzdifferenz (schnelle EMA minus langsame EMA)
  3. Berechnen Sie den 9-Tage-Moving Average des MACD als Signallinie
  4. 14 Tage RSI berechnet
  5. Wenn der MACD <-0.1 ist, der RSI <27 und der schnelle EMA niedriger ist als der langsame EMA, machen Sie mehr
  6. Kurzschluss, wenn MACD>0.125 und RSI>81 und der schnelle EMA höher ist als der langsame EMA
  7. Setzen Sie Stop, Stop und Move Stop, um Ihre Positionen zu verwalten

Analyse der Stärken

  1. Der Trend ist nicht nur ein Trend, sondern auch ein Trend.
  2. In Kombination mit dem Trend-Indikator EMA und dem Reversal-Indikator RSI kann die Signalqualität verbessert werden
  3. Die Verwendung von mobilen Stop-Losses zur Gewinnschließung kann das Risiko von Verlusten wirksam kontrollieren

Risikoanalyse

  1. Zwei-Wege-Transaktionen benötigen mehr Geld, um die Sicherheiten zu unterstützen.
  2. Der Markt ist in der Lage, seine offenen Positionen zu beenden, wenn sich die Situation drastisch verändert.
  3. Fehlende Parameter können zu häufigen Transaktionen führen

Die Risiken können auf folgende Weise gelöst werden:

  1. Genügend finanzielle Unterstützung und Kontrolle der Positionsgröße
  2. Rationalisierte Stop-Distanz, um zu starke Stopps zu vermeiden
  3. Optimierung der Parameter und Verringerung der Handelsfrequenz

Optimierungsrichtung

  1. Einführung in die Börse kann in Kombination mit Volatilitätsindikatoren in Betracht gezogen werden.
  2. Verschiedene Parameterkombinationen können getestet werden, um die besten Parameter zu finden
  3. Optimierung von Stop-Loss-Strategien, wie z. B. Trailing Stop, je nach Marktbedingungen
  4. Automatische Optimierungsparameter, die mit einem Machine Learning-Algorithmus kombiniert werden können

Zusammenfassen

Diese Strategie ermöglicht den Bindetraining durch die Kombination von MACD und RSI. Die Strategie nutzt mobile Stop-Losses, um Gewinne zu sichern, und kann in nicht-trendenden Situationen überschüssige Gewinne erzielen. Die Strategie kann die Parameter-Setting, die Stop-Loss-Strategie usw. weiter optimieren, um überschüssige Gewinne zu erzielen.

Strategiequellcode
/*backtest
start: 2023-09-08 00:00:00
end: 2023-10-08 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=3
// Revision:        290
// Author:          @Hugo_Moriceau
//study("Moriceau_Crypto_strategies_Long_short_indicator_thesis",overlay=true)

// Pyramide 10 order size 100, every tick

strategy("Moriceau_Crypto_strategies_Long_short_indicator",overlay=true)

// === GENERAL INPUTS ===

fast = 12, slow = 26
fastMA = ema(close, fast)
slowMA = ema(close, slow)

macd = fastMA - slowMA
signal = sma(macd, 9)
rsi = rsi(close,14)

dataB = macd < -0.1  and rsi<27 and fastMA < slowMA
// data1 = macd > 0.125  and rsi>81 and fastMA> slowMA
dataS = macd > 0.125 and rsi > 81 and fastMA > slowMA

tradeInvert     = input(defval = false, title = "Invert Trade Direction?")

// === LOGIC ===

// is fast ma above slow ma?
Achat = macd < -0.1  and rsi < 27 and fastMA < slowMA ? true : false
vente = macd > 0.125 and rsi > 81 and fastMA > slowMA ? true : false

// are we inverting our trade direction?
tradeDirection = vente ? Achat ? false : true : Achat ? true : false

// === Plot Setting ===

plot(fastMA,color=red)
plot(slowMA,color=blue)
barcolor(color=iff(fastMA > slowMA, yellow, na))
barcolor(color=iff(fastMA < slowMA, black, na))
//barcolor(color=iff(macd > 0.12*close , fuchsia, na))
//barcolor(color=iff(macd < -0.1*close , lime, na))
plotchar(dataB, char='B',color=black,size = size.auto,location = location.belowbar,transp= 0)  
plotchar(dataS, char='S',color=black,size = size.auto,location = location.abovebar,transp= 0)

//fast = plot(maFast, title = "FastMA", color = yellow, linewidth = 2, style = line, transp = 50)
//slow = plot(maSlow, title = "SlowMA", color = black, linewidth = 2, style = line, transp = 50)

// === BACKTEST RANGE ===
FromMonth = input(defval = 05, title = "From Month", minval = 1)
FromDay   = input(defval = 23, title = "From Day", minval = 1)
FromYear  = input(defval = 2021, title = "From Year", minval = 2017)
ToMonth   = input(defval = 5, title = "To Month", minval = 1)
ToDay     = input(defval = 25, title = "To Day", minval = 1)
ToYear    = input(defval = 2021, title = "To Year", minval = 2017)


// === STRATEGY RELATED INPUTS ===+
// the risk management inputs
inpTakeProfit   = input(defval = 2500, title = "Take Profit", minval = 28)
inpStopLoss     = input(defval = 600, title = "Stop Loss", minval = 15)
inpTrailStop    = input(defval = 300, title = "Trailing Stop Loss", minval = 5)
inpTrailOffset  = input(defval = 50, title = "Trailing Stop Loss Offset", minval = 1)

// === RISK MANAGEMENT VALUE PREP ===

// if an input is less than 1, assuming not wanted so we assign 'na' value to disable it.

useTakeProfit   = inpTakeProfit  >= 1 ? inpTakeProfit  : na
useStopLoss     = inpStopLoss    >= 1 ? inpStopLoss    : na
useTrailStop    = inpTrailStop   >= 1 ? inpTrailStop   : na
useTrailOffset  = inpTrailOffset >= 1 ? inpTrailOffset : na


// === STRATEGY - LONG POSITION EXECUTION ===

enterLong() => not tradeDirection[1] and tradeDirection 
exitLong() => tradeDirection[1] and not tradeDirection
strategy.entry(id = "Achat", long = true, when = enterLong()) // use function or simple condition to decide when to get in
strategy.close(id = "TP 50% Sell", when = exitLong()) // ...and when to get out

// === STRATEGY - SHORT POSITION EXECUTION ===

enterShort() => tradeDirection[1] and not tradeDirection
exitShort() => not tradeDirection[1] and tradeDirection
strategy.entry(id = "Vente", long = false, when = enterShort())
strategy.close(id = "Vente", when = exitShort())

// === STRATEGY RISK MANAGEMENT EXECUTION ===

// finally, make use of all the earlier values we got prepped
strategy.exit("Vente", from_entry = "Vente", profit = useTakeProfit, loss = useStopLoss, trail_points = useTrailStop, trail_offset = useTrailOffset)
strategy.exit("Short", from_entry = "Achat", profit = useTakeProfit, loss = useStopLoss, trail_points = useTrailStop, trail_offset = useTrailOffset)