Announcement

Collapse
No announcement yet.

TradeStation Dlls?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • TradeStation Dlls?

    Hello All,

    Anyone else here using TradeStaion and writing DLLs for it? I would like to share ideas with you.

    Currently I have got TS to call my DLL and execute some code. Now I want to create a Progress bar. TS displays a stocks movement in a series or bars on a chart. When I apply a study, TS starts with the first bar on the chart and crunches through my code and then goes to the next bar and does it all over again. Variables are carried over from bar to bar, but I will be calling my DLL hundreds of times.

    I want to be able to create a progress bar on the first bar and send it the total number of bars and the number os bars crunched so far to get a progres bar. The problem is the progress bar will be called thousands of times.

    Does anyone know of cut and paste code for a progress bar that can be called many times and remain up untill the last bar sends it a command to go away? Something simple that can compile to a DLL.


    ------------------
    Kind Regards
    Mike

  • #2
    There were several samples posted up here, search on PROGRESS and you may find some.

    I do have the code for it however, let me see if I can dig up a sample and post it here.
    Code:
    This one uses a new thread to open and display the progress bar, so it is sorta separate from your application and can process the progress bar even if the app is crunching data:
    
    $Compile Exe
    $Resource "PROG.PBR"
    $Include "WIN32API.INC"
    $Include "COMMCTRL.INC"
    
    Global hIcon        As Long
    Global hDlg         As Long
    Global tDlg         As Long
    Global hProgressDlg As Long
    Global hProgressBar As Long
    Global hDialogText  As Long
    Global hInstance    As Long
    Global g_hThread    As Long
    Global g_FileSpec   As String
    
    Global Cancel       As Long
    Global g_lngInitThreadHandle As Long
    
    Declare Sub UpdateProgress(Text As Asciiz)
    Declare Function ProcessFile(FileSpec As String) As Long
    
    Declare CallBack Function ThreadItemsProc() As Long
    Declare CallBack Function DialogProc() As Long
    
    %PROGRAM = 1024
    %PROGRESS = %WM_USER + 902
    
    '===============================
    'Resource file requirements:
    '#define PROGRAM 1024
    'PROGRAM ICON "PROGRAM.ICO"
    '===============================
    
    '----------------------------------------------------------------------------------------------------------------
    
    Function WinMain (ByVal hInstance     As Long, _
                      ByVal hPrevInstance As Long, _
                      lpCmdLine           As Asciiz Ptr, _
                      ByVal iCmdShow      As Long) As Long
    
    
    ProcessFile "DEBUG.TXT"
    End Function
    
    '----------------------------------------------------------------------------------------------------------------
    
    Function ProcessFile(FileSpec As String) As Long
    Local id As Long
    Local l_Result As Long
    
    
    g_FileSpec = "DEBUG.TXT"  'For testing purposes, use your own global filespec name
    
    
    hIcon = LoadIcon( hInstance, ByVal %PROGRAM)
    Dialog New 0, "Progressbar  - " + g_FileSpec ,,, 200,50 ,  %SW_SHOWNORMAL To hDlg
    Control Add Image, hDlg, -3,"#1024",-1,-1,14,14 'Icon
    Dialog Send hDlg, %WM_SETICON, %ICON_SMALL, hIcon
    Control Add Label, hDlg, -3, "Encrypting " + g_FileSpec, 25,1,160,10
    Control Add "msctls_progress32",hDlg,%PROGRESS,"",1,20,150,10, %WS_CHILD Or %WS_VISIBLE Or %WS_CLIPSIBLINGS Or %CCS_BOTTOM
    Control Add Button, hDlg, %IDCANCEL, "&Cancel", 155, 16,40, 14, %WS_TABSTOP
    
    ' Create a thread to handle dialog messages of modeless dialog boxes
    If IsFalse g_lngInitThreadHandle Then
       Thread Create InitThread(id) To g_hThread
       ' Let the thread end when it stops
       Thread Close g_hThread To l_Result
       'Add WaitForObject here
    Else
       Exit Function
    End If
    
    'Create modeless dialog for thread:
    Dialog New 0,"" ,,,180,60,  %WS_CHILD Or %DS_CONTROL, 0 To tDlg
    Dialog Show Modeless tDlg Call ThreadItemsProc
    Dialog Show Modal hDlg Call DialogProc
    
    
    End Function
    
    
    '----------------------------------------------------------------------------------------------------------------
    
    Function InitThread(ByVal id As Long) Export As Long
    Local FilePos   As Long
    Local FileSize  As Long
    Local MaxBuff   As Long
    Local x         As Long
    
    g_lngInitThreadHandle = %TRUE
    
    
    FileSize = 500000 'Or import your filesize
    BytesToRead& = FileSize
    FilePos& = 1
    MaxBuff& = 4096
    
    Control Send hDlg, %PROGRESS, %PBM_SETRANGE, 0 ,MakLng(0,FileSize& \ MaxBuff&)
    Control Send hDlg, %PROGRESS, %PBM_SETSTEP, 1 , 0
    
    
    For x = 1 To FileSize \ MaxBuff&
        'Time this one in your loops of processing files etc...
        Control Send hDlg, %PROGRESS, %PBM_STEPIT , 0, 0
    '    Sleep 50 'to simulate a heavy load on the computer
    Next
    
    'Set Global Flag to False here
    g_lngInitThreadHandle = %FALSE
    Dialog End hDlg, 1
    
    End Function
    
    
    '------------------------------------------------------------------------------
    Function ThreadDialog(ByVal hDlg As Long) Export As Long
    Local Rc As Long
    Do
        Dialog DoEvents
        Dialog Get Size hDlg To Rc,Rc
    Loop While Rc
    
    Function = 1
    End Function
    '----------------------------------------------------------------------------------------------------------------
    CallBack Function ThreadItemsProc() As Long
    Local wMsg   As Long
    Local wParam As Long
    Local lParam As Long
    Local x      As Long
    wMsg = CbMsg
    lParam = CbLparam
    wparam = CbWparam
      Select Case wMsg
        Case %WM_ACTIVATE
    
        Case %WM_COMMAND
    
          Select Case LoWrd(wParam)
            Case %IDCANCEL
                Dialog End tDlg, 0
                Dialog End hDlg, 0
    
          End Select
      End Select
    End Function
    
    '----------------------------------------------------------------------------------------------------------------
    CallBack Function DialogProc() As Long
    Local wMsg   As Long
    Local wParam As Long
    Local lParam As Long
    Local x      As Long
    wMsg = CbMsg
    lParam = CbLparam
    wparam = CbWparam
      Select Case wMsg
        Case %WM_ACTIVATE
    
        Case %WM_COMMAND
          Select Case LoWrd(wParam)
    
            Case %IDCANCEL
                Dialog End tDlg, 0
                Dialog End hDlg, 0
          End Select
    
       Case %WM_DESTROY
            Dialog End tDlg, 0 'Destroy Modeless dialog
    
      End Select
    
    End Function


    ------------------
    Scott
    mailto:[email protected][email protected]</A>
    Scott Turchin
    MCSE, MCP+I
    http://www.tngbbs.com
    ----------------------
    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

    Comment


    • #3
      This is one that was posted by another person (Please take credit here)
      I don't recall who did this one, a bit more complex however.

      Code:
         #Compile Exe
         #Register None
         #Dim All
         #Include "WIN32API.INC"
      
         CallBack Function PicProc
            Static Done As Long, hBrush1 As Long, hBrush2 As Long
            Local hDC As Long, LpPaint As PaintStruct
            Local tRect As Rect, hBrush As Long, Clr As Long
            Local i As Long, j As Long, x1 As Long, x2 As Long, hRgn As Long
            Select Case CbMsg
               Case %WM_INITDIALOG
                  hBrush1 = CreateSolidBrush(Rgb(  0,   0, 255))
                  hBrush2 = CreateSolidBrush(Rgb(255, 255, 255))
               Case %WM_DESTROY
                  DeleteObject hBrush1: DeleteObject hBrush2
                  InvalidateRect GetParent(CbHndl), ByVal 0, %True
                  UpdateWindow GetParent(CbHndl)
               Case %WM_ERASEBKGND: Function = 1: Exit Function
               Case %WM_USER + 1
                  Done = CbWparam
                  InValidateRect CbHndl, ByVal 0, %True: UpdateWindow CbHndl
               Case %WM_PAINT
                  GetClientRect CbHndl, tRect
                  hDC = BeginPaint(CbHndl, LpPaint)
                  j = tRect.nLeft + (tRect.nRight - tRect.nLeft) * Done * 0.01
                  For i = 1 To 2
                     If i = 1 Then x1 = tRect.nLeft: x2 = j: hBrush = hBrush1: Clr = %WHITE _
                              Else x1 = j + 1: x2 = tRect.nRight: hBrush = hBrush2: Clr = %BLACK
                     hRgn = CreateRectRgn (x1, tRect.nTop, x2, tRect.nBottom)
                     SetWindowRgn CbHndl, hRgn, %False
                     FillRect hDC, tRect, hBrush
                     SetBkMode hDC, %TRANSPARENT
                     SetTextColor hDC, Clr
                     DrawText hDC, Str$(Done)+"%", -1, tRect, _
                        %DT_SINGLELINE Or %DT_CENTER Or %DT_VCENTER
                     DeleteObject hRgn
                  Next
                  EndPaint CbHndl, LpPaint
            End Select
         End Function
      
         CallBack Function DlgProc
            Static Done As Long, hDlg As Long
            Select Case CbMsg
               Case %WM_COMMAND
                  If CbCtl = 101 Then
                     Done = 0
                     SetTimer CbHndl, 1, 500, ByVal %Null
                     Dialog New CbHndl, "", 10, 10, 176, 12, %WS_CHILD Or %WS_VISIBLE Or %WS_BORDER To hDlg
                     Dialog Show Modeless hDlg Call PicProc
                     Dialog Send hDlg, %WM_USER + 1, Done, 0
                  End If
               Case %WM_TIMER
                  Done = Done + 5
                  If Done > 100 Then Dialog End hDlg: KillTimer CbHndl, 1 Else _
                  Dialog Send hDlg, %WM_USER + 1, Done, 0
            End Select
         End Function
      
         Function PbMain
            Local hDlg As Long, hDlg1 As Long
            Dialog New 0, "Progress Bar",,, 200, 80, %WS_SYSMENU To hDlg
            Control Add Button, Hdlg, 101, "Show", 50, 40,100, 14, %BS_DEFAULT
            Dialog Show Modal hDlg Call DlgProc
         End Function
      ------------------
      Scott
      mailto:[email protected][email protected]t</A>
      Scott Turchin
      MCSE, MCP+I
      http://www.tngbbs.com
      ----------------------
      True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

      Comment


      • #4
        Thx guys.

        I think I can get what i want out of these.

        If I compile the code as a DLL, hoe do I call it from my DLL?



        ------------------
        Kind Regards
        Mike

        Comment

        Working...
        X