
動的移動平均クロスオーバーコンボ戦略 (Dynamic Moving Average Crossover Combo Strategy) は,複数の技術指標と市場段階の検出を統合した複合取引戦略である.それは,市場の波動性を動的に計算し,価格と長期移動平均との距離と波動性に基づいて市場の3段階を判断する. 震動,トレンド,整理. 戦略は,異なる市場段階において,異なる入場出場ルールを採用し,同時に,EMA/SMA交差,MACD,およびBollinger Bandsなどの複数の指標を組み合わせて,買入と売り出しの信号を発する.
ATR (平均実際の波動幅度) を用いて,最近14日の市場内日波動を計算する.それから100日間のシンプル移動平均を波して,平均波動性を得する.
価格が200日単調移動平均の相対距離を計算する.距離が平均波動性の1.5倍を超え,方向が明確である場合は,トレンド状態として判断する.現在の波動性が平均波動性の1.5倍を超えれば,震動状態として判断する.
急速EMAは10日周期で,緩慢SMAは30日周期である。 急速EMA上での緩慢SMAの穿越時,買取信号が生成される。
パラメータ12,26,9のMACDを計算する.MACD列が正値に変化すると買取信号が生成される.
20日間の標準差チャネルを計算する.チャネル幅が20日間のSMAより小さい場合は,整理期として判断する.
振動期: 線が横切ったり,MACD柱が正し,閉盤価格がBollinger Bands内にある場合,入場は多めにする。
トレンド期: 線交差やMACD柱の正規変遷が多く発生する.
整理期: 線が交差し,閉店価格がLower Bandより高い場合,入場が多くなること.
次の条件を満たす場合,平仓に出場する:MACDは連続して2つのKラインが負であり,閉盘価格は2日連続で下落した.
ストック期間:また,StockRSIが超買い領域に入るときに出場する.
編集期:Upper Bandより価格が低いときに出演する.
市場環境の判断と組み合わせたスマートな取引戦略で,以下の利点があります.
システム化して主観的な介入を減らす
市場環境の調整戦略のパラメータと組み合わせると,より適応性がある.
マルチ指標の組み合わせにより,信号の確実性を高めます.
Bollinger Bandsの自動ストップは,リスクを低減する.
偽信号をフィルターする.
ダイナミックストップ・ローズ・ストップ・ストップ,トレンド・トラッキング・トレンド・トレンド.
主なリスクは以下の通りです.
パラメータ設定を誤って設定すると,策略が失敗する可能性があります. パラメータの組み合わせを最適化することをお勧めします.
突発的な出来事がモデルに障害をもたらした. 戦略の論理を更新することをお勧めします.
取引料金を圧縮して利益を得るスペース。 低手数料券商を選ぶことを推奨。
多指標の組み合わせは戦略の複雑さを高めます. 核心指標を選択することをお勧めします.
更に,次の次元から最適化できます.
市場環境の判断基準を最適化し,正確性を向上させる.
機械学習モジュールを追加し,パラメータの自己適応を実現する.
テキスト処理と組み合わせて重大事件のリスクを判断する.
マルチマーケットの反省で,最適な組み合わせのパラメータを探します.
トレーリングストップの策略
動的移動平均の交差組合せ戦略は,多指標のスマート取引戦略である.市場環境の調整パラメータを組み合わせて,条件判断型の体系化された取引を実現できる.強い適応性と確実性がある.しかし,パラメータ設定と新しいモジュールの両方が,戦略の複雑さを増加させないように慎重に注意する必要がある.全体的に,これは強力な可行性のある量化戦略の考え方である.
/*backtest
start: 2024-01-28 00:00:00
end: 2024-02-04 00:00:00
period: 10m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Improved Custom Strategy", shorttitle="ICS", overlay=true)
// Volatility
volatility = ta.atr(14)
avg_volatility_sma = ta.sma(volatility, 100)
avg_volatility = na(avg_volatility_sma) ? 0 : avg_volatility_sma
// Market Phase detection
long_term_ma = ta.sma(close, 200)
distance_from_long_term_ma = close - long_term_ma
var bool isTrending = math.abs(distance_from_long_term_ma) > 1.5 * avg_volatility and not na(distance_from_long_term_ma)
var bool isVolatile = volatility > 1.5 * avg_volatility
// EMA/MA Crossover
fast_length = 10
slow_length = 30
fast_ma = ta.ema(close, fast_length)
slow_ma = ta.sma(close, slow_length)
crossover_signal = ta.crossover(fast_ma, slow_ma)
// MACD
[macdLine, signalLine, macdHistogram] = ta.macd(close, 12, 26, 9)
macd_signal = crossover_signal or (macdHistogram > 0)
// Bollinger Bands
source = close
basis = ta.sma(source, 20)
upper = basis + 2 * ta.stdev(source, 20)
lower = basis - 2 * ta.stdev(source, 20)
isConsolidating = (upper - lower) < ta.sma(upper - lower, 20)
// StockRSI
length = 14
K = 100 * (close - ta.lowest(close, length)) / (ta.highest(close, length) - ta.lowest(close, length))
D = ta.sma(K, 3)
overbought = 75
oversold = 25
var float potential_SL = na
var float potential_TP = na
var bool buy_condition = na
var bool sell_condition = na
// Buy and Sell Control Variables
var bool hasBought = false
var bool hasSold = true
// Previous values tracking
prev_macdHistogram = macdHistogram[1]
prev_close = close[1]
// Modify sell_condition with the new criteria
if isVolatile
buy_condition := not hasBought and crossover_signal or macd_signal and (close > lower) and (close < upper)
sell_condition := hasBought and (macdHistogram < 0 and prev_macdHistogram < 0) and (close < prev_close and prev_close < close[2])
potential_SL := close - 0.5 * volatility
potential_TP := close + volatility
if isTrending
buy_condition := not hasBought and crossover_signal or macd_signal
sell_condition := hasBought and (macdHistogram < 0 and prev_macdHistogram < 0) and (close < prev_close and prev_close < close[2])
potential_SL := close - volatility
potential_TP := close + 2 * volatility
if isConsolidating
buy_condition := not hasBought and crossover_signal and (close > lower)
sell_condition := hasBought and (close < upper) and (macdHistogram < 0 and prev_macdHistogram < 0) and (close < prev_close and prev_close < close[2])
potential_SL := close - 0.5 * volatility
potential_TP := close + volatility
// Update the hasBought and hasSold flags
if buy_condition
hasBought := true
hasSold := false
if sell_condition
hasBought := false
hasSold := true
// Strategy Entry and Exit
if buy_condition
strategy.entry("BUY", strategy.long, stop=potential_SL, limit=potential_TP)
strategy.exit("SELL_TS", from_entry="BUY", trail_price=close, trail_offset=close * 0.05)
if sell_condition
strategy.close("BUY")
// Visualization
plotshape(series=buy_condition, style=shape.labelup, location=location.belowbar, color=color.green, text="BUY", size=size.small)
plotshape(series=sell_condition, style=shape.labeldown, location=location.abovebar, color=color.red, text="SELL", size=size.small)
plot(long_term_ma, color=color.gray, title="200-Day MA", linewidth=1)
plot(potential_SL, title="SL Level", color=color.red, linewidth=1, style=plot.style_linebr)
plot(potential_TP, title="TP Level", color=color.green, linewidth=1, style=plot.style_linebr)
bgcolor(isVolatile ? color.new(color.purple, 90) : isTrending ? color.new(color.blue, 90) : isConsolidating ? color.new(color.orange, 90) : na)