この戦略は,取引量指標 ((VFI) によるトレンド追跡取引を実現する.戦略は,株式価格の変動と取引量変化を計算し,市場トレンドの方向を判断し,低買い高売りを実現する.
VFI指標を計算する:株価の対数変化と取引量に基づいてVFI値を計算し,平滑処理によって震動を排除する.
トレンドの方向を判断する:VFI指標の0軸を横切るのは看板信号で,0軸を横切るのは下落信号である.
取引シグナル: 急速EMA上では遅いEMAを穿え,VFI上では買入ラインを穿えるときに多めにする.VFI下では売り出線を穿えるときに平仓する.
ストップ・モード: 固定ストップ・割合を設定する.
この戦略は,主にVFI指数によってトレンドの方向を判断し,均線システムと連携して取引シグナルを発信する.VFI指数は,株価の変動と取引量の変化を通じて市場の感情を反映し,トレンド追跡指標である.単一の価格指数と比較して,VFI指数判断はより包括的で,トレンドの転換点をよりよく識別し,揺れをフィルターします.
VFI指数は,単一の価格指数よりもトレンドを判断し,波動的な市場と偽の突破を効果的にフィルターします.
均線システムは判断を補助し,VFI指標が震動市で誤信号を発するのを防ぐ.
固定ストップポイントを設定し,リスク管理に有利である.
トレンドフォローモデルで,市場の転換点を推測する必要なく,トレンドフォローで余分な利益を得ることができます.
パラメータ設定は柔軟で,市場に応じてパラメータを調整し,異なる周期と品種に適応することができます.
VFI指数は,大きな揺れの中,誤った信号を発する可能性があります.
固定ストップポイントは大きすぎたり小さすぎたりして,早すぎたり遅すぎたりする.
買い売りパラメータが正しく設定されていない場合,取引が頻繁に発生したり,請求書が欠けたりする可能性があります.
トレンド追跡戦略は逆転を捉えることができず,時効的なストップダストが必要です.
パラメータを間違えた場合,早すぎたり遅すぎたりすることがあります.
VFIのパラメータを調整し,指標の計算を最適化する.
平均線周期を調整し,信号発信時間を最適化する.
ストップポイントを動的に調整し,ストップ方法を最適化する.
他の指標のフィルターと組み合わせて,信号の質を向上させる.
大周期と小周期に対してそれぞれ最適化パラメータの組み合わせ。
異なる品種のパラメータの健壮性をテストし,パラメータの適応性を向上させる.
この戦略は,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)