View Full Version : Using output variables within a strategy?
Burga1
11-15-2007, 08:52 PM
Greetings,
I'm trying to code my first strategy. My question is how do you use the wizard to extract "calculated output" variables from within an indicator? For example I see where you can have the inputs of a particular indicator manipulated to do things...however what about variables whose values are calculated within the indicator? They don't seem to show up as optional values to use within the wizard...
Thanks in advance.
NinjaTrader_Josh
11-15-2007, 10:39 PM
Hi Burga1,
When you choose the indicator from the list there will be an option known as "Plot". From there you can choose any variable that is exposed in the indicator. For example, if you look at the Stochastics indicator you will see a plot for the D and the K values. You can choose whichever one you want to use.
Burga1
11-16-2007, 08:50 AM
Hmm, OK I see that. So if I have a custom indicator I made and I want to be able to access variables calculated within that indicator--I need to make them "Plots"...and would that be accomplished using this code for example:
Add(new Plot(Color.FromKnownColor(KnownColor.PaleTurquoise ), PlotStyle.Line, "Name equal to my variable"));
If that is not correct then can you please let me know...? Thanks in advance.
NinjaTrader_Ray
11-16-2007, 09:13 AM
That is one way to do it. Another is to just store data in a DataSeries object and provide a public property for this DataSeries object.
PrTester
11-16-2007, 11:51 AM
That is one way to do it. Another is to just store data in a DataSeries object and provide a public property for this DataSeries object.
Ray, can you put in the pipeline some example regarding public property for DataSeries in the Reference Sample Section.
Regards,
NinjaTrader_Ray
11-16-2007, 11:54 AM
Already ahead of you :)
Will have something in the near future... Thanks for the suggestion!
Burga1
11-16-2007, 03:17 PM
OK, thanks...so something like this should be acceptable then...
Add(new Plot(Color.FromKnownColor(KnownColor.PaleTurquoise ), PlotStyle.Line, "SIGNAL"));
...
VALUE1 = 100 * (Inside12 / Inside22);
Signal.Set(VALUE1);
SIGNAL = EMA(Signal, Sig)[0];
thanks in advance.
Burga1
11-16-2007, 03:29 PM
Sorry, another question. What happens if it is named incorrectly? I used the wizard initially to setup the code template and inadvertantly used names I didn't want for the "Add(new plot...etc)" line. It seems I cannot simply change the names, they still appear in the strategy wizard under the old names in the "Plot" field...thanks again.
NinjaTrader_Ray
11-16-2007, 03:44 PM
Check under the "Properties" region and remove any unwanted properties.
Burga1
11-16-2007, 04:05 PM
Thanks. That worked to remove the unwanted properties. However now I have no properties to be able to choose from in the strategy builder. I guess that code I wrote below in the 5:17pm post is not acceptable then?
NinjaTrader_Ray
11-16-2007, 04:33 PM
We will post a reference sample in the near future that will illustrate the correct approach for exposing a property.
In a nutshell, declare a DataSeries variable internal to your strategy, set values to it, expose this DataSeries as a property.
See the reference sample section for info on DataSeries, then look at any indicator's "Property" region to get an idea on how to expose a property.
Burga1
11-16-2007, 07:24 PM
Hi,
I'm sorry but I'm not following you. I believe you mean something like this (in the "properties" section):
[Description("Main_SIGNAL")]
[Category("Parameters")]
public double The_ROC
{
get { return The_ROC; }
set { The_ROC = EMA(Signal, Sig)[0]; }
}
However when I attempt to add such commands I get warnings/errors about a possible crash...
Thank you.
NinjaTrader_Dierk
11-17-2007, 12:00 AM
Correct, since your code while throw C# for and endless loop. Needed to be:
[Description("Main_SIGNAL")]
[Category("Parameters")]
publicdouble The_ROC
{
get { return the_ROC; }
set { the_ROC = EMA(Signal, Sig)[0]; }
}
Note the capitalization
Burga1
11-17-2007, 08:00 AM
Thanks for the reply. Why does the "t" at the start of the variable name need to be small case while in the "publicdouble" definition it can be capitalized?
NinjaTrader_Dierk
11-17-2007, 08:04 AM
Unfortunately we are unable to provide support for basic C# programming questions. Please consult the C# docs from Microsoft to understand how C# properties work.
Why does the "t" at the start of the variable name need to be small case while in the "public double" definition it can be capitalized?
This is because they are different variable names, for two different doubles. The property defines "The_ROC", whereas "the_ROC" should be defined in the "Variables" region of your indicator.
Take a look at almost ANY indicator provided with NinjaTrader or created by the wizard, and you will see this duality.
And other than that, you really do need to get some C# training or read a C# tutorial, there are lots of them on the Internet.