
多因子組合せ自在移動平均戦略は,日内線,移動平均線,聚合交差線およびHA均線を同時に使用する複合戦略である.この戦略は,牛市でより高い累積利益を得るためにより多くの取引機会を掘り起こすことを目的としている.
この戦略の核心的な論理は,複数の技術指標を組み合わせて,買入・売却のシグナルを評価し,異なる要因のマッチングの結果に応じて,異なる強さの取引シグナルを与えることです.
具体的には,この戦略で使われる4つの主要な技術指標は以下の通りです.
日内線。策略は日内線の色を使って価格トレンドを判断し,連続した2つの緑の実体HA平均線は買い信号であり,連続した2つの赤の空心HA平均線は空頭信号。
移動平均. 戦略は,同時に,快速,遅速,フィルタリングの3つの異なるパラメータの設定を使用する移動平均. 速い線が遅速線を横切るとき,遅速線が線を横切るとき,買いの信号;逆に,売りの信号. 移動平均は,中長期のトレンドを効果的に判断する.
ストキャスティック指数。この指数は多空交差のタイミングを判断する。%K線が下方向から%D線を突破すると,買入信号;上方向から下方向から突破すると,売出信号。
マッチングスコアメカニズム 以上の複数の要因のマッチング状況に応じて,戦略はスコアメカニズムを採用する.マッチング要因が多くなるほど,対応信号の強さも大きい.
複数の要因を総合的に判断することで,戦略は中短期間でより微妙な取引機会を捉え,牛市で余分な利益を得ることができます.
多因子組合せ移動平均策の最大の利点は,信号の信頼性を高めることです.単一の技術指標は誤信号に容易であり,この策は,複数の指標を組み合わせて使用することで,偽信号の干渉を効果的に減らすことができます.
また,単一の指数に従うよりも,多要素の組み合わせにより取引の勝利率が向上します.牛市では,戦略により高い累積利益を得ることができます.
この戦略の主なリスクは,多因子組合せ自体が戦略の複雑さを増加させるということである.複数の指標のパラメータ設定,頻繁な調整などを同時に考慮する必要がある.
また,熊市では,戦略的なポジションの保持時間が長すぎることがあります. ストップ・ロスを設定しても,大きな損失を回避することは困難です.
さらに,ストキャスティック指数やHA均線などの技術指数は,突発事件の影響を受けやすいため,誤信号を発生し,不必要な損失を引き起こす可能性があります.
この戦略は以下の点で最適化できます.
各指標パラメータの設定を最適化して,最適なパラメータの組み合わせを見つけます.
モデルのトレーニングとパラメータの自己適応モジュールを追加し,パラメータをリアルタイムで最適化します.
ストップ・ローズ戦略を増加させ,最大撤退策を減少させる.
ポジションコントロールモジュールを追加し,市場状況に応じてポジションを動的に調整する.
機械学習アルゴリズムと組み合わせた,多因子評価のニューラルネットワークモデル.
多因子組合せは,移動平均戦略に自律的に適応し,複数の技術指標の優位性を総合的に利用する.この戦略は,信号の質を効果的に高め,牛市で余分な収益を得ることができる.しかし,同時に,戦略の複雑さを増加させ,さらなるテストと最適化が必要である.
/*backtest
start: 2022-12-08 00:00:00
end: 2023-12-14 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/
// © cyrule
//@version=4
strategy("2nd Grade Strategy", overlay=true, shorttitle="2GTS", max_lines_count = 500, max_labels_count = 500, calc_on_every_tick = true, calc_on_order_fills = true, pyramiding = 1, default_qty_type = strategy.percent_of_equity, default_qty_value = 10)
source = input(close, title = "Source")
// **********************
// * Heikin-Ahshi *
// * kudos to garethyeo *
// **********************
showHA = input(true, title = "Show Heikin Ashi?", group = "Heikin Ashi")
ha_open = security(heikinashi(syminfo.tickerid), timeframe.period, open)
ha_high = security(heikinashi(syminfo.tickerid), timeframe.period, high)
ha_low = security(heikinashi(syminfo.tickerid), timeframe.period, low)
ha_close = security(heikinashi(syminfo.tickerid), timeframe.period, close)
bgcolor(iff(showHA and ha_open < ha_close , color.new(#53b987, transp = 92.5), na), title = 'Green HA')
bgcolor(iff(showHA and ha_open >= ha_close, color.new(#eb4d5c, transp = 92.5), na), title = 'Red HA' )
// ******************
// * Moving Average *
// ******************
// MA Settings
showMA = input(true, title = "Show Moving Averages?", group = "Moving Averages")
fastMALength = input(title = "Fast MA Length", minval = 1, step = 1, defval = 20, group = "Moving Averages")
slowMALength = input(title = "Slow MA Length", minval = 1, step = 1, defval = 50, group = "Moving Averages")
maType = input(title = "Moving Average Type", defval = "SMA", options = ["SMA", "EMA", "RMA", "WMA", "VWMA"], group = "Moving Averages")
filterMALength = input(title = "Filter MA Length", minval = 1, step = 1, defval = 200, group = "Moving Averages")
filterMAType = input(title = "Filter MA Type", defval = "EMA", options = ["SMA", "EMA", "RMA", "WMA", "VWMA"], group = "Moving Averages")
// Calculate MA
var float maFast = na
var float maSlow = na
var float maFilter = na
if (maType == "SMA")
maFast := sma(source, fastMALength)
maSlow := sma(source, slowMALength)
if (maType == "EMA")
maFast := ema(source, fastMALength)
maSlow := ema(source, slowMALength)
if (maType == "RMA")
maFast := rma(source, fastMALength)
maSlow := rma(source, slowMALength)
maFilter := rma(source, filterMALength)
if (maType == "WMA")
maFast := wma(source, fastMALength)
maSlow := wma(source, slowMALength)
if (maType == "VWMA")
maFast := vwma(source, fastMALength)
maSlow := vwma(source, slowMALength)
if (filterMAType == "SMA")
maFilter := sma(source, filterMALength)
if (filterMAType == "EMA")
maFilter := ema(source, filterMALength)
if (filterMAType == "RMA")
maFilter := rma(source, filterMALength)
if (filterMAType == "WMA")
maFilter := wma(source, filterMALength)
if (filterMAType == "VWMA")
maFilter := vwma(source, filterMALength)
BiruAtasMerah = (maFast >= maSlow) and (maSlow >= maFilter)
MerahAtasBiru = (maFast <= maSlow) and (maSlow <= maFilter)
// Lukis MA
plot(series = showMA ? maFast : na, color = color.blue, title = "MA Fast")
plot(series = showMA ? maSlow : na, color = color.red, title = "MA Slow")
plot(series = showMA ? maFilter : na, color = #FFCC00, title = "MA Filter")
// **************
// * Stochastic *
// **************
// Stochastic Settings
showSSC = input(true, title = "Show Stochastic Crossovers?", group = "Stochastic")
Length = input (10, minval = 1, title = "%K Length", group = "Stochastic")
SmoothK = input (3, minval = 1, title = "%K Smoothing", group = "Stochastic")
SmoothD = input (3, minval = 1, title = "%D Smoothing", group = "Stochastic")
// Calculate Stochastic
var float K = na
var float D = na
if (maType == "SMA")
K := sma(stoch(source, high, low, Length), SmoothK)
D := sma(K, SmoothD)
if (maType == "EMA")
K := ema(stoch(source, high, low, Length), SmoothK)
D := ema(K, SmoothD)
if (maType == "RMA")
K := rma(stoch(source, high, low, Length), SmoothK)
D := rma(K, SmoothD)
if (maType == "WMA")
K := wma(stoch(source, high, low, Length), SmoothK)
D := wma(K, SmoothD)
if (maType == "VWMA")
K := vwma(stoch(source, high, low, Length), SmoothK)
D := vwma(K, SmoothD)
StochasticCrossOver = crossover(K, D)
StochasticCrossUnder = crossunder(K, D)
// Lukis SS
plotshape(showSSC and StochasticCrossOver and K <= 20 ? K : na, text = "Golden\nCrossover", color = color.new(color.green, transp = 25), location = location.belowbar, size = size.tiny, title = "Golden Crossover" )
plotshape(showSSC and StochasticCrossUnder and K >= 80 ? D : na, text = "Deadly\nCrossover", color = color.new(color.red, transp = 25), location = location.belowbar, size = size.tiny, title = "Deadly Crossover" )
plotshape(showSSC and StochasticCrossOver and K <= 80 and K > 20 ? K : na, text = "Bullish\nCrossover", color = color.new(color.green, transp = 50), location = location.belowbar, size = size.tiny, title = "Bullish Crossover")
plotshape(showSSC and StochasticCrossUnder and K >= 20 and K < 80 ? D : na, text = "Bearish\nCrossover", color = color.new(color.red, transp = 50), location = location.belowbar, size = size.tiny, title = "Bearish Crossover")
showBull = input(true, title = "Show Bullish Signal?", group = "Signal")
showBear = input(false, title = "Show Bearish Signal?", group = "Signal")
bullishCriteria = 0
if (ha_open < ha_close) and (ha_open[1] < ha_close[1]) and (ha_open[2] >= ha_close[2])
bullishCriteria := bullishCriteria + 1
if (maFast > maSlow) and (maSlow > maFilter)
bullishCriteria := bullishCriteria + 1
if (K > D) and (K > K[1]) and (D > D[1])
bullishCriteria := bullishCriteria + 1
bearishCriteria = 0
if (ha_open >= ha_close) and (ha_open[1] >= ha_close[1]) and (ha_open[2] < ha_close[2])
bearishCriteria := bearishCriteria + 1
if (maFast < maSlow) and (maSlow < maFilter)
bearishCriteria := bearishCriteria + 1
if (K < D) and (K < K[1]) and (D < D[1])
bearishCriteria := bearishCriteria + 1
signal = color.new(color.white, transp = 0)
if bearishCriteria == 2
signal := color.new(color.orange, transp = 50)
if bearishCriteria == 3
signal := color.new(color.red, transp = 50)
if bullishCriteria == 2
signal := color.new(color.aqua, transp = 50)
if bullishCriteria == 3
signal := color.new(color.green, transp = 50)
bullishCriteria := showBull ? bullishCriteria : 0
bearishCriteria := showBear ? bearishCriteria : 0
bgcolor(iff(bullishCriteria > 1, signal, na), title = 'Bullish Signal')
bgcolor(iff(bearishCriteria > 1, signal, na), title = 'Bearish Signal')
longTPPerc = input(title = "Take Profit Threshold (%)" , minval = 0.0, step = 0.5, defval = 2.5, group = "Trading") / 100
profitRatio = input(title = "Profit-to-Loss ratio (risk tolerance)", minval = 1.0, step = 0.1, defval = 1.4, group = "Trading")
longSLPerc = longTPPerc / profitRatio
takeProfit = strategy.position_avg_price * (1 + longTPPerc)
stopLoss = strategy.position_avg_price * (1 - longSLPerc)
strategy.initial_capital = 50000
strategy.entry("Long" , strategy.long , floor(strategy.initial_capital*.1/close), stop = strategy.position_avg_price * 1.25, when = bullishCriteria > 1)
strategy.entry("Short", strategy.short, floor(strategy.initial_capital*.1/close), stop = strategy.position_avg_price * 1.25, when = bearishCriteria > 1)
strategy.close("Long" , when = (open >= takeProfit) or (open <= stopLoss) or (high >= takeProfit) or (low <= stopLoss))
strategy.close("Short", when = (open >= takeProfit) or (open <= stopLoss) or (high >= takeProfit) or (low <= stopLoss))
plotshape(bullishCriteria, location = location.belowbar, color = color.new(color.black, transp = 100))
plotshape(bearishCriteria, location = location.belowbar, color = color.new(color.black, transp = 100))