NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 09-12-2007, 09:53 AM   #1
Folls
Senior Member
 
Join Date: Jan 2006
Location: Chicago, Illinois, USA
Posts: 126
Thanks: 0
Thanked 1 time in 1 post
Default Using windows Form instead of file io

I am currently using a file to pass information between an application I am developing with Visual Studio C# Express and NT. My life and my application would be much better if I could run this all from NT instead.

I'm trying to define a form class and use it but so far I am unsuccessful. Questions:
1) Is this this possible?
2) If not, is there a better way than file io available to communicate with NinjaTrader?

Here is the code I used. It gets an error "The type of namespace 'TestForm' could not be found."

public class FormsTest : Strategy
{
#region Variables
// Wizard generated variables
private int myInput0 = 1; // Default setting for MyInput0
// User defined variables (add any user defined variables below)

//define class for test Form
public class testForm : Form
{
//constructor
public void TestForm()
{
//commented out for now
//this.Text = "this is a test Form";
}
}
#endregion

/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
CalculateOnBarClose = true;
TestForm display = new TestForm();
}

Thanks!

Folls
Folls is offline  
Reply With Quote
Old 09-12-2007, 10:06 AM   #2
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

1) Yes this is possible since this is C# and .NET but it is outside the scope of what we are able to provide support for. I have seen others create some very creative custom windows to drive information to various NinjaScript objects. Maybe someone here can help. You can always contact one of our NinjaScript consultants who could help you in this area as well.

2) Same answer as above.

http://www.ninjatrader.com/webnew/pa...injaScript.htm
NinjaTrader_Ray is offline  
Reply With Quote
Old 09-12-2007, 10:26 AM   #3
Folls
Senior Member
 
Join Date: Jan 2006
Location: Chicago, Illinois, USA
Posts: 126
Thanks: 0
Thanked 1 time in 1 post
Default Just one example?

Thanks. Maybe Ninja (or anyone) can post one simple example so everyone can see how it's done. You don't need to support it from that point. One simple example to get started would be very valuable.

Folls
Folls is offline  
Reply With Quote
Old 09-12-2007, 06:48 PM   #4
gert74
Member
 
Join Date: May 2007
Posts: 35
Thanks: 0
Thanked 0 times in 0 posts
Default

First of all, when developing forms for use with NT I have found that it is more convenient to develop the actual forms in Visual Studio, compile the form code into a DLL and add a reference to that DLL from NT. That way you have all the wysiwyg tools of VS at your disposal which makes forms development much easier.

Now, that being said your way should work as well. From the code you posted it seems your problem might be that you named your form class with a lower case starting character: testForm rather than TestForm. And of course you would have to call the Show() method of the form after you instantiate it to actually see anything

However, I think you will find that showing a form in the Initialize method of a strategy will not be practical as Initialize gets called multiple times before a strategy is ever put on a chart. I have yet to sort out exactly how and why.
gert74 is offline  
Reply With Quote
Old 09-13-2007, 07:36 AM   #5
Folls
Senior Member
 
Join Date: Jan 2006
Location: Chicago, Illinois, USA
Posts: 126
Thanks: 0
Thanked 1 time in 1 post
Default

Thanks for the advice. I will pursue the dll method. As you probably guessed, I am new to C# programming. I can use all the help I can get so I appreciate your assistance!

If I can get a form to work, I'll post a simple one in this forum for future use by others. If anyone has one they would like to post, please do so.

Thanks!

Folls
Folls is offline  
Reply With Quote
Old 09-13-2007, 11:33 PM   #6
gert74
Member
 
Join Date: May 2007
Posts: 35
Thanks: 0
Thanked 0 times in 0 posts
Default

Strictly speaking, you might not even need a DLL. As far as I can see, you could just copy the source files from your Visual Studio project to one of the NinjaTrader Custom folders, but I have not been experimenting with that, so I cannot tell if that will cause any problems or inconvenience.

One disadvantage to using the DLL method however, is that in order to update the DLL you would have to close NT, as it will lock the DLL when it loads it.

Using Visual Studio will also allow you to explore the NinjaTrader.Core DLL which contains all kinds of unsupported goodies.

For example the chart form that a strategy is running on is a standard Windows.Forms form with Windows.Forms controls on it. Therefore you can manipulate it programmatically, such as adding buttons to the ToolStrip.
gert74 is offline  
Reply With Quote
Old 09-13-2007, 11:43 PM   #7
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

>> For example the chart form that a strategy is running on is a standard Windows.Forms form with Windows.Forms controls on it. Therefore you can manipulate it programmatically, such as adding buttons to the ToolStrip.

This is not supported and we strongly recommend not doing that, since it could throw up NT internal operations.
NinjaTrader_Dierk is offline  
Reply With Quote
Old 09-13-2007, 11:55 PM   #8
gert74
Member
 
Join Date: May 2007
Posts: 35
Thanks: 0
Thanked 0 times in 0 posts
Default

Yup, just wanna emphasize that something like that is definitely not supported. And if you encounter any issues with your strategies you will need to clean out that part of your code as one of the first things to try.

You need to know what you are doing and be very careful with your testing.

Also, any time you use something unsupported, there is no guarantee that it will not break with the next release of NT.
gert74 is offline  
Reply With Quote
Old 09-14-2007, 12:05 AM   #9
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

Correct. Your clarification is appreciated.
NinjaTrader_Dierk is offline  
Reply With Quote
Old 09-20-2007, 01:25 PM   #10
Folls
Senior Member
 
Join Date: Jan 2006
Location: Chicago, Illinois, USA
Posts: 126
Thanks: 0
Thanked 1 time in 1 post
Default Only an empty form shows

I'm making progress in pursuing the dll based solution but could use some more advice. Here is a summary of what I did so far.

I created a simple windows forms application with one button in Visual Studio 2005. I then changed the output type in Visual Studio under properties to class library to generate a dll. I put the dll in the mydocs Ninja Trader Custom folder. I created a new strategy, added the using statement, added a new reference to the dll, and created a new instance of the form object in the Ninja Trader Initialize section.

protected override void Initialize()
{
CalculateOnBarClose = true;

//added by me to test creating a form from the dll
Form1 dllTest = new Form1();

}

I then put the strategy on a chart. A window does pop up but it is empty. The button I created does not show up.

Is there something that I'm missing to make the whole form I created in Visual Studio appear?

Any help would be great! When I get something simple working, I'll document it and post it here for all to share.

Thanks,

Folls
Folls is offline  
Reply With Quote
Old 09-20-2007, 03:21 PM   #11
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

do you call the form show method?

dllTest.Show();
NinjaTrader_Ray is offline  
Reply With Quote
Old 09-20-2007, 05:56 PM   #12
Folls
Senior Member
 
Join Date: Jan 2006
Location: Chicago, Illinois, USA
Posts: 126
Thanks: 0
Thanked 1 time in 1 post
Default

Great thanks. That worked. The form now appears. However, it appears when I single click the strategy when adding the strategy. Then, it appears multiple times when I add the strategy. Is there any way to have it appear only once?

Thanks again,

Folls
Folls is offline  
Reply With Quote
Old 09-21-2007, 06:55 AM   #13
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

Make sure you only run the code that creates and shows the form once. You should also take care of closing and disposing of the form.

Please see the Dispose() method.

http://www.ninjatrader-support.com/H...6/Dispose.html
NinjaTrader_Ray is offline  
Reply With Quote
Old 09-21-2007, 08:44 AM   #14
Folls
Senior Member
 
Join Date: Jan 2006
Location: Chicago, Illinois, USA
Posts: 126
Thanks: 0
Thanked 1 time in 1 post
Default Form1 appears 3 times before strategy is installed

I added the following isFormNeeded test to only start it once.

public class DLLTest : Strategy
{
#region Variables
// Wizard generated variables
private int myInput0 = 1; // Default setting for MyInput0
// User defined variables (add any user defined variables below)
private bool isFormNeeded = true;
#endregion

/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
CalculateOnBarClose = true;

//added by me to test creating a form from the dll
//The "if" was added because multiple forms were begin displayed
//This means the Form will only show when the strategy is
//installed. Once the form is closed, it won't show up again
if (isFormNeeded)
{
isFormNeeded = false;
Form1 dllTest = new Form1();
dllTest.Show();
}
}

Now, when I right click on the chart and bring up the strategies window, the Form1 appears 3 times before I even click on it in the strategies window. Then, when I install it, it appears more times. I'm clearly doing something wrong here. Any advice on this?

Thanks,

Folls
Folls is offline  
Reply With Quote
Old 09-21-2007, 08:48 AM   #15
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

Move your code to OnBarUpdate() since Initialize() can be called multiple times before its every added to a chart.
NinjaTrader_Ray is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple Windows pgabriel Miscellaneous Support 1 05-31-2007 08:15 AM
Windows Vista ForexResearch Miscellaneous Support 1 04-24-2007 03:06 AM
Linking DOM and windows ForexResearch SuperDOM and other Order Entry Windows 1 01-18-2007 03:39 AM
Windows Vista gdargento Miscellaneous Support 1 01-18-2007 01:09 AM
Windows Linking bmaltz Charting 6 11-20-2006 04:57 PM


All times are GMT -6. The time now is 11:36 PM.