VB计算MACD指标详细编码

。_饼干妹妹 提交于 2020-02-27 00:16:12

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        
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!