Strategie für die Mittelverlagerung der CCI

Schriftsteller:ChaoZhang, Datum: 2023-11-01 16:20:45
Tags:

img

Übersicht

Diese Strategie ist als flexibles Trend-Folge-Handelssystem auf Basis des CCI-Indikators konzipiert. Sie kann Handelssignale auf Basis von CCI-Nulllinie-Kreuzungen oder benutzerdefinierten Ober-/Unterband-Kreuzungen generieren. Die Strategie ermöglicht die Festsetzung von Fix-Stop-Loss- und Take-Profit-Verhältnissen, den Handel in bestimmten Zeitrahmen und mehr.

Strategie Logik

  1. Bei der Ermittlung der Marktentwicklung werden Null-Linienkreuzungen des CCI verwendet.

  2. CCI-Kreuzung über dem oberen Band ist bullisch und Kreuzung unter dem unteren Band ist bärisch. Band-Crossovers fungieren als Stops.

  3. Option, nur in bestimmten Zeitrahmen zu handeln und alle Positionen außerhalb dieser Zeiträume zu schließen.

  4. Setzen Sie festgelegte Stop-Loss- und Gewinnprozentsätze.

  5. Anpassbare Warnmeldungen für Ein- und Ausstiegssignale.

  6. Eine sehr anpassungsfähige Strategie mit einstellbaren CCI-Parametern, Bands, Stopps usw.

Analyse der Vorteile

  1. Die CCI ist auf Preisänderungen empfindlich und ist gut geeignet, um Trendumkehrungen zu erkennen.

  2. Die individuellen Bands können für verschiedene Märkte angepasst werden.

  3. Unterstützung des Handels in verschiedenen Zeitrahmen mit optimierten Parametern auf der Grundlage von Merkmalen.

  4. Festgelegte Stop-Loss-/Take-Profit-Risiko-/Rendite-Verhältnisse und Grenzrisiko.

  5. Vollständig anpassbare Parameter optimieren die Strategie für verschiedene Produkte und Marktbedingungen.

Risikoanalyse

  1. Die CCI, die anfällig für falsche Signale sind, sollten Signale mit längeren Zeitrahmenindikatoren überprüfen.

  2. Festgelegte Stop/Take-Prozentsätze können sich nicht an veränderte Marktbedingungen anpassen.

  3. Der Handel in festen Zeitrahmen birgt das Risiko, dass in den Intervallperioden Chancen verpasst werden.

  4. Häufige Optimierungen von Parametern können zu Über- oder Fehlgeschäften führen.

  5. Es sind Makrofaktoren zu berücksichtigen, da die Optimierung allein nicht ausreicht, um Risiken zu beseitigen.

Optimierungsrichtlinien

  1. Hinzufügen von längeren Zeitrahmenindikatoren zur Überprüfung von CCI-Signalen.

  2. Einbeziehung dynamischer Stopps/Takes wie ATR.

  3. Testparameter in unterschiedlichen Zeitrahmen und Ermittlung hocheffizienter Zeiträume.

  4. Optimierung der CCI-Parameter und -Bänder für sich ändernde Märkte.

  5. Sie sollten auch andere Faktoren wie Volatilität und Volumen berücksichtigen.

  6. Wählen Sie die für die gehandelten Produkte geeigneten Zeitrahmen aus.

  7. Betrachten Sie maschinelles Lernen, um Strategieoptimierungen zu automatisieren.

Zusammenfassung

Insgesamt ist dies ein sehr flexibles und anpassbares Trendfolgensystem. Die wichtigsten Vorteile sind die Verwendung von CCI für Trends, benutzerdefinierte Bands zur Begrenzung des Risikos, feste Stopps / Takes und Zeitrahmenwahl. Es muss auf falsche CCI-Signale und unflexible Stops geachtet werden. Zukünftige Verbesserungen könnten durch die Optimierung von Parametern, das Filtern von Signalen, die Auswahl effizienter Zeitrahmen und die Einbeziehung von maschinellem Lernen für automatische Anpassungen an Marktveränderungen erzielt werden, um eine konsistentere Überzinsung zu erzielen.


/*backtest
start: 2023-10-01 00:00:00
end: 2023-10-31 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/
// © REV0LUTI0N

//@version=4

strategy(title="CCI Strategy", overlay=true, initial_capital = 10000, default_qty_value = 10000, default_qty_type = strategy.cash)


//CCI Code

length = input(20, minval=1, title="CCI Length")
src = input(close, title="Source")
ma = sma(src, length)
cci = (src - ma) / (0.015 * dev(src, length))


// Strategy Backtesting
startDate  = input(timestamp("2099-10-01T00:00:00"), type = input.time, title='Backtesting Start Date')
finishDate = input(timestamp("9999-12-31T00:00:00"), type = input.time, title='Backtesting End Date')

time_cond  = true


//Time Restriction Settings
startendtime = input("", title='Time Frame To Enter Trades')
enableclose = input(false, title='Enable Close Trade At End Of Time Frame')
timetobuy = true
timetoclose = true


//Strategy Settings

//Strategy Settings - Enable Check Boxes
enableentry = input(true, title="Enter First Trade ASAP")
enableconfirmation = input(false, title="Wait For Cross To Enter First Trade")
enablezero =input(true, title="Use CCI Simple Cross Line For Entries & Exits")
enablebands = input(false, title="Use Upper & Lower Bands For Entries & Exits")

//Strategy Settings - Band Sources
ccisource = input(0, title="CCI Simple Cross")
upperbandsource =input(100, title="CCI Enter Long Band")
upperbandexitsource =input(100, title="CCI Exit Long Band")
lowerbandsource =input(-100, title="CCI Enter Short Band")
lowerbandexitsource =input(-100, title="CCI Exit Short Band")

//Strategy Settings - Crosses
simplecrossup = crossover(cci, ccisource)
simplecrossdown = crossunder(cci, ccisource)
uppercrossup = crossover(cci, upperbandsource)
lowercrossdown = crossunder(cci, lowerbandsource)
uppercrossdown = crossunder(cci, upperbandexitsource)
lowercrossup = crossover(cci, lowerbandexitsource)
upperstop = crossunder(cci, upperbandsource)
lowerstop = crossover(cci, lowerbandsource)


// Stop Loss & Take Profit % Based
enablesl = input(false, title='Enable Stop Loss')
enabletp = input(false, title='Enable Take Profit')
stopTick = input(5.0, title='Stop Loss %', type=input.float, step=0.1) / 100
takeTick = input(10.0, title='Take Profit %', type=input.float, step=0.1) / 100

longStop = strategy.position_avg_price * (1 - stopTick)
shortStop = strategy.position_avg_price * (1 + stopTick)
shortTake = strategy.position_avg_price * (1 - takeTick)
longTake = strategy.position_avg_price * (1 + takeTick)

plot(strategy.position_size > 0 and enablesl ? longStop : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Long Fixed SL")
plot(strategy.position_size < 0 and enablesl ? shortStop : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Short Fixed SL")
plot(strategy.position_size > 0 and enabletp ? longTake : na, style=plot.style_linebr, color=color.green, linewidth=1, title="Long Take Profit")
plot(strategy.position_size < 0 and enabletp ? shortTake : na, style=plot.style_linebr, color=color.green, linewidth=1, title="Short Take Profit")


// Alert messages
message_enterlong  = input("", title="Long Entry message")
message_entershort = input("", title="Short Entry message")
message_closelong = input("", title="Close Long message")
message_closeshort = input("", title="Close Short message")
    

//Strategy Execution

//Strategy Execution - Simple Line Cross
if (cci > ccisource and enablezero and enableentry and time_cond and timetobuy)
    strategy.entry("Long", strategy.long, alert_message = message_enterlong)
if (cci < ccisource and enablezero and enableentry and time_cond and timetobuy)
    strategy.entry("Short", strategy.short, alert_message = message_entershort)

if (simplecrossup and enablezero and enableconfirmation and time_cond and timetobuy)
    strategy.entry("Long", strategy.long, alert_message = message_enterlong)
if (simplecrossdown and enablezero and enableconfirmation and time_cond and timetobuy)
    strategy.entry("Short", strategy.short, alert_message = message_entershort)

//Strategy Execution - Upper and Lower Band Entry
if (uppercrossup and enablebands and time_cond and timetobuy)
    strategy.entry("Long", strategy.long, alert_message = message_enterlong)
if (lowercrossdown and enablebands and time_cond and timetobuy)
    strategy.entry("Short", strategy.short, alert_message = message_entershort)

//Strategy Execution - Upper and Lower Band Exit
if strategy.position_size > 0 and uppercrossdown and enablebands and time_cond and timetobuy
    strategy.close_all(alert_message = message_closelong)
if strategy.position_size < 0 and lowercrossup and enablebands and time_cond and timetobuy
    strategy.close_all(alert_message = message_closeshort)

//Strategy Execution - Upper and Lower Band Stops
if strategy.position_size > 0 and upperstop and enablebands and time_cond and timetobuy
    strategy.close_all(alert_message = message_closelong)
if strategy.position_size < 0 and lowerstop and enablebands and time_cond and timetobuy
    strategy.close_all(alert_message = message_closeshort)

//Strategy Execution - Close Trade At End Of Time Frame    
if strategy.position_size > 0 and timetoclose and enableclose and time_cond
    strategy.close_all(alert_message = message_closelong)
if strategy.position_size < 0 and timetoclose and enableclose and time_cond
    strategy.close_all(alert_message = message_closeshort)

//Strategy Execution - Stop Loss and Take Profit
if strategy.position_size > 0 and enablesl and time_cond
    strategy.exit(id="Close Long", stop=longStop, limit=longTake, alert_message = message_closelong)
if strategy.position_size < 0 and enablesl and time_cond
    strategy.exit(id="Close Short", stop=shortStop, limit=shortTake, alert_message = message_closeshort)
    
if strategy.position_size > 0 and enabletp and time_cond
    strategy.exit(id="Close Long", stop=longStop, limit=longTake, alert_message = message_closelong)
if strategy.position_size < 0 and enabletp and time_cond
    strategy.exit(id="Close Short", stop=shortStop, limit=shortTake, alert_message = message_closeshort)



Mehr