close
S-乖離率指標
1.公式

N-bias=(當日收盤價 - N日移動平均價) / N日移動平均價 * 100

除了串接DDE之外,另需新增一個文字檔,並且記錄每天商品的收盤價

 

程式碼如下:

%E4%B9%96%E9%9B%A2%E7%8E%87.png  

 

 

%E4%B9%96%E9%9B%A2%E7%8E%8701.png

 

 

%E4%B9%96%E9%9B%A2%E7%8E%8702.png

 

Imports NDde
Imports NDde.Client
Imports System.Text
Imports System
Imports System.IO
Public Class Form1
    Dim obi As New StreamReader("c:\Price.txt")
    Dim arr_Price As New ArrayList()
    Dim Price, arr_num, SumPrice, AvgPrice, BIASn As Double
    Private WithEvents dde As DdeClient
    Dim i As Double
    Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
        dde = New DdeClient("Excel.exe", "DDE.xlsx", Me) '串接dde
        dde.Connect()
        Dim temp1 As Byte()
        Try
            temp1 = dde.Request("R1C1", 1, 60000)
        Catch ex As Exception
        End Try
        Try
            dde.StartAdvise("R1C1", 1, True, 60000)
        Catch ex As Exception
        End Try
        Do
            Price = obi.ReadLine() '讀取Price檔案第一行
            If Price <> 0 Then
                arr_Price.Add(Price)
                SumPrice += Price '將Price的每日價格累加給SumPrice
                ListBox1.Items.Add("價格" & Price)
            End If
        Loop Until Price <= 0
        obi.Close()
        arr_num = arr_Price.Count + 1 '計算陣列總數
        Label4.Text = arr_num
    End Sub
    Public Sub DDE_Advise(ByVal sender As Object, ByVal e As NDde.Client.DdeAdviseEventArgs) Handles dde.Advise
        If e.Item.ToString = "R1C1" Then
            i = e.Text
            AvgPrice = (SumPrice + i) / arr_num '加上今日價格來計算均價
            BIASn = i - AvgPrice
            Label6.Text = (BIASn / AvgPrice) * 100
            Label2.Text = i
        End If
    End Sub
End Class

以上純屬個人興趣研究

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 興小弟讀書筆記 的頭像
    興小弟讀書筆記

    興小弟讀書筆記

    興小弟讀書筆記 發表在 痞客邦 留言(1) 人氣()