为Excel VBA创建VHF技术指标

时间:2018-10-15 12:17:40

标签: excel vba technical-indicator

我正在尝试使用Excel VBA创建垂直水平滤镜(VHF)指示器。

为简单起见,计算n天的VHF是n周期高点的最大值与n周期低点的最小值之间的差与过去n周期之和之和的绝对值之比。收盘价的第一差:

enter image description here

Function VHF(highs As Range, lows As Range, n As Integer, price As Range, price0 As Range)

Dim count As Long
Dim maxhigh As Double
Dim minlow As Double
Dim closediff As Double
Dim day As Integer

maxhigh = Application.Max(highs)
minlow = Application.Min(lows)
day = WorksheetFunction.count(Range(price0, price))
    If day >= n Then
        For j = 2 To n - 1
            closediff = closediff + Abs(price0.Offset(j, 0) - price0.Offset(j - 1, 0))
        Next j
        VHF = (maxhigh - minlow) / closediff
    End If
End Function

我的VBA代码存在问题,希望有人可以帮助我,谢谢!

0 个答案:

没有答案