양량 흐름 지표에 기초한 트렌드 다음 전략

저자:차오장, 날짜: 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)




더 많은