View Full Version : Visual Basic 6 COM interface errors
10-11-2006, 01:27 AM
I amtrying to use the Ninja Trader COM interface with Visual Basic 6. I get an error message "ActiveX component can't create object" when trying to create object "Set NT = New NinjaTrader_Client.Client" (see code below). I followed the information in the help file and I added NinjaTrader client reference and it does show up in the object browser.
Dim NT As NinjaTrader_Client.Client
Private Sub Form_Load()
Set NT = New NinjaTrader_Client.Client <-----ERROR OCCURS HERE
Private Sub cmdBuy_Click()
Dim RC As Integer
RC = NT.Command("Place", "Sim101", "ER2", "Buy", 3, "Market", , , "Day", "", NT.NewOrderId, "ER2 Daytrade")
Private Sub cmdSellShort_Click()
Dim RC As Integer
RC = NT.Command("Place", "Sim101", "ER2", "Sell", 3, "Market", , , "Day", "", NT.NewOrderId, "ER2 Daytrade")
Has something changed in the latest version or am I doing something wrong? Any suggestions would greatly be approeciated. My NT version is 5.2.1000.4.
Thank you, Steve
10-11-2006, 02:13 AM
Your post suggests, that your code worked fine with prior NT releases. Please try the following:
- terminate any app
- uninstall NT
- manually remove file <windows>\system32\NtDirect.dll
- reinstall NT
10-11-2006, 03:12 AM
Thank you for the quick reply. No my code did not work with a prior release, this code was just created yesterday. I am using the DLL with Tradestion and it works fine.
I followed your instructions, but I still have the same problem. I tried on two computers. Any other suggestions?Has the COM interface ever been tested in VB 6? I searched throught the forum, but did not find any information.
10-11-2006, 03:40 AM
1) Yes, COM interface was tested as any NT feature is tested before publishing.
2) However, we know that some users have issues with COM which are - for whatever reason - not resolvable.
-> I suggest code against the DLL as you did from within TS.
12-30-2006, 06:56 AM
Hi Dirk, Hi MarlinTrader,
I am using Visual Basic 6 - NinjaTraderSimulation (new customer)and have never used Tradestation. I have the same problem (run time error 429 - Cannot create the object) although the reference is set! Additonally, I don't see how the instance-setting will work:
Dim nt as NinjaTrader_Client.CLIENT (but the functions are in ICLIENT)
Set nt = new NinjaTrader_Client.CLIENT (triggers the error)
I also don't know what this means "I suggest code against the DLL as you did from within TS"
Please give me acode-sample that works and please explain itlike you do for a child that saves time!
Thank you very much!
12-30-2006, 03:21 PM
Please consult the docs. If see provided COM sample does not work for you (see below), then I suggest trying the TradeStation DLL interface. There are samples in the docs as well.
12-31-2006, 03:25 AM
Thank you very much for your prompt answer!
May I was not clear enough but I am not using TRADESTATION and I don't have it in mind to do it in the future!
The problem is that that the COM interface (NinjaTrader_Client)is only addable and the file "NtDirect.dll" is not.
I also searched in the "HELP system"(you call them docs) but I don't have an example that shows me how to cope with the problem in the Visual Basic (NOT Tradestation).
Please help me because I'd like to trade as soon as possible. Thank you!
Best Regards and I wish you a happy new year!
12-31-2006, 11:17 PM
Please check out the docs: Automated Tradig Interface -> COM interface and DLL interface.
Samples are available:
- in the docs (DLL and COM)
- DLL interface: see TradeStation or eSignal wrapper code
Other than that, there are no samples available.
Happy New Year and all the best for you as well.
01-02-2007, 08:56 AM
I'm sorry but the docs doesn't help me. Both the COM interface and the DLL interface don't work in the VISUAL BASIC 6.0 environment!
Maybe it is not possible in the FREESIMULATION EDITION.
I'd like to trade with Visual Basic via Ninjatrader, nothing else, no Tradestation or Esignal. Please check it or tell me simply that it doesn't work and I have to look for another solution.
01-02-2007, 09:19 AM
Unfortunately we do not have the internal resources to test in the VB environment. Theoretically it should work but obviously your experience suggests otherwise. You could alternatively use the File interface and have your VC app write out files and read files to interface with NT.
01-02-2007, 09:36 AM
I was able to make the DLL work successfully with VB 6. Attached is a ZIP file with a simple order entry VB 6 application that I created that should get you started. There are no comments, but the code is should be easily understood.
01-02-2007, 10:40 AM
Thank you very much! Somehow, there were duplicate postings sodeleted one but that seem to have blown away the attachment. Would you beso kind to post the attachment again? Sorry for the inconvenience.
01-02-2007, 12:49 PM
VB 6 Application Attached
01-03-2007, 08:30 AM
Thank you very much! I could see the light but it is still far away!
Positive: Your program showed me how to work with the DLL. I have successfully tested 2 functions, viz. Connected & command. I've placed market orders.
Negative: All other functions doesn't work.You can also see this by trying your Button"Get Order Id".And I miss the functions for receiving the real time tick data. I tried to define the functionGetDouble in the following way:
Private Declare Function GetDouble Lib "NTDirect.dll" (ByVal instrument As String) As Double
But it triggered an error! I also tried the functions Orders & OrderStatus and they doesn't work like the others, although it doesn't force an error.
Please help me, I'd like to trade as soon as possible!
01-03-2007, 08:56 AM
The ATI does not provide market data. There are no functions designed for that. There are some functions forsetting market data from an external source. This is so external applications, such as a charting application can drive NT as a simulator.
01-03-2007, 09:57 AM
Bad news for me but I can handle that!
So I will use NT for sending/changing/cancelling Trades via VB 6 only. But for this I still need the functions in the NTDirect.dll to be able to control the trades. As I said, even in the very helpful sample program (thanks to MarlinTrader) they don't work!
Still hope! Thanks!
11-27-2007, 10:07 AM
I encountered the same problem. I tried to call DLL functions with VB 6.0. However, some functions don't work. The functions "OrderStatus" and "NewOrderId" return nothing. I guess the reason is that for those functions return a string, the Ninja Trader DLL return the data type as LPSTR instead of LPCTSTR.
May I suggest to solve this problem in the next version, say NT 6.5?
Perhaps, you can add some new functions such "OrderStatusVB" and "NewOrderIdVB", etc., which return the data type as LPCTSTR.
11-27-2007, 10:16 AM
I suggest trying the DLL interface if you encounter problems on the COM interface.
11-27-2007, 11:14 AM
Thank you for your reply.
I've tried the DLL interface. However, the functions, which return string such as "OrderStatus" and "NewOrderId", don't work. I'm pretty sure this is because of the return data type problem as I explained in the previous post.
11-27-2007, 12:26 PM
Interfaces do work, since they work in e.g. in the TradeStation context.
11-27-2007, 07:50 PM
yes, the DLL functions do work for Tradestation but not for VB 6.0
As I have explained earlier, that's because of the difference of the string data type between VC and VB.
For example, you may have used these parameters in your Win32 DLL function "OrderStatus":
LPSTR _stdcall OrderStatus(LPSTR orderId)
However, from my experience, this won't work for VB. The function should be modified as:
LPCTSTR _stdcall OrderStatus(LPSTR orderId)
However, the modified function will work for VB but may not work properly for Tradestation. The same applies for all functions, which return the string data type. So may I suggest to add some new functions for VB in the next version as follows:
LPCTSTR _stdcall OrderStatusVB(LPSTR orderId)
LPCTSTR _stdcall NewOrderIdVB()
LPCTSTR _stdcall OrdersVB(LPSTR account)
LPCTSTR _stdcall StrategiesVB(LPSTR account)
11-27-2007, 11:12 PM
Thanks for clarification and suggestion. I suggest going by TradeStation or eSignal logic and you will be fine.