0

VB.NET 2010 below is working. But I need to use default values as stated in TA-Lib documentation: TA_INTEGER_DEFAULT or TA_REAL_DEFAULT for optional parameters. How I can use that in coding? Currently I assign values manually (need to know what are the values).

Public Sub CalcMACD()
        ' CALCULATE allocationSize
        Dim lookback As Integer = TicTacTec.TA.Library.Core.MacdLookback(optInFastPeriod, optInSlowPeriod, optInSignalPeriod)
        Dim temp As Integer = Math.Max(lookback, startIdx)
        If (temp > endIdx) Then
            allocationSize = 0                    ' No output
        Else
            allocationSize = endIdx - temp + 1
        End If

        optInFastPeriod = 12                                 ' Set optional values <==== HOW TO USE TA_INTEGER_DEFAULT
        optInSlowPeriod = 26                                 ' Set optional values <==== HOW TO USE TA_INTEGER_DEFAULT
        optInSignalPeriod = 9                                ' Set optional values <==== HOW TO USE TA_INTEGER_DEFAULT

        Dim outMACD As Double()                                                       ' Declare output variable type
        ReDim outMACD(allocationSize)
        Dim outMACDSignal As Double()                                                 ' Declare output variable type
        ReDim outMACDSignal(allocationSize)
        Dim outMACDHist As Double()                                                   ' Declare output variable type
        ReDim outMACDHist(allocationSize)

        ' the calculation
        Dim res As TicTacTec.TA.Library.Core.RetCode = TicTacTec.TA.Library.Core.Macd(startIdx, endIdx, openPrice, optInFastPeriod, optInSlowPeriod, optInSignalPeriod, outBegIdx, outNBElement, outMACD, outMACDSignal, outMACDHist)


        ' Add result column to Datagridview
        ' #1 add column to Datagridview1
        DataGridView1.ColumnCount = DataGridView1.ColumnCount + 3
        Dim columnID As Integer = DataGridView1.ColumnCount - 3
        ' #2 define column header
        DataGridView1.Columns(columnID).HeaderText = "MACD"
        DataGridView1.Columns(columnID + 1).HeaderText = "MACD Signal"
        DataGridView1.Columns(columnID + 2).HeaderText = "MACD Histogram"
        '#3 insert values to column
        For i As Integer = startIdx To endIdx
            DataGridView1(columnID, i).Value = outMACD(i)
            DataGridView1(columnID + 1, i).Value = outMACDSignal(i)
            DataGridView1(columnID + 2, i).Value = outMACDHist(i)
        Next
End Sub
theB
  • 6,450
  • 1
  • 28
  • 38
RainerJ
  • 71
  • 2
  • 10

1 Answers1

0
Public Sub CalcMACD(Optional ByVal optInFastPeriod As Integer = TA_INTEGER_DEFAULT, Optional ByVal optInSlowPeriod As Integer = TA_INTEGER_DEFAULT, Optional ByVal optInSignalPeriod As Integer = TA_INTEGER_DEFAULT)

    ' CALCULATE allocationSize
    Dim allocationSize As Integer = 0
    Dim lookback As Integer = TicTacTec.TA.Library.Core.MacdLookback(optInFastPeriod, optInSlowPeriod, optInSignalPeriod)

    Dim temp As Integer = Math.Max(lookback, startIdx)
    If (temp < endIdx) Then
        allocationSize = endIdx - temp + 1
    End If

    ' Declare output variables
    Dim outMACD(allocationSize) As Double
    Dim outMACDSignal(allocationSize) As Double                                              
    Dim outMACDHist(allocationSize) As Double

    ' the calculation
    Dim res As TicTacTec.TA.Library.Core.RetCode = TicTacTec.TA.Library.Core.Macd(startIdx, endIdx, openPrice, optInFastPeriod, optInSlowPeriod, optInSignalPeriod, outBegIdx, outNBElement, outMACD, outMACDSignal, outMACDHist)

    ' Add result column to Datagridview
    ' #1 add column to Datagridview1
    DataGridView1.ColumnCount = DataGridView1.ColumnCount + 3
    Dim columnID As Integer = DataGridView1.ColumnCount - 3
    ' #2 define column header
    DataGridView1.Columns(columnID).HeaderText = "MACD"
    DataGridView1.Columns(columnID + 1).HeaderText = "MACD Signal"
    DataGridView1.Columns(columnID + 2).HeaderText = "MACD Histogram"
    '#3 insert values to column
    For i As Integer = startIdx To endIdx
        DataGridView1(columnID, i).Value = outMACD(i)
        DataGridView1(columnID + 1, i).Value = outMACDSignal(i)
        DataGridView1(columnID + 2, i).Value = outMACDHist(i)
    Next
End Sub
Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
  • 1.So, not defining value for optional parameters? Cannot, since that means value is zero. – RainerJ Jun 20 '16 at 05:03
  • The value for the optional parameter is set/defined in the function definition. – Joel Coehoorn Jun 20 '16 at 13:51
  • Error 1 'TA_INTEGER_DEFAULT' is not declared. It may be inaccessible due to its protection level. – RainerJ Jun 22 '16 at 12:49
  • @RainerJ Both the semantics of the name and ALL CAPS convention strongly hint that `TA_INTEGER_DEFAULT` should be defined as a **constant** somewhere in your project. Find where that happens, make sure they are public, and make sure you reference them properly. – Joel Coehoorn Jun 22 '16 at 15:02
  • I Add-Reference TA-Lib-Core.dll and previous code works. I checked to c sourcecode and found that TA_INTEGER_DEFAULT is (int32.min) and TA_REAL_DEFAULT = -4E37. But, how if we only have dll (how to access constants) ? – RainerJ Jun 23 '16 at 01:04
  • I add constant variables declaration in my program: – RainerJ Aug 04 '16 at 09:47