
Diese Strategie basiert auf einem Moving Average und kann die Parameter automatisch anpassen. Sie ist für den Markt geeignet, der in hohen Zeiträumen schwankt. Sie ist in der Lage, automatisch die optimale Kombination von Parametern zu finden und ein Handelssignal zu erzeugen, wenn der Preis den Moving Average durchbricht.
Diese Strategie verwendet einen adaptiven Moving Average als Handelssignal. Zuerst wird der einfache Moving Average für die angegebene Periode ((start)) berechnet. Dann wird eine Kombination von Parametern um die CMA getestet, um zu bestimmen, welche Kombination von CMA-Linien am wenigsten von der K-Linien-Einheit und der Schattenlinie berührt wird.
Die Strategie testet die Anzahl der CMA-Linien, der statistischen Einheitslinien und der Schattenlinien, die sie berühren, nach dem CMA-Zyklus plus 1 ((CMA_P1) und minus 1 ((CMA_M1). Wenn die CMA weniger als CMA_P1 und CMA_M1 berührt, bleibt die aktuelle CMA-Zyklus erhalten; wenn die CMA_P1 weniger berührt, werden die CMA-Zyklen plus 1 verwendet; wenn die CMA_M1 weniger berührt, werden die CMA-Zyklen minus 1 verwendet.
Wenn der Preis die CMA von unten nach oben durchbricht, erzeugt er ein Kaufsignal; wenn der Preis die CMA von oben nach unten durchbricht, erzeugt er ein Verkaufsignal.
Diese adaptive Moving-Average-Strategie hat folgende Vorteile:
Automatische Suche nach optimalen Parametern. Die Strategie testet automatisch verschiedene Perioden, um die optimalen Parameter zu finden, ohne die Perioden für die manuelle Auswahl des Moving Averages zu benötigen.
Der Adaptive Moving Average kann mehr Geräusche als der Moving Average mit fester Periode filtern, wodurch viele Falschsignale reduziert werden.
Die Strategie kann sich also dynamisch an die Veränderungen anpassen. Wenn der Markt von der Bilanzierung in eine Trendwende übergeht, werden die Moving-Average-Zyklen automatisch verlängert, um ein Signal zu erzeugen.
Einfachere Handelssysteme. Diese Anpassung kann das gesamte Handelssystem vereinfachen, ohne die Optimierung von Parametern zu benötigen.
Die Strategie kann auf andere Indikatoren übertragen werden, um Strategien zu entwickeln, die sich an Brin-Bands anpassen, an KD anpassen usw.
Es gibt einige Risiken bei dieser Strategie, die beachtet werden müssen:
Das Risiko von Purchase-Optionen. Wenn der Markt Purchase-Optionen aufweist, kann die reale Linie nicht über den Moving Average hinausgehen, was zu falschen Signalen führt. Filterbedingungen müssen hinzugefügt werden, um dieses Risiko zu verringern.
Die Gefahr, dass ein Durchbruch nicht erfolgreich ist. Ein Durchbruch muss überprüft werden, um sicherzustellen, dass der Durchbruch erfolgreich ist.
Trendumkehrrisiken. Ein Trendumkehrrisiko, das nach dem Betreten eines Trendmarkts auftritt, erfordert eine rechtzeitige Umstellung, da dies zu Verlusten führen kann.
Parameteroptimierungsrisiken. Anpassungsbereite Parameter können in die lokale Optimierung fallen, was zu deutlich überflüssigen Moving Averages führt. Modellbewertungsmethoden müssen eingeführt werden, um dieses Problem zu vermeiden.
Überoptimierungsrisiken. Die Anpassungsparameter können überoptimiert werden, wodurch die Allgemeingültigkeit des Modells verloren geht. Es muss lange Zeit in verschiedenen Marktumgebungen überprüft werden und kann nicht übermäßig auf Rückmeldungen angewiesen werden.
Die Strategie des adaptiven Moving Averages kann optimiert werden in folgenden Bereichen:
Trend-Breakout-Verifizierungsmechanismen, um falsche Breakouts durch fortlaufende Breakouts zu filtern.
Eine weitere Stop-Loss-Strategie, bei der der Preis auf der anderen Seite des Moving Averages wieder aufgeht.
Options-Filtermechanismen wurden hinzugefügt, um falsche Signale in der Purchase-Option-Markt zu vermeiden.
Die Einführung von Bewertungskennzahlen, die die Parameteranpassung einschränken, wie IC, LIC, SIC usw., um zu verhindern, dass die Parameter übermäßig optimiert werden.
Ausweitung auf andere Indikatoren, die Entwicklung von Anpassungsstrategien für Goldfork-Totenforken, Anpassungsstrategien für Brin-Bänder usw.
Optimierung der Berechnung von Moving Averages durch Verwendung von Glatten Moving Averages wie Gewichts- und Index-Moving Averages.
Diese Strategie erzeugt Handelssignale, indem sie die Moving Average-Zyklen anpasst und nach den optimalen Parametern sucht. Im Vergleich zu den festen Parametern kann sie viele falsche Signale reduzieren und sich an die Veränderungen des Marktes anpassen.
||
This strategy is based on moving average, can automatically adjust parameters, and is suitable for wavy markets at high timeframes. It can automatically find the optimal parameter combination and generate trading signals when price breaks through the moving average line.
This strategy uses an adaptive moving average as trading signal. First it calculates the simple moving average (CMA) of the specified period (start). Then it tests the CMA parameters around the period, judging which combination has the least touches by candlestick body and wick. Finally it uses the CMA with the least touches as the signal line.
Specifically, the strategy tests the CMA with period plus 1 (CMA_P1) and minus 1 (CMA_M1), counts the number of touches by body and wick. If CMA has less touches than CMA_P1 and CMA_M1, then keep the current period; if CMA_P1 has less touches, then increase the period by 1; if CMA_M1 has less touches, then decrease the period by 1. This finds a relatively smooth CMA as the signal line.
When price breaks through CMA upward, a buy signal is generated; when price breaks through CMA downward, a sell signal is generated.
This adaptive moving average strategy has the following advantages:
Automatically find optimal parameters. No need to manually select moving average period, the strategy will test different periods and find the optimum.
Reduce false signals. Compared with fixed period MA, the adaptive MA can filter out more noise and reduce many false signals.
Adapt to market changes. When market switches from range-bound to trending, the MA period will automatically increase to generate signals; when market switches from trending to range-bound, the MA period will automatically decrease. So the strategy can dynamically adapt to market changes.
Simplify trading system. This adaptive method can simplify the whole trading system without manual parameter optimization.
Good scalability. The concept can be applied to other indicators like adaptive Bollinger Bands, adaptive KD etc.
There are also some risks to note for this strategy:
Call option risk. When market has a call option pattern, the candle body may fail to break the MA line, resulting in wrong signals. Filter conditions need to be added to reduce such risk.
Failed breakout risk. MA breakout does not always continuation, some failed breakouts may occur. Breakout validation is needed to ensure high success rate.
Trend reversal risk. Trend reversal after entering the trend needs to be switched timely, otherwise it may cause losses. Stop loss should be set to control the loss.
Parameter optimization risk. Adaptive adjusted parameters may fall into local optimization, resulting in redundant MAs. Model evaluation methods need to be introduced to avoid this problem.
Overfitting risk. Excessive parameter tuning may lead to overfitting and lose the model generalization ability. Prolonged verification in different market environments is needed, not just rely on backtest results.
Some directions to improve this adaptive MA strategy:
Add trend breakout validation via consecutive breakouts to filter false breakouts.
Increase stop loss strategy, stop loss when price moves back to the other side of MA.
Add option filter to avoid wrong signals when call option appears.
Introduce evaluation metrics like IC, LIC, SIC etc. to constrain parameter tuning and prevent overfitting.
Expand to other indicators like adaptive golden cross strategy, adaptive Bollinger Bands etc.
Optimize MA calculation by using weighted MA, exponential MA etc. to get smoother MA.
This strategy generates trading signals by adaptively adjusting the MA period to find optimal parameters. Compared with fixed parameters, it can reduce many false signals and adapt to market changes. But we also need to watch out for potential risks, and do verification and walk-forward optimization before applying it in live trading for steady profits.
[/trans]
/*backtest
start: 2022-11-10 00:00:00
end: 2023-11-16 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/
// © fondDealer96636
//@version=5
strategy('Automatic Moving Average', overlay=true, max_bars_back=201, pyramiding=0, currency=currency.USD, default_qty_type=strategy.cash, default_qty_value=10000, initial_capital=10000)
// input
start = 20
lookback = input(20, "Sensitivity", tooltip="Low (High Sensitivity), High (Low Sensitivity).\n\nAdjust according to timeframe and asset.")
smoothing = input(3, "Smoothing")
source = input(close, "Source")
startYear = input(2020, "Start year")
resp = 1
in_date_range = time >= timestamp(syminfo.timezone, startYear, 1, 1, 0, 0)
// global
var ix = -1
var mal = array.new_int(0)
// functions
avg(source, len) =>
sum = 0.0
for i = 0 to len-1
sum += source[i]
sum/len
bull = close > open
wick_touch(x) =>
bull ? ((close <= x and x <= high) or (low <= x and x <= open)) : ((open <= x and x <= high) or (low <= x and x <= close))
body_touch(x) =>
bull ? (open < x and x < close) : (close < x and x < open)
touches(t) =>
touches = 0
for i = 0 to lookback-1
touches += t[i] ? 1 : 0
touches
// local
ix := ix+1
prev_mal = ix >= 1 ? array.get(mal, ix-1) : start
cma = avg(source, prev_mal)
cma_p1 = avg(source, prev_mal+1)
cma_m1 = avg(source, prev_mal-1)
d = touches(wick_touch(cma))
d_p1 = touches(wick_touch(cma_p1))
d_m1 = touches(wick_touch(cma_m1))
d_b = touches(body_touch(cma))
d_p1_b = touches(body_touch(cma_p1))
d_m1_b = touches(body_touch(cma_m1))
any_body_touch = d_b > 0 or d_p1_b > 0 or d_m1_b > 0
no_wick_touch = d <= 0 and d_p1 <= 0 and d_m1 <= 0
wick_maximized = d >= d_p1 and d >= d_m1 ? prev_mal : (d_p1 >= d and d_p1 >= d_m1 ? prev_mal+resp : (d_m1 >= d and d_m1 >= d_p1 ? prev_mal-resp : na))
up = cma > cma[1]
down = cma < cma[1]
against_trend = (up and close < cma) or (down and close > cma)
new_mal = no_wick_touch or against_trend ? prev_mal-resp : (any_body_touch ? prev_mal+resp : wick_maximized)
next_mal = na(new_mal) ? prev_mal : new_mal
array.push(mal, next_mal < 2 ? 2 : (next_mal > 200 ? 200 : next_mal))
// graph
scma = ta.ema(cma, smoothing)
uptrend = scma > scma[1]
downtrend = scma < scma[1]
plot(scma, "Automatic MA", color=uptrend ? color.green : color.red)
uptrending = close > scma and uptrend
downtrending = close < scma and downtrend
defy = not uptrending and not downtrending
defy_cross = defy and body_touch(scma)
barcolor(uptrending ? color.lime : (downtrending ? color.red : (defy_cross ? color.black : color.white)))
// strategy
change_to_uptrend = uptrending and downtrend[1]
change_to_downtrend = downtrending and uptrend[1]
long = in_date_range and change_to_uptrend
short = in_date_range and change_to_downtrend
if long
strategy.entry("Long", strategy.long)
if short
strategy.entry("Short", strategy.short)