トレンドフォロー戦略 移動平均と超トレンドに基づいた

作者: リン・ハーンチャオチャン,日付: 2023-11-14 16:23:42
タグ:

img

概要

この戦略は移動平均値とスーパートレンド指標を組み合わせてトレンドをフォローします.トレンドが上昇するときは長くなって,トレンドが下がると短くなります.

戦略の論理

  1. 重度の移動平均MAを計算する. 期間中の重度の平均価格を計算するには,重量としてボリュームを使用する.

  2. Hull 移動平均を MA に基づいて計算します.Hull 移動平均は価格変化により敏感です.

  3. スーパートレンド指標を計算します. スーパートレンドは,トレンド変化を識別するためにATRを組み合わせます. 上下帯を計算します.

  4. 上部帯を超えると長行 下部帯を超えると短走

  5. 価格動きを視覚的に観察するために,オープン,閉鎖,高値,低値などの補助指標をグラフ化します.

  6. 指標のクロスオーバーに基づいて 取引決定をする

利点分析

  1. この戦略は移動平均と超傾向の両方を組み合わせて,より正確なトレンド検出を可能にします.

  2. Hull移動平均は価格変動に敏感で,時速のスポットトレンド逆転に役立ちます.

  3. スーパートレンドは,市場変動に適応するために上下帯を動的に調整します.

  4. 補助指標は,指標信号で意思決定を支援するために,価格動きを視覚的に表示します.

  5. この戦略は移動平均期間のパラメータ最適化,超トレンド倍数等を可能にします

リスク分析

  1. Whipsawsは,範囲限定の市場において誤った信号を生成し,不必要な取引を引き起こします.

  2. 複数の指標の監視により 戦略の実施は比較的複雑になります

  3. パラメータは,異なる製品の特性に適した調整が必要です.

  4. 単一のポジションでの損失を制限するために,厳格なストップロスは必要である.

  5. 取引頻度が高いため 委員会からの影響管理が必要です

オプティマイゼーションの方向性

  1. 異なる移動平均値をテストして 市場に敏感な平均値を見つけます

  2. 異なるスーパートレンド倍数をテストして タイミングでトレンドの変化を把握します

  3. 波動性が上昇する場合は,ポジションサイズを減らすため,波動性指数を含める.

  4. 範囲内での誤った信号を避けるために 突破条件を追加します

  5. ストップロスの戦略を最適化し,市場状況に適応できるようにする.

概要

この戦略は,トレンドを追跡するために移動平均とスーパートレンドの両方を使用してトレンド方向を判断する.利点は,より正確なトレンド検出のための指標間の相互検証である.しかし,誤った信号には注意すべきである.この戦略は,パラメータ最適化とリスク管理を通じてさらに改善することができる.それは強いトレンド特性を持つ楽器のトレンドフォローオペレーションに適している.


/*backtest
start: 2022-11-07 00:00:00
end: 2023-11-13 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/
// © rajukpatel

//@version=5
strategy('My RK Strategy with Alert', shorttitle='My RK Strategy with Alert', overlay=true )
src5 = input(close)

tf = input(1440)
len5 = timeframe.isintraday and timeframe.multiplier >= 1 ? tf / timeframe.multiplier * 7 : timeframe.isintraday and timeframe.multiplier < 60 ? 60 / timeframe.multiplier * 24 * 7 : 7

ma = ta.ema(src5 * volume, len5) / ta.ema(volume, len5)


//script taken from https://www.tradingview.com/script/kChCRRZI-Hull-Moving-Average/

src1 = ma

p(src1, len5) =>
    n = 0.0
    s = 0.0
    for i = 0 to len5 - 1 by 1
        w = (len5 - i) * len5
        n += w
        s += src5[i] * w
        s
    s / n

hm = 2.0 * p(src1, math.floor(len5 / 3)) - p(src1, len5)
vhma = p(hm, math.floor(math.sqrt(len5)))
lineColor = vhma > vhma[1] ? color.lime : color.red
plot(vhma, title='VHMA', color=lineColor, linewidth=3)
hColor = true
vis = true
hu = hColor ? vhma > vhma[2] ? #00ff00 : #ff0000 : #ff9800

vl = vhma[0]
ll = vhma[1]
m1 = plot(vl, color=hu, linewidth=1, transp=60)
m2 = plot(vis ? ll : na, color=hu, linewidth=2, transp=80)

fill(m1, m2, color=hu, transp=70)
//

b = timeframe.isintraday and timeframe.multiplier >= 1 ? 60 / timeframe.multiplier * 7 : timeframe.isintraday and timeframe.multiplier < 60 ? 60 / timeframe.multiplier * 24 * 7 : 7



//
res5 = input.timeframe('D')

o = request.security(syminfo.tickerid, res5, open, barmerge.gaps_off, barmerge.lookahead_on)
c = request.security(syminfo.tickerid, res5, close, barmerge.gaps_off, barmerge.lookahead_on)
hz = request.security(syminfo.tickerid, res5, high, barmerge.gaps_off, barmerge.lookahead_on)
l = request.security(syminfo.tickerid, res5, low, barmerge.gaps_off, barmerge.lookahead_on)



col = c >= o ? color.lime : color.red

ppo = plot(b ? o >= c ? hz : l : o, color=col, title='Open', style=plot.style_stepline, transp=100)
ppc = plot(b ? o <= c ? hz : l : c, color=col, title='Close', style=plot.style_stepline, transp=100)

plot(b and hz > c ? hz : na, color=col, title='High', style=plot.style_circles, linewidth=2, transp=60)
plot(b and l < c ? l : na, color=col, title='Low', style=plot.style_circles, linewidth=2, transp=60)

fill(ppo, ppc, col, transp=90)

//
// INPUTS //
st_mult = input.float(1, title='SuperTrend Multiplier', minval=0, maxval=100, step=0.01)
st_period = input.int(50, title='SuperTrend Period', minval=1)

// CALCULATIONS //
up_lev = l - st_mult * ta.atr(st_period)
dn_lev = hz + st_mult * ta.atr(st_period)

up_trend = 0.0
up_trend := c[1] > up_trend[1] ? math.max(up_lev, up_trend[1]) : up_lev

down_trend = 0.0
down_trend := c[1] < down_trend[1] ? math.min(dn_lev, down_trend[1]) : dn_lev

// Calculate trend var
trend = 0
trend := c > down_trend[1] ? 1 : c < up_trend[1] ? -1 : nz(trend[1], 1)

// Calculate SuperTrend Line
st_line = trend == 1 ? up_trend : down_trend

// Plotting
//plot(st_line[1], color = trend == 1 ? color.green : color.red , style = plot.style_cross, linewidth = 2, title = "SuperTrend")
buy = ta.crossover(c, st_line)
sell = ta.crossunder(c, st_line)
signal = input(false)

/////////////// Plotting /////////////// 
plotshape(signal and buy, style=shape.triangleup, size=size.normal, location=location.belowbar, color=color.new(color.lime, 0))
plotshape(signal and sell, style=shape.triangledown, size=size.normal, location=location.abovebar, color=color.new(color.red, 0))


if buy
    strategy.entry('My Long Entry Id', strategy.long)

if sell
    strategy.entry('My Short Entry Id', strategy.short)



もっと