Anyone write a Visual Basic program to help their trading?

Discussion in 'Trading Software' started by monty21, Mar 26, 2009.

  1. richardm

    richardm

    ATR volatility stop for ya...
    tradestation and multicharts are great, but look at all of the proprietary junk they stiffarm you with, here is a simple ATR indicator from Visual Chart 5 complete with initialization and error checking - - yes, some namespace dependencies here in term of plotting, but hey at least it is very, very workable...

    Dim ATRRange As Long
    Dim Factor As Double
    Const Data As Long = 0
    Dim AvTrueRangeData As Long

    Option Explicit
    Public APP As OscUserApp
    Implements Indicator
    Public Sub Indicator_OnInitCalculate()
    With APP
    AvTrueRangeData = .GetIndicatorIdentifier(AvTrueRange, Data, ATRRange)
    .StartBar = 0
    End With
    End Sub

    Public Sub Indicator_OnCalculateBar(ByVal Bar As Long)
    With APP
    .SetIndicatorValue .Close - .GetIndicatorValue(AvTrueRangeData) * Factor
    .SetIndicatorValue .Close + .GetIndicatorValue(AvTrueRangeData) * Factor, 2
    End With
    End Sub

    Public Sub Indicator_OnSetParameters(ParamArray ParamList() As Variant)
    ATRRange = ParamList(1)
    Factor = ParamList(2)
    End Sub

    Public Sub Indicator_OnCalculateRange(ByVal StartBar As Long, ByVal FinalBar As Long)
    Dim i As Long
    i = APP.StartBar
    If StartBar > i Then
    i = StartBar
    End If
    While Not APP.ShouldTerminate And i <= FinalBar
    APP.CurrentBar = i
    Indicator_OnCalculateBar i
    i = i + 1
    Wend
    End Sub

    Private Sub OscUserAppInstance_OnConnection(ByVal Application As OscUserApp, ByVal MTDllInst As Object, Custom() As Variant)
    Set APP = Application
    End Sub
     
    #31     Sep 5, 2009
  2. richardm

    richardm

    'Sine Weighted Moving Average Indicator

    Dim Period As Integer
    Const PI = 3.1415926
    Dim Factor, Num, Den, PreviousValue

    Option Explicit
    Public APP As OscUserApp
    Implements Indicator

    Public Sub Indicator_OnInitCalculate()
    With APP
    Factor = 180 / 6
    .StartBar = Period - 1
    PreviousValue = 0
    End With
    End Sub

    Public Sub Indicator_OnCalculateBar(ByVal Bar As Long)
    With APP
    Dim i, SD
    Num = 0
    Den = 0
    For i = 1 To Period
    ' Para pasarlo a radianes.
    SD = ((i * Factor) * PI) / 180
    Num = Num + Sin(SD) * .Close(i - 1)
    Den = Den + Sin(SD)
    Next i
    If Den <> 0 Then
    .SetIndicatorValue Num / Den
    PreviousValue = Num / Den
    Else
    .SetIndicatorValue PreviousValue
    End If
    End With
    End Sub

    Public Sub Indicator_OnSetParameters(ParamArray ParamList() As Variant)
    Period = ParamList(1)
    End Sub
    Public Sub Indicator_OnCalculateRange(ByVal StartBar As Long, ByVal FinalBar As Long)
    Dim i As Long
    i = APP.StartBar
    If StartBar > i Then
    i = StartBar
    End If
    While Not APP.ShouldTerminate And i <= FinalBar
    APP.CurrentBar = i
    Indicator_OnCalculateBar i
    i = i + 1
    Wend
    End Sub

    Private Sub OscUserAppInstance_OnConnection(ByVal Application As OscUserApp, ByVal MTDllInst As Object, Custom() As Variant)
    Set APP = Application
    End Sub
     
    #32     Sep 5, 2009
  3. When Oh When will Traders Studio be realtime ?
     
    #33     Sep 7, 2009
  4. I find that Excel/VBA is good to start out but it is very system resource heavy and limiting once you have your system built. I like it for back testing and simple automation (currently using it for simple automation on a retail platform) but it's very crude and basic.

    C++ and SQL would be much better - except I don't know those

    a whole lot depends on your API as well as your trade. Excel can be perfect or it can really bog you down.
     
    #34     Sep 8, 2009
  5. Indeed. If you don't know how to configure Excel with all of it's settings options, you can go to 100% of CPU with realtime data. I confirmed the fact that I can write to the Windows registry about 3x faster than writing to a cell in a worksheet. That amazed me.
    Excel's storage overhead on a sheet is huge.
     
    #35     Sep 8, 2009
  6. richardm

    richardm

    traders studio realtime would be fantastic!
    Yeah in general spreadsheet anything is worthless for less than five minute timeframe...
     
    #36     Sep 8, 2009
  7. byteme

    byteme

    Um...I thought they were releasing a real-time version 2 or 3 years ago. Or am I mis-membering?
     
    #37     Sep 8, 2009
  8. Hi SysWiz'...

    You mean the ability to click on something inside the platform and then trade at the bid or ask of a specfiic market... or chart the data...

    or both?
     
    #38     Sep 8, 2009
  9. Hi Rich'

    worthless - if less than 5 minute timeframe - to do what?
     
    #39     Sep 8, 2009