Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
Initialization error
Collapse
X
-
Initialization error
When I first add an indicator it returns the attached error. But once I save a template with a value it is fine. This also happens with Strategy Analyzer but there is no way to same a template with a value for optimization variables there. How do I initialize in my code to prevent this?Last edited by EthanHunt; 08-17-2017, 07:03 AM.Tags: None
-
Hello EthanHunt,
What is the range allowed for this public property?
The error indicates you are setting the range between 1 and int.MaxValue, is this correct?
What is the initial value you are setting it to in State.SetDefaults?
(This would be something that affects c# and is not specific to NinjaScript)Chelsea B.NinjaTrader Customer Service
-
Yes the range is 1 and int.MaxValue. I have the value set to 50 in State.SetDefaults. That doesn't seem to be initializing? Thanks.
Originally posted by NinjaTrader_ChelseaB View PostHello EthanHunt,
What is the range allowed for this public property?
The error indicates you are setting the range between 1 and int.MaxValue, is this correct?
What is the initial value you are setting it to in State.SetDefaults?
(This would be something that affects c# and is not specific to NinjaScript)
Comment
-
Property declaration....
#region Properties
[Range(1, int.MaxValue), NinjaScriptProperty]
[Display(ResourceType = typeof(Custom.Resource), Name = "Period", GroupName = "NinjaScriptParameters", Order = 0)]
public int Period
{get; set;}
#endregion
Here is the State.SetDefaults...
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "Trading_Strategy";
Calculate = Calculate.OnBarClose;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = false;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 0;
StartBehavior = StartBehavior.WaitUntilFlat;
TimeInForce = TimeInForce.Gtc;
TraceOrders = false;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
StopTargetHandling = StopTargetHandling.PerEntryExecution;
BarsRequiredToTrade = 20;
// Disable this property for performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = true;
int Period = 50;
}
else if (State == State.Configure)
{
}
}
Originally posted by NinjaTrader_ChelseaB View PostHello EthanHunt,
Can you supply the code where the property is declared as well as the State.SetDefaults action block so that we may take a look?Last edited by EthanHunt; 08-17-2017, 10:50 AM.
Comment
-
Hi EthanHunt,
This all looks correct.
I'm not able to reproduce the behavior using the code supplied.
Attached is a test script. Are you able to reproduce the behavior with the test script?
Do you have template created for this strategy?
If the template is deleted does the error does continue?Attached FilesChelsea B.NinjaTrader Customer Service
Comment
-
I do not get an error with the code you supplied. I deleted the template and still get the error with my code.
Originally posted by NinjaTrader_ChelseaB View PostHi EthanHunt,
This all looks correct.
I'm not able to reproduce the behavior using the code supplied.
Attached is a test script. Are you able to reproduce the behavior with the test script?
Do you have template created for this strategy?
If the template is deleted does the error does continue?
Comment
-
Hello EthanHunt,
Please (copy and then) reduce the script to remove all logic but still produce the error.
Then, export the reduced script and post the export with your next post.
To export a NinjaTrader 8 NinjaScript do the following:- Click Tools -> Export -> NinjaScript...
- Click the 'add' link -> check the box(es) for the script(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
By default your exported file will be in the following location:- (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
Below is a link to the help guide on Exporting NinjaScripts.
Chelsea B.NinjaTrader Customer Service
Comment
-
File attached. When I run this script in Strategy Analyzer it gives me the error message.
Originally posted by NinjaTrader_ChelseaB View PostHello EthanHunt,
Please (copy and then) reduce the script to remove all logic but still produce the error.
Then, export the reduced script and post the export with your next post.
To export a NinjaTrader 8 NinjaScript do the following:- Click Tools -> Export -> NinjaScript...
- Click the 'add' link -> check the box(es) for the script(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
By default your exported file will be in the following location:- (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
Below is a link to the help guide on Exporting NinjaScripts.
http://ninjatrader.com/support/helpG...-us/export.htmAttached Files
Comment
-
Hello EthanHunt,
I overlooked that you are declaring Period twice.
Its declared as an int property in the scope of the class and then declared again locally in OnStateChange().
When you use int or any other stuct type before a variable name you are declaring a variable with the type of int.
(You may notice the other variables being set in OnStateChange do not have type declarations in front of them)
This means the local Period that can only be used in State.SetDefaults is being set to 1, while the Period declared in the class of the indicator is never being set and has a default value of 0.Chelsea B.NinjaTrader Customer Service
Comment
-
Yes that is it, declaring the type within OnStateChange(). I took out the int declaration and it runs fine. Thank you!
Originally posted by NinjaTrader_ChelseaB View PostHello EthanHunt,
I overlooked that you are declaring Period twice.
Its declared as an int property in the scope of the class and then declared again locally in OnStateChange().
When you use int or any other stuct type before a variable name you are declaring a variable with the type of int.
(You may notice the other variables being set in OnStateChange do not have type declarations in front of them)
This means the local Period that can only be used in State.SetDefaults is being set to 1, while the Period declared in the class of the indicator is never being set and has a default value of 0.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Padan, Today, 02:02 AM
|
5 responses
16 views
0 likes
|
Last Post Today, 11:14 AM | ||
Started by Lele2k24, Yesterday, 11:24 AM
|
8 responses
28 views
0 likes
|
Last Post
by Lele2k24
Today, 11:00 AM
|
||
Started by kramnor2001, Yesterday, 02:30 PM
|
4 responses
24 views
0 likes
|
Last Post
by bltdavid
Today, 10:44 AM
|
||
Started by eduardodipp7, Today, 10:29 AM
|
0 responses
2 views
0 likes
|
Last Post
by eduardodipp7
Today, 10:29 AM
|
||
Started by AgriTrdr, 07-16-2023, 12:54 PM
|
39 responses
272 views
0 likes
|
Last Post
by f.saeidi
Today, 10:23 AM
|
Comment