Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Excel VBA and ATI

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

    Excel VBA and ATI

    Brand new to Excel VBA. I am trying to automate trading strategies via Excel. I created VBA code as below.

    Private Declare PtrSafe Function CashValue Lib "D:\NinjaTrader 8\bin\NinjaTrader.Client.DLL" (ByVal lpAccountName As String) As Double

    Private Sub CommandButton1_Click()
    Dim dbCashValue As Double
    dbCashValue = CashValue("")
    Range("A1").Value = dbCashValue
    End Sub​

    When I click on CommandButton1, it stops on the line "dbCashValue = CashValue(""), and I get an error msg (see attached).

    Any ideas what I'm doing wrong?​
    Attached Files

    #2
    Is the AT Interface enabled?

    Comment


      #3
      It was not -- thank you for the tip bitdavid! However, after turning this on, I am still getting the same result. It appears the problem is with my VBA code, but I've got to believe I'm not the first person to do this. Someone else must have done it before, and so hoping to find someone with the requisite VBA and NT experience. Hoping to get some feedback from NT early next week when everyone is back in the office. May hit Stackoverflow for some feedback too.

      Interestingly, when I was reading the documentation on utilizing the DLL interface, I saw nothing about enabling ATI. It's probably somewhere in the docs, just didn't see it in the sections I was reading.

      Thanks again -- back to sleuthing!

      Comment


        #4
        Just to make life easier, perhaps you should approach
        this a but differently.

        Instead of trying to get Excel/VBA working, make your first
        attempt be directly with VB.Net.

        From VB.Net, the solution for VBA might come more easily.

        [Of course, ya gotta realize, I am not expert on this -- I mean,
        I'm just making (I hope) helpful suggestions -- I've never tried
        to actually do anything with NinjaScript outside of C#.]

        Comment


          #5
          Maybe you need to add 'NinjaTrader.Client.dll' as a reference inside VBA?

          Comment


            #6
            bltdavid I had the same idea re: adding the DLL as a reference inside VBA. When I tried, it said "Can't add a reference to the specified file." The help behind that msg said that the DLL is not usable by VBA. I'm hoping that on Monday, someone at NT will be able to provide guidance on using this DLL outside of NT, which is the entire premise of NT's Automated Trading Interface (ATI). VBA supports external DLL calls, so one would expect that this interface should be accessible from VBA.

            Comment


              #7
              Bummer ... which version of NinjaTrader are you using?

              Comment


                #8
                On my system, I'm using 8.0.26.1, installed into the default location.

                There are two different Client assemblies,

                C:\Program Files(x86)\bin\NinjaTrader.Client.dll
                C:\Program Files(x86)\bin64\NinjaTrader.Client.dll

                Have you tried using the bin64 version?

                Comment


                  #9
                  Oh, uh ... sorry

                  the bin vs bin64 distinction goes away starting in 8.0.27.0

                  my bad

                  Comment


                    #10
                    I'm using 8.1.1.3, and I only have the bin directory.

                    Comment


                      #11
                      Hello Elevator2TheTop,

                      Thanks for your post.

                      The NinjaTrader.Client.dll for NinjaTrader 8 can be found in:
                      • C:\Program Files\NinjaTrader 8\bin\NinjaTrader.Client.dll
                      Please see this forum thread for information about the API: https://forum.ninjatrader.com/forum/...626#post793626

                      ​Support for the API is very limited from NinjaTrader Support. We are not able to assist with any code in an application external to NinjaTrader. We are able to detail the usage of any methods available from the API.

                      Below I am providing a publicly available link to the help guide that lists the functions available to the API.

                      Help Guide NT8 API functions - http://ninjatrader.com/support/helpG..._interface.htm

                      Let me know if I may assist further.
                      <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                      Comment


                        #12
                        Since the function expects a string as an argument (ByVal lpAccountName As String), you might need to pass an actual account name rather than an empty string. Try passing something like "Account1" instead of " to see if it resolves the issue.I remember when I was starting out with VBA to automate some stock tracking—ran into a similar roadblock. Once I figured out how to pass values correctly, everything clicked.If you’re looking for more in-depth VBA tutorials, https://excel.tv/best-excel-courses/ has some excellent resources for diving deeper into VBA!
                        Last edited by JosephDavidsona; 02-19-2025, 02:44 PM.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                        0 responses
                        574 views
                        0 likes
                        Last Post Geovanny Suaza  
                        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                        0 responses
                        333 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by Mindset, 02-09-2026, 11:44 AM
                        0 responses
                        101 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                        0 responses
                        553 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by RFrosty, 01-28-2026, 06:49 PM
                        0 responses
                        551 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X