View Full Version : Export last data to file
curious
06-26-2009, 05:54 AM
What is the best way to export the last bid/offer/last data to a simple *.txt file? Can it be done by any NT tools or script only?
NinjaTrader_Bertrand
06-26-2009, 06:01 AM
Hi curious, welcome to our support forums! Yes, you would need custom coding to write this to a txt file - http://www.ninjatrader-support2.com/vb/showthread.php?t=3477
For Level1 data you can work with OnMarketData() - http://www.ninjatrader-support.com/HelpGuideV6/OnMarketData.html
curious
06-26-2009, 06:15 AM
Thanks.
OK, I'll write&compile some code that I need in NinjaScript Editor. How should then I run it?
NinjaTrader_Bertrand
06-26-2009, 06:23 AM
You can then run the indicator or strategy from the chart by right clicking in it and selecting either to add 'indicators' or 'strategies'.
curious
06-26-2009, 06:51 AM
As I understand for level1 data I can use both OnMarketData() and OnBarUpdate() methods. What is the difference between them for bid/ask data export? Almost every bid/ask change brings OnBarUpdate also. Am I right? Or there is any difference which I have not considered?
NinjaTrader_Bertrand
06-26-2009, 07:02 AM
You're correct, you can use either one to access the needed data. Just would need to run things in realtime on CalculateOnBarClose = false to get updates on each incoming tick.
auspiv
06-28-2009, 06:36 PM
As I understand for level1 data I can use both OnMarketData() and OnBarUpdate() methods. What is the difference between them for bid/ask data export? Almost every bid/ask change brings OnBarUpdate also. Am I right? Or there is any difference which I have not considered?
each bid/ask change doesn't necessarily mean OnBarUpdate is called. for example, if someone canceled an order right at the ask, the ask would drop but there would be no reported executions. see one of my older posts to get a feel for what can be done with last/bid/ask data.. http://www.ninjatrader-support2.com/vb/showthread.php?t=10296
curious
10-30-2009, 04:10 PM
Yes, you would need custom coding to write this to a txt file - http://www.ninjatrader-support2.com/vb/showthread.php?t=3477
Going back to your example. You offer to use the File.WriteAllLines() method (or I can use File.WriteAllText() instead), but they work only with string data type. Is there any method to output doubles (bid, ask, etc.) directly or I have to use Convert.ToString() function before and File.WriteAllLines()/File.WriteAllText() then?
NinjaTrader_Ben
10-31-2009, 11:01 AM
Hello,
If I recall correctly, they should write fine. Try it, if it does not work you will need use .ToString()
curious
11-02-2009, 02:17 PM
Hello,
If I recall correctly, they should write fine. Try it, if it does not work you will need use .ToString()
Well, it doesn't work w/o .ToString(). Returns 2 errors:
The best overloaded method match for 'System.IO.File.WriteAllText(string,string)' has some invalid arguments
Argument '2': cannot convert from 'double' to 'string'
NinjaTrader_Josh
11-02-2009, 02:28 PM
The error states what is wrong. You can't use a double when it is looking for a string. To convert the double to a string you can just use .ToString() on the double variable.