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 Hwop38, 05-04-2026, 07:02 PM
|
0 responses
174 views
0 likes
|
Last Post
by Hwop38
05-04-2026, 07:02 PM
|
||
|
Started by CaptainJack, 04-24-2026, 11:07 PM
|
0 responses
329 views
0 likes
|
Last Post
by CaptainJack
04-24-2026, 11:07 PM
|
||
|
Started by Mindset, 04-21-2026, 06:46 AM
|
0 responses
252 views
0 likes
|
Last Post
by Mindset
04-21-2026, 06:46 AM
|
||
|
Started by M4ndoo, 04-20-2026, 05:21 PM
|
0 responses
356 views
0 likes
|
Last Post
by M4ndoo
04-20-2026, 05:21 PM
|
||
|
Started by M4ndoo, 04-19-2026, 05:54 PM
|
0 responses
183 views
0 likes
|
Last Post
by M4ndoo
04-19-2026, 05:54 PM
|

Comment