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
This Indicator is crashing NT.
Collapse
X
-
This Indicator is crashing NT.
Attached is just a sample Indicator that is part of a larger project. When I try to load the NT Indicator list, this indicator crashes NT. I have attached the zip and removed everything from it except for the code that is pertinent. Can you take a peek at it and give me a nudge in the right direction? I can't figure this one out. -
to prevent crash
move
Code:sectors.Add(new S("XLK",26.28));
Code:if (State == State.SetDefaults)
Code:else if (State == State.DataLoaded)
to prevent further endless cpu usage
update
Code:public class S { private double weight; public S(string ticker,double weight) { Ticker = ticker; Weight = noWeighting ? 100 : weight; } public double Weight { get { return noWeighting ? 100 : weight; } set { weight = value; } } public string Ticker { get; set; } }
additional note
if you ever load this indicator onto a chart that is not minute-based, you may get irregular results, depending on what your full code is actually doing. This is due to
Code:AddDataSeries("XLK",BarsPeriodType.Minute,BarsPeriod.Value);
If you are trying to keep your added dataseries' timeframe the same as your primary bars, you can try using
Code:AddDataSeries("XLK");
Last edited by gubbar924; 10-09-2018, 03:41 AM.
- Likes 1
-
Hello swooke,
Thanks for your post. And thank you gubbar924 for providing suggestions to help swooke fix his code.
I have included a video and some that explains the NinjaScript lifecycle and how OnStateChange can be used with best practices. Essentially, operations that do not depend on data being loaded should be done in State.Configure, operations that do depend on data should be done in State.DataLoaded. BarsPeriod.Value would depend on data being loaded and may not always be available in State.Configure which is why using AddDataSeries("XLK"); would be recommended.
Suggested reading for the NinjaScript LifeCycle and Best practices is linked below.- NinjaScript LifeCycle video:https://youtu.be/gyel6m3VIWs
- Best Practices: https://ninjatrader.com/support/helpG...
- LifeCycle: https://ninjatrader.com/support/helpG...
- OnStateChange: https://ninjatrader.com/support/helpG...
Attached FilesJimNinjaTrader Customer Service
Comment
-
Jim,
Is there any way you could comment on my really stripped down script? I reduced it from about 2500 lines to demonstrate a the issue. I tried following the advice given in the previous post but NT still crashed. The script is pretty small. I just need a little direction on where I am going wrong.
Comment
-
Hello swooke,
The code that is generating the issue is from your custom class and HashSet code. This sort of implementation would be outside the context of NinjaScript support. The issue sounds like you are caught in an infinite loop. Looking at the code provided, I would suggest checking your getters and setters for any recursive operations to troubleshoot further. For example, referencing the same public property in the getter instead of getting the backing field property or setting the backing field with the public property instead of value in the setter.
Here is an example that can be modeled:
Code:public string DisplayText { get { return displayText; } set { if (displayText == value) return; displayText = value; needsLayoutUpdate = true; } }
JimNinjaTrader Customer Service
Comment
-
Thanks for the direction. That was a big help. One last question, is it a common design pattern to stop the render function when a user opens the settings window? Is this just done with an if statement at the top of the render function to check of the window is open?
Comment
-
Hello swooke,
This is not a common practice. Charts will still update with the indicator dialog open, for example, and skipping rendering operations would prevent the indicator from updating visually with this open. I'm also not aware of any supported way to do this.
Best Practices for performance when writing NinjaScript can be referenced here - https://ninjatrader.com/support/help...tm#Performance
Please let us know if you have any questions.JimNinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by andrewtrades, Today, 04:57 PM
|
1 response
5 views
0 likes
|
Last Post Today, 05:02 PM | ||
Started by chbruno, Today, 04:10 PM
|
0 responses
5 views
0 likes
|
Last Post
by chbruno
Today, 04:10 PM
|
||
Started by josh18955, 03-25-2023, 11:16 AM
|
6 responses
436 views
0 likes
|
Last Post
by Delerium
Today, 03:42 PM
|
||
Started by FAQtrader, Today, 03:35 PM
|
0 responses
7 views
0 likes
|
Last Post
by FAQtrader
Today, 03:35 PM
|
||
Started by rocketman7, Today, 09:41 AM
|
5 responses
19 views
0 likes
|
Last Post Today, 03:33 PM |
Comment