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 CaptainJack, 05-29-2026, 05:09 AM
|
0 responses
245 views
0 likes
|
Last Post
by CaptainJack
05-29-2026, 05:09 AM
|
||
|
Started by CaptainJack, 05-29-2026, 12:02 AM
|
0 responses
157 views
0 likes
|
Last Post
by CaptainJack
05-29-2026, 12:02 AM
|
||
|
Started by charlesugo_1, 05-26-2026, 05:03 PM
|
0 responses
165 views
1 like
|
Last Post
by charlesugo_1
05-26-2026, 05:03 PM
|
||
|
Started by DannyP96, 05-18-2026, 02:38 PM
|
1 response
250 views
0 likes
|
Last Post
|
||
|
Started by CarlTrading, 05-11-2026, 05:56 AM
|
0 responses
201 views
0 likes
|
Last Post
by CarlTrading
05-11-2026, 05:56 AM
|

Comment