調整された移動平均値と累積的な高低指数の組み合わせ戦略

作者: リン・ハーンチャオチャン, 日付: 2023-11-21 15:19:35
タグ:

img

概要

この戦略は,主に高低指数,移動平均指数,スーパートレンド指数を組み合わせて,市場の傾向とオープンポジションを決定します.

戦略の論理

  1. 高低指数は,特定の期間の最新価格が新しい高値か新低値になったかどうかを判断し,スコアを蓄積する.スコアが上昇すると,上昇力の強化を表す.スコアが下がると,下落力の強化を表す.

  2. 移動平均指数は,価格が上向きの梯形形上昇傾向か下向きの梯形形下落傾向にあるかどうかを判断する.移動平均が梯形形上昇を示すとき,それは上昇力の強化を表す.梯形形下落を示すとき,それは下向きの力の強化を表す.

  3. 高低指数と移動平均指数の判断を組み合わせて市場傾向を決定し,その後スーパートレンド指数の方向と組み合わせた取引機会を見つけます.特に,高低指数と移動平均指数の両方が上昇勢力の強化を示し,スーパートレンド指数の方向が下向きである場合,ロングポジションを開きます.両方の指数が弱気勢の強化を示し,スーパートレンド指数の方向が上向きである場合,ショートポジションを開きます.

利点

  1. 高低指数は,価格動向と勢力の変化を効果的に判断することができる.移動平均指数は,価格傾向を効果的に決定することができる.両者の組み合わせは,市場の方向性をより正確に決定することができる.

  2. スーパートレンドインデックスと組み合わせたポジション開設は,ポジションの早期または遅めの開設を防ぐことができます. スーパートレンドインデックスは,価格逆転点を効果的に特定することができます.

  3. 複数の指標が互いを確認し 誤った信号を減らす

リスク

  1. 高低指数と移動平均指数からの誤った信号は,負債を発生させる可能性があります.

  2. 過剰な参加とスーパートレンドインデックスのパラメータの設定が不適切である場合,誤った信号が生じる可能性があります.

  3. 急速なトレンド逆転と不適切なストップ損失設定は,大きな損失につながる可能性があります.

  4. リスクは指標のパラメータを最適化し,ストップロスの価格レベルを調整することで削減できます.

最適化

  1. パラメータの最適な組み合わせを見つけるために,異なる種類の移動平均指標をテストする.

  2. 高低指数と移動平均指数のパラメータを最適化して信号をより安定して信頼できるようにします.

  3. 誤った信号を減らすため,MACD,KDなど,他の検証指標を組み込む.

  4. 機械学習アルゴリズムを組み込み パラメータと信号重量を自動的に最適化します

  5. 人気のない商品の取引を避けるために 感情分析を組み込む.

結論

この戦略は,高低指数と移動平均指数を通じて市場動向と勢いを決定し,その後スーパートレンド指数を使用してシグナルをフィルタリングし,バリーッシュとベアシグナルが互いに対峙し,スーパートレンド指数が逆転するときにポジションを開く.その利点は複数のシグナル検証とポジションのタイムリー開設にあります.これはリスクを効果的に制御できます.既存の問題には,誤った信号とトレンド判断の誤りが含まれます.パラメータ最適化,ストップ損失設定,シグナルフィルタリングなどを通じてさまざまな改善ができるよう,戦略をより堅牢かつ信頼性のあるものにすることができます.


/*backtest
start: 2023-10-21 00:00:00
end: 2023-11-20 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/
// © HeWhoMustNotBeNamed

//@version=4
strategy("AlignedMA and Cumulative HighLow Strategy", overlay=true, initial_capital = 1000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type = strategy.commission.percent, pyramiding = 1, commission_value = 0.01, calc_on_order_fills = true)

MAType = input(title="Moving Average Type", defval="sma", options=["ema", "sma", "hma", "rma", "vwma", "wma"])
includePartiallyAligned = input(true)
HighLowPeriod = input(50, minval=1,step=1)
LookbackPeriod = input(10, minval=1,step=1)

supertrendMult = input(2, minval=1, maxval=10, step=0.5)
supertrendLength = input(10, minval=1)

tradeDirection = input(title="Trade Direction", defval=strategy.direction.long, options=[strategy.direction.all, strategy.direction.long, strategy.direction.short])
backtestYears = input(10, minval=1, step=1)

f_getMovingAverage(source, MAType, length)=>
    ma = sma(source, length)
    if(MAType == "ema")
        ma := ema(source,length)
    if(MAType == "hma")
        ma := hma(source,length)
    if(MAType == "rma")
        ma := rma(source,length)
    if(MAType == "vwma")
        ma := vwma(source,length)
    if(MAType == "wma")
        ma := wma(source,length)
    ma
    
f_getMaAlignment(MAType, includePartiallyAligned)=>
    ma5 = f_getMovingAverage(close,MAType,5)
    ma10 = f_getMovingAverage(close,MAType,10)
    ma20 = f_getMovingAverage(close,MAType,20)
    ma30 = f_getMovingAverage(close,MAType,30)
    ma50 = f_getMovingAverage(close,MAType,50)
    ma100 = f_getMovingAverage(close,MAType,100)
    ma200 = f_getMovingAverage(close,MAType,200)

    upwardScore = 0
    upwardScore := close > ma5? upwardScore+1:upwardScore
    upwardScore := ma5 > ma10? upwardScore+1:upwardScore
    upwardScore := ma10 > ma20? upwardScore+1:upwardScore
    upwardScore := ma20 > ma30? upwardScore+1:upwardScore
    upwardScore := ma30 > ma50? upwardScore+1:upwardScore
    upwardScore := ma50 > ma100? upwardScore+1:upwardScore
    upwardScore := ma100 > ma200? upwardScore+1:upwardScore
    
    upwards = close > ma5 and ma5 > ma10 and ma10 > ma20 and ma20 > ma30 and ma30 > ma50 and ma50 > ma100 and ma100 > ma200
    downwards = close < ma5 and ma5 < ma10 and ma10 < ma20 and ma20 < ma30 and ma30 < ma50 and ma50 < ma100 and ma100 < ma200
    upwards?1:downwards?-1:includePartiallyAligned ? (upwardScore > 5? 0.5: upwardScore < 2?-0.5:upwardScore>3?0.25:-0.25) : 0

f_getHighLowValue(HighLowPeriod)=>
    currentHigh = highest(high,HighLowPeriod) == high
    currentLow = lowest(low,HighLowPeriod) == low
    currentHigh?1:currentLow?-1:0

inDateRange = time >= timestamp(syminfo.timezone, year(timenow) - backtestYears, 01, 01, 0, 0)

maAlignment = f_getMaAlignment(MAType,includePartiallyAligned)
alignedMaIndex = sum(maAlignment,LookbackPeriod)

maAlignmentDirection = alignedMaIndex > alignedMaIndex[1] ? 1 : alignedMaIndex < alignedMaIndex[1] ? -1 : 0
maAlignmentDirection := maAlignmentDirection == 0? nz(maAlignmentDirection[1],0):maAlignmentDirection

highLowIndex = f_getHighLowValue(HighLowPeriod)
cumulativeHighLowIndex = sum(highLowIndex,LookbackPeriod)

hlDirection = cumulativeHighLowIndex > cumulativeHighLowIndex[1] ? 1 : cumulativeHighLowIndex < cumulativeHighLowIndex[1] ? -1 : 0
hlDirection := hlDirection == 0? nz(hlDirection[1],0):hlDirection

[superTrend, dir] = supertrend(supertrendMult, supertrendLength)

buyEntry = (dir == -1 and maAlignmentDirection == 1 and hlDirection == 1)
sellEntry = (dir == 1 and maAlignmentDirection == -1 and hlDirection == -1)

barColor = buyEntry?color.lime:sellEntry?color.orange:color.gray
barcolor(barColor)

// strategy.risk.allow_entry_in(tradeDirection)
strategy.entry("Buy", strategy.long, when=barColor == color.lime and inDateRange, oca_name="oca_buy")
strategy.close("Buy", when=dir == 1)

strategy.entry("Sell", strategy.short, when=barColor == color.orange and inDateRange, oca_name="oca_sell")
strategy.close("Sell", when=dir == -1)


もっと