量流指標に基づく戦略をフォローする傾向

作者: リン・ハーンチャオチャン開催日:2023年10月10日 14:51:13
タグ:

概要

この戦略は,ボリューム・フロー・インディケーター (VFI) をベースにトレンド・フォロー・トレーディングを実施する.価格変動とボリュームの変化を計算して市場のトレンド方向を判断し,低価格購入と高価格販売を実現する.

戦略原則

  1. VFI指標を計算する:物価変化とボリュームの対数値に基づいてVFI値を計算し,スムージング技術によって振動を平らにする.

  2. トレンド方向を決定する.VFIが0を超えると上昇信号であり,0を下回ると下落信号である.

  3. トレーディング・シグナル: 急速なEMAが遅いEMAを超え,VFIが買いラインを超えるとロング;VFIが売りラインを超えると閉じる.

  4. ストップ損失: 固定ストップ損失パーセントを設定する.

この戦略は主にトレンド方向を決定するためにVFIに依存し,トレード信号を生成するために移動平均と組み合わせます.VFIは価格変動とボリューム変化を通じて市場の感情を反映し,トレンドフォローインジケーターになります.単一価格指標と比較して,VFIはより包括的な判断を提供し,トレンド逆転点をよりよく特定し,統合をフィルタリングします.

利点

  1. VFIは単一価格指標よりも傾向を決定し,統合と誤ったブレイクを効果的にフィルタリングします.

  2. 移動平均値は補足的な判断を提供し,変動市場におけるVFIからの誤った信号を回避する.

  3. 固定ストップロスはリスクを制御し,リスク管理を容易にする.

  4. トレンドフォローモードは逆転を予測することなく 過剰な収益を生み出します

  5. 柔軟なパラメータ調節により 異なる時期や製品に対応できます

リスク

  1. VFIは,重要な変動時に誤った信号を生成する可能性があります.

  2. 固定ストップロスは 幅が幅が狭すぎたり

  3. 設定が正しくない入口と出口は,取引が過剰または行われない状態になる.

  4. トレンドフォローは逆転を捉えることができず,時宜のストップロスの必要性がある.

  5. 不適切なパラメータが早送りや遅延を引き起こす

改良

  1. パラメータを調整することで VFI 計算を最適化する.

  2. 信号のタイミングを良くするために 移動平均周期を微調整します

  3. 固定ストップロスの代わりに動的ストップロスを使用する.

  4. フィルター信号に他の指標を追加します.

  5. パラメータを個別に最適化する 時間枠に基づいて

  6. 耐久性を異なる製品でテストする

結論

この戦略は,VFIでトレンド方向を決定し,間違ったシグナルをフィルタリングするために移動平均を使用する.逆転を予測することなく,トレンドフォローを通じて低い購入/高い販売を実現する.利点は,単一の価格指標よりも優れたトレンド検出と統合をフィルタリングする能力にある.主なリスクは変動中に間違ったシグナルを生成することである.パラメータを最適化し,補充指標を追加し,ストップロスのテクニックを追加することで,その安定性を改善することができます.全体的に,パラメータチューニングとストップロスの最適化により,このVFIベースの戦略は信頼できるトレンドフォローシステムになることができます.


/*backtest
start: 2023-10-02 00:00:00
end: 2023-10-06 21:00:00
period: 3m
basePeriod: 1m
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/
// © mohanee
//This strategy is based on VFI indicator published by  UTS.  
//more details of VFI indicator can be found at  [url=http://mkatsanos.com/VFI.html]http://mkatsanos.com/VFI.html[/url] 
// I have added buy line and sell line to the indicator  and tested  SPY stock/index on one hour chart

//@version=4
strategy(title="VFI  strategy [based on VFI indicator published by  UTS]", overlay=false,pyramiding=2, default_qty_type=strategy.fixed,    initial_capital=10000, currency=currency.USD)


// Const
kMaColor = color.aqua
kNeutralColor = color.gray
kBearColor = color.red
kBullColor = color.green

kAlma = "ALMA"
kEma = "EMA"
kSma = "SMA"
kWma = "WMA"


// Input

vfi_length = input(8, title="Length", minval=1)  //default 130
vfi_coef = input(0.2, title="Coef", minval=0.1)
vfi_volCutoff = input(2.5, title="Volume Cutoff", minval=0.1)
vfi_smoothLen = input(3, title="Smoothing Period", minval=1)
vfi_smoothType = input(kEma, title="Smoothing Type", options=[kAlma, kEma, kSma, kWma])

//These are adde by me for the strategy purpose  BEGIN
vfi_buyLine = input(-4, title="Buy Line", minval=-10)
vfi_sellLine = input(5, title="Sell Line", minval=-10)
stopLoss = input(title="Stop Loss%", defval=5, minval=1)
//These are adde by me for the strategy purpose  END

vfi_longEMA = input(200, title="Long EMA", minval=1)
vfi_shortEMA1 = input(50, title="short EMA1", minval=1)
vfi_shortEMA2 = input(9, title="short EM2A", minval=1)

vfi_showTrend = input(false, title="Visualize Trend")
vfi_showFill = input(true, title="Apply Filling")
vfi_showMa = input(true, title="Show Moving Average")
vfi_maType = input(kSma, title="Moving Average Type", options=[kAlma, kEma, kSma, kWma])
vfi_maLength = input(30, title="Moving Average Length", minval=1)
vfi_almaOffset = input(0.85, title="• ALMA - Offset (global setting)", minval=0.0, maxval=1.0, step=0.05) // more smoothness (closer to 1) vs. more responsiveness (closer to 0)
vfi_almaSigma = input(6.0, title="• ALMA - Sigma (global setting)", minval=0.0, step=0.05) // the larger sigma the smoother ALMA


// Functionality

isRising(sig) =>
    sig > sig[1]
    
isFlat(sig) =>
    sig == sig[1]

vfi_trendColor(sig) =>
    isFlat(sig) ? kNeutralColor : isRising(sig) ? kBullColor : kBearColor
    
vfi_color(sig) =>
    isFlat(sig) ? kNeutralColor : sig > 0 ? kBullColor : kBearColor
    
osc_color(sig) =>
    sig == 0 ? kNeutralColor : sig > 0 ? kBullColor : kBearColor

smooth(t, sig, len) =>
    ma = float(sig)         // None
    if t == kSma            // Simple
        ma := sma(sig, len)
    if t == kEma            // Exponential
        ma := ema(sig, len)
    if t == kWma            // Weighted
        ma := wma(sig, len)
    if t == kAlma           // Arnaud Legoux
        ma := alma(sig, len, vfi_almaOffset, vfi_almaSigma)
    ma

calc_vfi(fviPeriod, smoothType, smoothLen, coef, vCoef) =>
    avg = nz(hlc3)
    inter = log(avg) - log(avg[1])
    vInter = stdev(inter, 30)
    cutOff = coef * vInter * close
    vAve = smooth(kSma, volume[1], fviPeriod)
    vMax = vAve * vCoef
    vC = min(volume, vMax)
    mf = avg - avg[1]
    vCp = iff(mf > cutOff, vC, iff(mf < -cutOff, -vC, 0))
    sVfi = sum(vCp, fviPeriod) / vAve
    vfi = smooth(smoothType, sVfi, smoothLen)
    
value_vfi = calc_vfi(vfi_length, vfi_smoothType, vfi_smoothLen, vfi_coef, vfi_volCutoff)
value_ma = smooth(vfi_maType, value_vfi, vfi_maLength)

longEMAval= ema(close, vfi_longEMA)
shortEMAval1= ema(close, vfi_shortEMA1)
shortEMAval2= ema(close, vfi_shortEMA2)

color_vfi = vfi_showTrend ? vfi_trendColor(value_vfi) : vfi_color(value_vfi)
color_osc = vfi_showFill ? osc_color(value_vfi) : na
color_ma = vfi_showMa ? kMaColor : na


// Drawings

plot_vfi = plot(value_vfi, title="VFI", color=color_vfi, linewidth=1)
plot_fill = plot(0, color=color_vfi, editable=false)
fill(plot_vfi, plot_fill, title="Oscillator Fill", color=color_osc, transp=75) 
hline(vfi_buyLine, color=color.green, title="Buy Line", linewidth=2, linestyle=hline.style_dashed)
hline(vfi_sellLine, color=color.purple, title="Sell Line", linewidth=2, linestyle=hline.style_dashed)
plot(value_ma, title="MA", color=color_ma, linewidth=2)

strategy.entry(id="VFI LE", long=true,  when=crossover(value_vfi,vfi_buyLine)  and ( shortEMAval1 >= longEMAval  ))

//strategy.close(id="VFI LE", comment="Exit",   when=crossunder(value_vfi,vfi_sellLine))
strategy.close(id="VFI LE", comment="TP Exit",   when=crossunder(value_vfi,vfi_sellLine) and close>strategy.position_avg_price)
//strategy.close(id="VFI LE", comment="Exit",   when=  (shortEMAval1 > shortEMAval2 )  and crossunder(close, shortEMAval2))

//stoploss
stopLossVal =   strategy.position_avg_price -  (strategy.position_avg_price*stopLoss*0.01) 
strategy.close(id="VFI LE", comment="SL Exit",   when=crossunder(value_vfi,vfi_sellLine) and close < stopLossVal)




もっと