PDA

View Full Version : Printing to a file


MicroAl
03-11-2009, 05:38 PM
Is there a simple way of getting ninja to print to a file? For example say I have an indicator that produces 1 for a higher daily close, I would like
to output this to a file with details such as date etc. I know that this can be done with C# programming but is there a simple way to do this. It would aid greatly in analysis of the markets.

MicroAl
03-12-2009, 03:01 AM
OK I have found the Samplestreamwriter example and have used it to output data. In the indicator there is a variable:-

privatestring path = Cbi.Core.UserDataDir.ToString() + "MyTestFile.txt";

I would like to amend the location the file is saved in, so that I have a ninja test directory for example. How do I do this? I presume that it is not just a case of amending the
above line as there are probably other references to the path variable in the 'Ninjaascript generated code' section.

Thanks

TAJTrades
03-12-2009, 04:13 AM
privatestring path = Cbi.Core.UserDataDir.ToString() + "MyTestFile.txt";

The above will write a file to the My Documents/Ninja Folder

I use:
private string path = @"F:\" + "ES " + String.Format("{0:yyMMdd ddd}",DateTime.Now) + ".csv";

Which will create a file named "ES 090311 Wed" for yesterdays data.

The ".csv" extension allows me to open the file easily in Open Office Calc or Excel

F:\ is my memory stick drive (I would rather have errors on my Mem Stick and not on my hard drive) and lowers the rear and tear on the hard drive.

This my not be the best way to do it but it works on my computer. Disclaimer: I am a trader first and a horrible code hack second.

Hope this helps.

TAJ

mrlogik
03-12-2009, 05:47 AM
Micro,

you may want to reference this (http://www.ninjatrader-support2.com/vb/showthread.php?t=9198&highlight=file+stream) post for some background information.

I have found the following works for me

//Variables
private bool logFileInit = false;
private FileStream file;
private StreamWriter sw;

//OnBarUpdate method
//*******************************
// CREATE LOG FILE
//*******************************
if(!logFileInit)
{
logFileInit = true;

try
{
if(file == null)
file = new FileStream("C:\\test.txt", FileMode.OpenOrCreate, FileAccess.Write);
if(sw == null)
sw = new StreamWriter(file);
}
catch(Exception ex)
{
Print(ex.ToString());
}
}

//To use it
sw.Write("your text");


//********************************
// DISPOSE METHOD -- CLEAN UP OBJECTS
// To Properly dispose of it when finished to
// prevent file locking, etc
//********************************
public override void Dispose()
{
//******************
// Clean up resources
//******************

try
{
if(sw != null)
{
// Close the stream writer
sw.Close();
}

if(file != null)
{
// Close the file writer
file.Close();
}
}
catch (Exception e)
{
Print(e.ToString());
}

//Removes all draw objects
RemoveDrawObjects();

//call base
base.Dispose();
}


hope this helps.

MicroAl
03-12-2009, 10:15 AM
Thanks to both of you. I certaintly have plenty to look at over the weekend.

One for the Ninja Administrators. Through the wizards you can fairly easily
use the menus etc to set up some complicated strategies. Why not add a facility for market analysis? Ie something that allows a user to check for market patterns and obtain a printout. Eg a user could select to find how many times and on what dates a higher close followed a previous higher close etc. Could be an additional selling point!

NinjaTrader_Bertrand
03-12-2009, 10:23 AM
Thanks for the input MicroAl, like a pattern data mining tool...

MicroAl
03-12-2009, 10:46 AM
Yes that would be a very useful addition.

While I consider your product to be excellent in many respects, a couple of things do let it down in actual trading. One, the simple inability to draw a line, right click and set an alert (is there a problem with patents here?)

The other is concerning workspaces. For the newbie traders among us who have not got the room for multiple monitors etc, a simple way of pointing and clicking on a tab to change a displayed workspace etc is essential especially when day trading and a fast decision is required. If there is a key sequence which does this I apologise but I have not seen one and have read on the forum that key macros are not supported.

NinjaTrader_Bertrand
03-12-2009, 11:01 AM
For the workspaces try pressing Shift + F3 to cylce to the next active one.

Thanks for the suggestion on adding an alert to the drawn lines.

You can also check into this indicator - http://www.ninjatrader-support2.com/vb/local_links.php?action=jump&id=125&catid=1

MicroAl
03-12-2009, 11:35 AM
Thanks, that is just what I wanted.

Regards