PDA

View Full Version : Using windows Form instead of file io


Folls
09-12-2007, 09:53 AM
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

NinjaTrader_Ray
09-12-2007, 10:06 AM
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/partners_onlinetrading_NinjaScript.htm

Folls
09-12-2007, 10:26 AM
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

gert74
09-12-2007, 06:48 PM
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.

Folls
09-13-2007, 07:36 AM
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

gert74
09-13-2007, 11:33 PM
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.

NinjaTrader_Dierk
09-13-2007, 11:43 PM
>> 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.

gert74
09-13-2007, 11:55 PM
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.

NinjaTrader_Dierk
09-14-2007, 12:05 AM
Correct. Your clarification is appreciated.

Folls
09-20-2007, 01:25 PM
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

NinjaTrader_Ray
09-20-2007, 03:21 PM
do you call the form show method?

dllTest.Show();

Folls
09-20-2007, 05:56 PM
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

NinjaTrader_Ray
09-21-2007, 06:55 AM
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/HelpGuideV6/Dispose.html

Folls
09-21-2007, 08:44 AM
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

NinjaTrader_Ray
09-21-2007, 08:48 AM
Move your code to OnBarUpdate() since Initialize() can be called multiple times before its every added to a chart.

Folls
09-21-2007, 09:27 AM
Thanks. I moved the code to onbarupdate. I still get three Form1's as follows.

1) When I right click on chart and bring up the strategies window, a Form with no button appears.
2) When I apply the strategy to the chart, a form with a button appears.
3) When I click OK in the strategies window, the final form with a button appears.

I think we're getting closer. Any more advice?

Folls

NinjaTrader_Ray
09-21-2007, 09:32 AM
Unfortunately not, looks like you will need to roll up your sleeves and debug this.

gert74
09-23-2007, 09:42 PM
Just to sum up what I wrote to Folls in a PM, so that others may benefit as well.

First of all, I believe the blank form is being shown from one of your strategies where you were experimenting with forms. Initialize will get called once on all compiled strategies as soon as you open the strategies window, so it could easily be another of your strategies causing this.

Whenever you click "Apply" or "OK" in the strategies window all currently running strategies on the chart are stopped and new instances of them are created.

This means that any variables inside the strategies will be reset. Creating a property around the variable seems to allow values to be carried over between instances.

However, once you move your code to OnBarUpdate it means that your strategy will processing all your historical data as well as any incoming realtime data while you have the window open using whatever default settings the strategy has.

Any settings you change after the strategy has been started will not be applied retroactively unless you reload the strategy.

It would be really cool if there was something like a BeforeFirstBarUpdate method where we could execute custom initialization code only once before any bar updates are processed.

Folls
09-24-2007, 10:42 AM
Thanks! That worked great. I now get only one form. I'll make a simple Visual Studio application that exchanges data with Ninja Trader via a form. I'll then post the Visual Studio project, the Ninja strategy code, and a brief document describing what I did.

That will hopefully help others that are interested in passing values to and from Ninja.

Folls

Folls
10-03-2007, 01:12 PM
I'm still working on my basic example. I have one that appears to be working where I check in OnBarUpdate() to see if the input to the form has changed. However, it would be better if the notification of changed input was event driven. So, I put the following in the Visual Studio code to fire an event when the Input button is clicked:

//event to notify ninja that enter has been clicked with new input
public event EventHandler InputAlert;

private void button1_Click(object sender, EventArgs e)
{
//if there is input
if (String.Compare(textBox1.Text, "") > 0)
{
InputValue1 = Convert.ToDouble(textBox1.Text);
InputValue2 = Convert.ToDouble(textBox2.Text);

textBox3.Text = (InputValue1 * InputValue2).ToString();

//notify ninja new input has been entered by firing an event
if (InputAlert != null)
InputAlert(this, new EventArgs());
}
}

Now, when I try to create an event handler and register it in the strategy, it won't compile. I have the following code in the OnBarUpdate() method. I have also tried it in Initialize() with the same result. Both times I get the error "statement expected".

//an event is fired when new input is entered
//create an event handler and register it
private void InputAlertHandler(object sender, EventArgs e)
{
//get the new info, multiply, store, and display in the form
inputOutputForm.OutputValue1 = inputOutputForm.inputValue1 * inputOutputForm.inputValue1;
inputOutputForm.Controls["textBox4"].Text = (inputOutputForm.inputValue1 * inputOutputForm.inputValue1).ToString();

}
inputOutputForm.InputAlert += new EventHandler(InputAlertHandler);

Do you have any advice on how to get this to compile with the event handler and registration?

Thanks!

Folls

gert74
10-03-2007, 07:10 PM
I do not know if this is your problem, but I can see an inconsistency with the input value properties on the form.

In your form code you use InputValue1 and InputValue2 with captial I while in you strategy code you use lower case i.

Usually the compile error messages at the bottom of the code editor will give you some good info on what is wrong and if you double click the error message it will take you to the line of code that is causing problems.

Folls
10-04-2007, 07:13 AM
Thanks! That was definitely a problem that would have surfaced if I can get past this one. I included a picture of what is happening with line numbers and error messages. I can comment out all code (as shown in the picture) in the method as well as the register code and still have the same problem. If I remove the InputAlertHandler method entirely, it compiles. If I put the InputAlertHandler method in Visual Studio, there is no error.

For some reason, Ninja doesn't like it. Am I allowed to have this method in the OnBarUpdate() or Initialize()? I get the same problem when InputAlertHandler is in either method. I don't believe there is anywhere else to put it.

Any more help would be appreciated!

Folls

gert74
10-04-2007, 08:30 PM
OK, now I see the problem.

You cannot define a method inside another method.

Just move your InputHandler method outside the OnBarUpdate method and you should be alright.

Folls
10-10-2007, 02:25 PM
Thanks for the help! Here is a simple example of a Form made in Visual Studio and then used in a Ninja Strategy.

Read the text file. It explains how to install the example.

I wouldn't recommend attempting this idea unless you have some programming experience.

I hope it helps someone!

Folls

pippero
08-14-2008, 07:27 AM
Thank You Folls!

just a quick not to say this is by far the most useful example I have seen so far.

kenz987
09-08-2008, 05:08 PM
Thank you for this. Using this and some other samples I was able to create a form from inside the OnBarUpdate. I'm now trying to place command buttons directly on the chart page, but just can not get it right. Anyone have any suggestions? Thanks, Ken

traderT
02-07-2009, 06:46 AM
Thanks Folls, this is going to be most helpful with an indicator that I am developing.

clearpicks
06-22-2009, 06:49 AM
Hello,

Is it possible to create buttons on the chart directly to allow the user interact with a script/strategy instead of creating a form window outside of the chart? Is there anyone already did this? Help is appreciated.

- Clearpicks

NinjaTrader_Josh
06-22-2009, 07:27 AM
clearpicks,

Unfortunately this is beyond the level of what we can support, but hopefully some of the more advanced users who may have done so can help you out.

r2kTrader
11-09-2009, 07:40 PM
I think you would need a routine to first get the window handle ...

There is some good code here to help give you an idea of how to get the NT window handles. You will also need an Object Spy of somekind to get the form names, etc. I think.

http://www.ninjatrader-support2.com/vb/showthread.php?p=125932#post125932

Hello,

Is it possible to create buttons on the chart directly to allow the user interact with a script/strategy instead of creating a form window outside of the chart? Is there anyone already did this? Help is appreciated.

- Clearpicks

MicroTrends
12-16-2009, 06:34 PM
You could always test for existence of the form if it has been already created and then hook it...

MicroTrends
12-17-2009, 01:45 PM
you can get the window hanlde by its text..

Zapzap
01-18-2010, 08:22 AM
It is a rather old topic, which I just bumped into.
If you guys only need buttons on the chart, here is my workspace changer indicator. I made four nonfancy but clickable buttons on the chart. Maybe you can benefit from it....

traderT
01-18-2010, 09:55 AM
Will take a look tonight when I get home from work. Sounds like it will be useful :-)

dimkdimk
01-22-2010, 11:54 PM
Here is another example on how to create a button in ToolStrip of a chart window. Don't pay attention to those resources stuff as I just wanted to read resx file from Visual Studio.
Main idea is just get toolstrip control and add button as it is simply done in Visual Studio.

Pay special attention to call Dispose and remove button when it is disposing.
This is just a button and click handler to switch bool flag ( CanTrade or similar ). You may want to add other controls to toolstrip, just be careful and test as NT guys told us: It is dangerous.


#region Using declarations
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Resources;
using System.Collections;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Strategy;
using System.Windows.Forms;
using NinjaTrader.Gui.Chart;
#endregion
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
/// <summary>
/// TestStrat
/// </summary>
[Description("StrategyEx")]
public abstract class StrategyEx : Strategy
{
protected bool Initialized = false;

private ToolStripButton tsbtnStop = null; // Play/Stop Button to prevent Strategy from submitting orders
private ToolStripSeparator tsSeparator = null;
private bool bCanTrade = false;

protected string strStrategyResXPath = Environment.GetFolderPath(Environment.SpecialFolde r.Personal) + "\\NinjaTrader 7\\bin\\Custom\\Strategy\\Strategy.resx";

/// <summary>
/// Protect from being instantiated.
/// </summary>
protected StrategyEx()
{}
/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{

}
/// <summary>
/// overridden Dispose for disposing controls
/// </summary>
public override void Dispose()
{
if(Initialized)
{
if( ChartControl != null )
{
ToolStrip toolStrip = (ToolStrip) ChartControl.Controls["tsrTool"];

if( toolStrip != null )
{
//
// Dispose separator
//
if( tsSeparator != null )
{
toolStrip.Items.Remove(tsSeparator);
}

//
// Dispose Stop button
//
if( tsbtnStop != null )
{
tsbtnStop.Click -= new EventHandler(tsbtnStop_Click);
toolStrip.Items.Remove(tsbtnStop);
}

}
}

}
}
/// <summary>
/// This method is used to configure the strategy on first OnBarUpdate
/// </summary>
protected virtual void OnInitializeBeforeStart()
{

CreateToolStripButtons();
}


///
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if( !Initialized )
{
OnInitializeBeforeStart();
Initialized = true;
}
}


protected void CreateToolStripButtons()
{
if( ChartControl != null )
{
ToolStrip toolStrip = (ToolStrip) ChartControl.Controls["tsrTool"];

if( toolStrip != null )
{

//
// Create Separator
//
ToolStripSeparator tsSeparator = new ToolStripSeparator();
tsSeparator.Name = "tsSeparator";
toolStrip.Items.Add(tsSeparator);

//
// Create Stop Button
//
tsbtnStop = new ToolStripButton();
tsbtnStop.ImageTransparentColor = Color.Magenta;
tsbtnStop.Name = "tsbtnStop";
tsbtnStop.ImageTransparentColor = System.Drawing.Color.Magenta;
Image imgBtn = GetImageFromResX( strStrategyResXPath, bCanTrade ? "tsbtnStop.Image" : "tsbtnPlay.Image");
if( imgBtn != null )
{
tsbtnStop.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Ima ge;
tsbtnStop.Image = imgBtn;
}
else
{
tsbtnStop.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Tex t;
}
tsbtnStop.Text = bCanTrade ? "Disable trading" : "Enable trading";
tsbtnStop.Click += new EventHandler(tsbtnStop_Click);
toolStrip.Items.Add(tsbtnStop);

//
// Create another Button
//


}
}
}
private void tsbtnStop_Click(object sender, EventArgs e)
{
bCanTrade = !bCanTrade;

Image imgBtn = GetImageFromResX( strStrategyResXPath, bCanTrade ? "tsbtnStop.Image" : "tsbtnPlay.Image");
if( imgBtn != null )
{
tsbtnStop.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Ima ge;
tsbtnStop.Image = imgBtn;
}
else
{
tsbtnStop.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Tex t;
}
tsbtnStop.Text = bCanTrade ? "Disable trading" : "Enable trading";
}
static public Image GetImageFromResX(string resXPath, string imageResName)
{
// Create a ResXResourceReader for the resx file
ResXResourceReader rsxr = new ResXResourceReader(resXPath);
// Create an IDictionaryEnumerator to iterate through the resources.
IDictionaryEnumerator id = rsxr.GetEnumerator();
// Iterate through the resources and display the contents to the console.
foreach (DictionaryEntry d in rsxr)
{
if (d.Key.ToString() == imageResName)
{
//Close the reader.
rsxr.Close();
return (Image)d.Value;
}
}
//Close the reader.
rsxr.Close();
return null;
}

}
}

laparker
01-23-2010, 04:20 PM
dimkdimk

This is exactly what I am looking for. Could you do me a favor and tell me how to incorporate this in my strategy. What syntax would I need and where to call your code and get the extra buttons displayed. Probably a dumb question but I would welcome your help to get me started in the right direction.

-thanks

junkone
01-27-2010, 03:21 PM
you have shared something i had been dreaming about for a year or so. this opens a whole world of possibilities. thaks a lot!!!!

is it possible to add another row on the toolbar. you have demonstrated that it is possible to add components to the existing toolbar.
i was thinking of the following
1. add another row to the toolbar so that i can add more components specific to my strategy.
2. is it possible to add a textbox at the bottom of the form so that i can use it as a logging window for any messages that i get from my strategy.



Here is another example on how to create a button in ToolStrip of a chart window. Don't pay attention to those resources stuff as I just wanted to read resx file from Visual Studio.
Main idea is just get toolstrip control and add button as it is simply done in Visual Studio.

Pay special attention to call Dispose and remove button when it is disposing.
This is just a button and click handler to switch bool flag ( CanTrade or similar ). You may want to add other controls to toolstrip, just be careful and test as NT guys told us: It is dangerous.


#region Using declarations
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Resources;
using System.Collections;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Strategy;
using System.Windows.Forms;
using NinjaTrader.Gui.Chart;
#endregion
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
/// <summary>
/// TestStrat
/// </summary>
[Description("StrategyEx")]
public abstract class StrategyEx : Strategy
{
protected bool Initialized = false;

private ToolStripButton tsbtnStop = null; // Play/Stop Button to prevent Strategy from submitting orders
private ToolStripSeparator tsSeparator = null;
private bool bCanTrade = false;

protected string strStrategyResXPath = Environment.GetFolderPath(Environment.SpecialFolde r.Personal) + "\\NinjaTrader 7\\bin\\Custom\\Strategy\\Strategy.resx";

/// <summary>
/// Protect from being instantiated.
/// </summary>
protected StrategyEx()
{}
/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{

}
/// <summary>
/// overridden Dispose for disposing controls
/// </summary>
public override void Dispose()
{
if(Initialized)
{
if( ChartControl != null )
{
ToolStrip toolStrip = (ToolStrip) ChartControl.Controls["tsrTool"];

if( toolStrip != null )
{
//
// Dispose separator
//
if( tsSeparator != null )
{
toolStrip.Items.Remove(tsSeparator);
}

//
// Dispose Stop button
//
if( tsbtnStop != null )
{
tsbtnStop.Click -= new EventHandler(tsbtnStop_Click);
toolStrip.Items.Remove(tsbtnStop);
}

}
}

}
}
/// <summary>
/// This method is used to configure the strategy on first OnBarUpdate
/// </summary>
protected virtual void OnInitializeBeforeStart()
{

CreateToolStripButtons();
}


///
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if( !Initialized )
{
OnInitializeBeforeStart();
Initialized = true;
}
}


protected void CreateToolStripButtons()
{
if( ChartControl != null )
{
ToolStrip toolStrip = (ToolStrip) ChartControl.Controls["tsrTool"];

if( toolStrip != null )
{

//
// Create Separator
//
ToolStripSeparator tsSeparator = new ToolStripSeparator();
tsSeparator.Name = "tsSeparator";
toolStrip.Items.Add(tsSeparator);

//
// Create Stop Button
//
tsbtnStop = new ToolStripButton();
tsbtnStop.ImageTransparentColor = Color.Magenta;
tsbtnStop.Name = "tsbtnStop";
tsbtnStop.ImageTransparentColor = System.Drawing.Color.Magenta;
Image imgBtn = GetImageFromResX( strStrategyResXPath, bCanTrade ? "tsbtnStop.Image" : "tsbtnPlay.Image");
if( imgBtn != null )
{
tsbtnStop.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Ima ge;
tsbtnStop.Image = imgBtn;
}
else
{
tsbtnStop.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Tex t;
}
tsbtnStop.Text = bCanTrade ? "Disable trading" : "Enable trading";
tsbtnStop.Click += new EventHandler(tsbtnStop_Click);
toolStrip.Items.Add(tsbtnStop);

//
// Create another Button
//


}
}
}
private void tsbtnStop_Click(object sender, EventArgs e)
{
bCanTrade = !bCanTrade;

Image imgBtn = GetImageFromResX( strStrategyResXPath, bCanTrade ? "tsbtnStop.Image" : "tsbtnPlay.Image");
if( imgBtn != null )
{
tsbtnStop.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Ima ge;
tsbtnStop.Image = imgBtn;
}
else
{
tsbtnStop.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Tex t;
}
tsbtnStop.Text = bCanTrade ? "Disable trading" : "Enable trading";
}
static public Image GetImageFromResX(string resXPath, string imageResName)
{
// Create a ResXResourceReader for the resx file
ResXResourceReader rsxr = new ResXResourceReader(resXPath);
// Create an IDictionaryEnumerator to iterate through the resources.
IDictionaryEnumerator id = rsxr.GetEnumerator();
// Iterate through the resources and display the contents to the console.
foreach (DictionaryEntry d in rsxr)
{
if (d.Key.ToString() == imageResName)
{
//Close the reader.
rsxr.Close();
return (Image)d.Value;
}
}
//Close the reader.
rsxr.Close();
return null;
}

}
}

dimkdimk
01-27-2010, 04:49 PM
is it possible to add another row on the toolbar. you have demonstrated that it is possible to add components to the existing toolbar.
i was thinking of the following
1. add another row to the toolbar so that i can add more components specific to my strategy.
2. is it possible to add a textbox at the bottom of the form so that i can use it as a logging window for any messages that i get from my strategy.

p.1 - Probably, yes, but I have not tried.
p.2 - I am trying to achieve the same but I worry about coordinates of the chart window. If we start cutting it with our extra controls then we can screw up NinjaTrader charting window. I suggest, instead, to create a separate form ( similar to Data Box ) and dump all your stuff there. I will try to implement this soon.

For p.2 : there is alternative approach: you can use margin on the right of the chart. There were a few examples on this forum that utilise this area. I guess, you can tell then to Chart to not to draw in this area. There is a property of a chart about this.

With all these good things that you can do please remember that there might be some code in Ninja that rely on current state of forms and can be broken if we stuff it with new extra "frameworks" :-)

clfield
02-03-2010, 07:06 PM
I have been unable to get this to work....I copied the code you posted into a strategy file. Although it does compile, it does not show up in my strategies list on the chart??
I added the line

[Gui.Design.DisplayName("StrategyEx")]

but that did not help.
I as sure that it is something simple that I am missing...but C# seems to continue to baffle me.

It would be really great to have the option to put buttons on the tool bar to be able to control the strat without having to reload it every time.
Thanks for the help

dimkdimk
02-04-2010, 12:11 AM
I have been unable to get this to work....I copied the code you posted into a strategy file. Although it does compile, it does not show up in my strategies list on the chart??

Sorry for little explanation. The code was just to give an idea of how you could implement this yourself.
The reason it is not showing up :
This is an abstract class. When I create my new strategies I inherit them from this class, but not from the deafault one:

MyNewStrategy : public StrategyEx

So this class is not intendent to be shown in the list. It is just for programming purposes. You can add similar code to UserDefined.cs-like code. It is very well described in NT help ( for v.6.5 ). By adding methods of the code above to strategy's partial class in UserDefault.cs you will enable ALL your strategy to behave like this. If you don't want them all to do this then make something like I did above.
Or, just create a new strategy and add those things into its body. In this case only one strategy will be able to do this stuff.

P.S. This is advanced stuff so please think what you are doing. If you don't know how then it is better not to do this as it might break something in NT.

clfield
02-04-2010, 07:17 AM
I was able to fashion the code into an indicator which does put the buttons in the tool bar...but it does not seem to update the state of the bool operators in a timely fashion. I am new to this area of C#. I tried to place print statements in the indicator to verify the state of the bool variables attached to the buttons and print statements in the event method. The second seems to cause NT trouble.
Any ideas?

Mindset
02-08-2010, 04:03 AM
ZapZap and dimkdimk.
I love this when the true power of NT is exposed. Excellent work.

Mindset
02-09-2010, 03:06 AM
Learning from your workspace button code...
Why is restore empty? Doesn't seem to be required.


if (String.Compare(ws[cnt],ws[0]) == 0) restore(ws[cnt]);
else switchTo(ws[cnt]);


replaced with


if (String.Compare(ws[cnt],ws[0]) != 0)
switchTo(ws[cnt]);


compiles and works but is it good coding?

AlePaciotti
02-19-2010, 09:31 PM
I have not been able to bring up a button on the chart. I tried putting the code in UserDefined.cs and instantiate from another indicator or strategy but I am denied the possibility. It is very important for me to accomplish this because the source of a large project. Someone could give me a basic but functional example?

AlePaciotti
02-19-2010, 10:05 PM
Question: how could you do to call the FORM with a button on the CHART?


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

kenz987
03-20-2011, 03:35 PM
Hey Zap: I never would have thought of using a rectangle for a button, very clever and thank you for the post.
Also Dimk, Many thanks.
Ken

Mindset
03-21-2011, 12:58 AM
you have shared something i had been dreaming about for a year or so. this opens a whole world of possibilities. thaks a lot!!!!

is it possible to add another row on the toolbar. you have demonstrated that it is possible to add components to the existing toolbar.
i was thinking of the following
1. add another row to the toolbar so that i can add more components specific to my strategy.



You could use RichTextBox and then make up your own buttons. I did this for a customer a month or so back.

FREEN
11-05-2011, 06:30 AM
Waking up an old and interesting thread here.

I think the jtEconNews indicator panel would make an excellent base for custom input/output GUI´s. That is, if it´s not to much hassle populating it with labels/buttons and coupling events to NT. I´ve send a PM the the author - j0hnth0m - and asked him if he would mind sharing his experience and that part of the jtEconNews code.

FREEN
11-08-2011, 01:46 AM
Waking up an old and interesting thread here.

I think the jtEconNews indicator panel would make an excellent base for custom input/output GUI´s. That is, if it´s not to much hassle populating it with labels/buttons and coupling events to NT. I´ve send a PM the the author - j0hnth0m - and asked him if he would mind sharing his experience and that part of the jtEconNews code.

I´m forwarding this request to you NT guys as well. An indicator panel that can be populated with labels and buttons rather than the "standard" graphics would be appreciated.

Kindly, Fredrik

NinjaTrader_Matthew
11-08-2011, 08:38 AM
Fredrik,


We appreciate your suggestion and have assigned this feature request ID # 1370 in our tracking system.