Any comments?
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
using 'while'
Collapse
X
-
Could it be that your while loop never exits and causes an infinite loop?Originally posted by Rigsby66 View PostIt seems that if I use a 'while' loop in the OnBarUpdate(), I get a crash....
Any comments?
For example:
int myInt = 5;
while (myInt == 5)
// Do somethingRayNinjaTrader Customer Service
Comment
-
Well, if for example I use:Originally posted by NinjaTrader_Ray View PostCould it be that your while loop never exits and causes an infinite loop?
For example:
int myInt = 5;
while (myInt == 5)
// Do something
while (Stochastics(7, 14, 3).D[0] < 50)
{
Print(Stochastics(7, 14, 3).D[0]);
}
Comment
-
Well, I know that because as I already said Ninja crashes when I do it.Originally posted by NinjaTrader_Austin View PostRigsby, the code you posted would definitely cause an infinite loop and crash NinjaTrader because the loop doesn't have an exit.
The point is that there is an exit. The exit should be when the stochastics go >=50. This is the point of a while statement. It checks for a condition until it is met.... So I guess I need to do a while but grab the stochastics myself in each loop as this is obviously not happening otherwise..
Maybe I need to add that I am not a trader and am not a C# programmer... I am a C programmer who has lost his way... LOL
Comment
-
The stochastics in each loop will always be the same value since it does not change between the time OnBarUdpate() is called and exited thus you will still have the problem.Originally posted by Rigsby66 View PostWell, I know that because as I already said Ninja crashes when I do it.
The point is that there is an exit. The exit should be when the stochastics go >=50. This is the point of a while statement. It checks for a condition until it is met.... So I guess I need to do a while but grab the stochastics myself in each loop as this is obviously not happening otherwise..
Maybe I need to add that I am not a trader and am not a C# programmer... I am a C programmer who has lost his way... LOLRayNinjaTrader Customer Service
Comment
-
Rigsby, why won't an if statment work?
Code:[FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (Stochastics([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]7[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]14[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]3[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]).D[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]] < [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]50[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/SIZE][/FONT] [SIZE=2][FONT=Courier New]{[/FONT][/SIZE] [SIZE=2][FONT=Courier New]// Stochastics are less than 50. do something.[/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2] [SIZE=2][FONT=Courier New]} [/FONT][/SIZE][/SIZE][/FONT]
AustinNinjaTrader Customer Service
Comment
-
I was only poking for reactions.... As I said in my firs post, "any comments"....Originally posted by NinjaTrader_Austin View PostRigsby, why won't an if statment work?
Code:[FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (Stochastics([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]7[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]14[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]3[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]).D[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]] < [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]50[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/SIZE][/FONT] [SIZE=2][FONT=Courier New]{[/FONT][/SIZE] [SIZE=2][FONT=Courier New]// Stochastics are less than 50. do something.[/FONT][/SIZE][/SIZE][/FONT] [SIZE=2][FONT=Courier New][SIZE=2][FONT=Courier New]}[/FONT][/SIZE] [/FONT][/SIZE]
I guess I am just trying to find a more reliable cycle than OnBarUdpate()
Comment
-
OnBarUpdate() gets called for each and every tick (if CalculateOnBarClose = false). When OnBarUpdate gets called all indicators and values and such are updated and correct.Originally posted by Rigsby66 View PostI guess I am just trying to find a more reliable cycle than OnBarUdpate()
Lets take a step back, what do you mean by you want to find a more reliable cycle than OnBarUpdate?AustinNinjaTrader Customer Service
Comment
-
Sorry
Sorry, reliable is not what I meant... I meant more "kind of everything and not just a bar update" and have now found OnMarketData - so problem solved on that one.Originally posted by NinjaTrader_Austin View PostLets take a step back, what do you mean by you want to find a more reliable cycle than OnBarUpdate?
Thanx
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
571 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
330 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 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
548 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
549 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment