Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Condition only applies the first time
Collapse
X
-
Condition only applies the first time
hello. Excuse my English. I am a novice programmer. I have an indicator that I want to draw the bar a color and play a sound when a condition is given THE FIRST TIME. If I use Calculate.OnPriceChange or Calculate.OnEachTick the drawing and sound repeat constantly. How could I do so that both drawing and sound are only performed the first time the condition is met? thank you.Tags: None
-
Hello julifro,
You could use a bool variable for that. On each first tick of the bar you could reset the variable so that each new bar the condition can be checked again. Inside the condition you would toggle the bool so that the condition is not true after the first time it happens.
private bool myBool;
Code:protected override void OnBarUpdate() { if (IsFirstTickOfBar) { myBool = false; } if(myBool == false && Close[0] > Open[0]) { // do the alert myBool = true; } }
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
598 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
343 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
103 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
557 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
555 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment