Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
How to Create Plot Values For Use in Strategy
Collapse
X
-
How to Create Plot Values For Use in Strategy
Hello, I added bool variables to an indicator and I would like to make them available for use in a strategy. How can I do this? thanksTags: None
-
Hello ronaldgreene828,
You can make a bool, or a Series<bool> a public property to make this accessible to a host strategy.
Below is a link to the reference sample that demonstrates.
And a link to the help guide on Update().
However, please note only public Plot series can be used in the Strategy Builder specifically.
I'm trying to expose my variables to the strategy builder so everyone can have better use of the WaveTrend indicator (it has a lot of code). Explain this to me like I am 5 because this isnt the first time I've tried to figure it out and hit a wall. What is Series? I know its like an array that stores bars. Why not just call itChelsea B.NinjaTrader Customer Service
-
Thanks. I followed the example in SampleBoolSeries for 3 bool variables. I get the following error for each variable:
."The type Ninjatrader.Ninjascript.Indicator.SSLHybrid already contains a definition for 'WhiteDot'"
I entered the variables into the script only as shown in the example. I uploaded a text file.Attached FilesLast edited by ronaldgreene828; 06-12-2022, 06:20 PM.
Comment
-
Hello ronaldgreene828,
As a tip, to export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:- Click Tools -> Export -> NinjaScript...
- Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
- Click the 'Export' button
- Enter a unique name for the file in the value for 'File name:'
- Choose a save location -> click Save
- Click OK to clear the export location message
- (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
http://ninjatrader.com/support/helpG...-us/export.htm
You have two variables being declared with the same name. In C# you cannot re-use names. Once a variable is declared, no other variable, struct, or method can use that name.
private Series<bool> WhiteDot; <-- declared as a private variable
public Series<bool> WhiteDot <-- you cannot declare this a second time. You must choose a different name.
{
get { return WhiteDot; } // Allows our public WhiteDot Series<bool> to access and expose our internal WhiteDot Series<bool>
}
Most coders will use a lowercase for the first letter for all private variables and an uppercase first letter for all public variables, as these will be different.Chelsea B.NinjaTrader Customer Service
Comment
-
I see that now in the SampleBoolSeries and I did the same, using lower case first letter for the private variables and upper case first letter declaring the public variables. The plots for WhiteDot, GreenDot and PurpleDot are available now in the strategy builder. I created a test strategy to display the plot values. I'm getting the following error:
Strategy 'A2SSLHybrid'; Error on calling 'OnBarUpdate' method on bar 256: Index was outside the bounds of the array.
I'm only referencing values associated with Close[0] in the fixed text statement. What is causing the error?Attached FilesLast edited by ronaldgreene828; 06-13-2022, 07:34 AM.
Comment
-
Hello ronaldgreene828,
This would be an indexing error. Meaning an index used larger than the size of the collection.
Make a test indicator script and copy only the declaration of this one series. Does the error still occur?
If so, provide an export of the reduced test script.Chelsea B.NinjaTrader Customer Service
Comment
-
I thought that's what I created in the file attached. I followed the steps for exporting and I attached the file that was created. I see that it contains the indicator in the Indicator folder and the test script in the strategy folder. I didn't mean to send both, but that's what was generated in the zip file during export.
Comment
-
Hello ronaldgreene828,
This is not what is provided in your previous post. This appears to be the full indicator and is not reduced to a test script with only the plot added and value set. There appears to be many hundred lines of extra code.
Are you certain you are providing the test indicator and not the actual indicator?Chelsea B.NinjaTrader Customer Service
Comment
-
Inside the file in the strategy folder is the test strategy. I used the strategy builder to make one set with fixed text. It displays the plot for 3 variables for the indicator. Ninjatrader automatically included all of the plots in the script, but I only added one set and I never unlocked the code for the editor. Should I copy the OnBarUpdate portion and send that only?
Comment
-
Hello ronaldgreene828,
What line of code is causing the error? Is the error occurring when calling the indicator?
Is the error actually in the indicator?
Can you comment out the calls to the indicator and still reproduce the error in the strategy?
If the error can only be reproduced when calling the indicator, the issue is with the indicator.
Please provide a reduced indicator with only the plot added and made public.
Reducing is how to identify and correct an issue.Chelsea B.NinjaTrader Customer Service
Comment
-
I already made the test strategy, and that's what I'm having a problem with. It won't enable in a chart. Will making a test indicator help? I'm not sure how to do this.
Comment
-
They were bool values, WhiteDot, GreenDot and PurpleDot. I changed the values for display in fixed text to Close[0], Open[0] and High[0] and now it enables in a chart.
Comment
-
I commented out the fixed text line and the strategy enables. I don't get how bool values can look back if they are true/false. There is no other line added in OnBarUpdate.
The values called are whiteDot, greenDot and purpleDot and now I see that in the indicator they are used as whiteDot[0], greenDot[0] and purpleDot[0]. I don't see them referenced in any other way but for the last closed bar.Last edited by ronaldgreene828; 06-13-2022, 12:37 PM.
Comment
-
Hello ronaldgreene828,
Calling an indicator will run the code in that indicator. If the indicator encounters an error, then the host script is disabled.
To make an indicator right-click the Indicators folder in the NinjaScript Editor -> select New Indicator.
Add the code to define one of the plots. Try doing the WhiteDot plot only.
Then call the test indicator from the test strategy.Chelsea B.NinjaTrader Customer Service
Comment
-
I found my error. After creating bool series variables to call values for plot, I realized that I need to move them to the buffer region. I copied and pasted the format from other lines that had double values and then I didn't replace the portion in brackets with "get { return whiteDot; }" etc. When compiling I didn't get an error but now I found it. Thanks for helping me work through this.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
648 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
369 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
108 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
572 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
574 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|
Comment