볼륨 지표를 기반으로 한 추세 추종 전략


생성 날짜: 2023-10-10 14:51:13 마지막으로 수정됨: 2023-10-10 14:51:13
복사: 0 클릭수: 1032
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

개요

이 전략은 거래량 지표 ((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 지표에 기반하여 트렌드 방향을 판단하고, 평행 시스템과 함께 필터링 오류 신호를 제공합니다. 트렌드 추적을 통해 낮은 가격과 높은 가격을 달성하고, 구체적인 반전을 예측할 필요가 없습니다. 전략의 장점은 트렌드가 단일 가격 지표보다 우수하다는 판단을 통해 흔들림을 효과적으로 필터링 할 수 있습니다. 주요 위험은 흔들리는 시장에서 잘못된 신호를 발산 할 수 있습니다.

전략 소스 코드
/*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)