MACD指标的含义、用法及计算原理,请自己百度不啰嗦,直接上干货-代码如下:
Set rstStockHistroy = dbsDatabase.OpenRecordset("SELECT...... ", dbOpenDynaset)
rstStockHistroy.MoveLast
intrecordcounter = rstStockHistroy.RecordCount
rstStockHistroy.MoveFirst
'MsgBox ("记录:" & rstStockHistroy(0).Value)
For intcounter = 1 To intrecordcounter '从上市首日开始计算
If intcounter = 1 Then '上市首日
rstStockHistroy.Edit
rstStockHistroy(9) = 0 'DIFF
rstStockHistroy(10) = 0 'DEA
rstStockHistroy(11) = 0 'BAR
rstStockHistroy.Update
End If
If intcounter = 2 Then '上市次日
rstStockHistroy.MovePrevious
sigPreClose = rstStockHistroy(2)
sigPreDEA = rstStockHistroy(10)
rstStockHistroy.MoveNext
rstStockHistroy.Edit
rstStockHistroy(7) = sigPreClose * 11 / 13 + (rstStockHistroy(4) - sigPreClose) * 2 / 13 'EMA(12)= 昨收 ×11/13+(今收-昨收)×2/13
rstStockHistroy(8) = sigPreClose * 25 / 27 + (rstStockHistroy(4) - sigPreClose) * 2 / 27 'EMA(26)= 昨收 ×25/27+(今收-昨收)×2/27
rstStockHistroy(9) = rstStockHistroy(7) - rstStockHistroy(8) 'DIFF = 今日EMA(12) - 今日EMA(26)
rstStockHistroy(10) = sigPreDEA * 8 / 10 + rstStockHistroy(9) * 2 / 10 'DEA(MACD) = 前一日DEA×8 / 10 + 今日DIF×2 / 10
rstStockHistroy(11) = 2 * (rstStockHistroy(9) - rstStockHistroy(10)) 'BAR=2×(DIFF-DEA)
rstStockHistroy.Update
End If
If intcounter >= 3 Then
rstStockHistroy.MovePrevious
sigPreClose = rstStockHistroy(2)
sigPreEMA12 = rstStockHistroy(7)
sigPreEMA26 = rstStockHistroy(8)
sigPreDEA = rstStockHistroy(10)
rstStockHistroy.MoveNext
rstStockHistroy.Edit
rstStockHistroy(7) = sigPreEMA12 * 11 / 13 + rstStockHistroy(4) * 2 / 13 'EMA(12)= 前一日EMA(12)×11/13+今日收盘价×2/13
rstStockHistroy(8) = sigPreEMA26 * 25 / 27 + rstStockHistroy(4) * 2 / 27 'EMA(26)= 前一日EMA(26)×25/27+今日收盘价×2/27
rstStockHistroy(9) = rstStockHistroy(7) - rstStockHistroy(8) 'DIFF = 今日EMA(12) - 今日EMA(26)
rstStockHistroy(10) = sigPreDEA * 8 / 10 + rstStockHistroy(9) * 2 / 10 'DEA(MACD) = 前一日DEA×8 / 10 + 今日DIF×2 / 10
rstStockHistroy(11) = 2 * (rstStockHistroy(9) - rstStockHistroy(10)) 'BAR=2×(DIFF-DEA)
rstStockHistroy.Update
End If
rstStockHistroy.MoveNext
Next
来源:CSDN
作者:向锋
链接:https://blog.csdn.net/weixin_44114369/article/details/104521076