Which came last.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Last value above or below in arrays
Collapse
X
-
Hello fatbat,
Thanks for your post and welcome to the NinjaTrader forums!
If I understand correctly you are looking for a way to have a signal to show which last occurred, either RSI > 80 or RSI < 20. The easist way would be to use a bool variable (either true or false) that is set by checking for the conditions. For example, you can create bool called rsiFlag that is set true when RSI goes above 80 and then is set false when RSI is less than 20:
Your code can then use the bool condition to identify what last occurred.Code:if (RSI(14, 3)[0] > 80) { rsiFlag = true; } else if (RSI(14, 3)[0] < 20) { rsiFlag = false; }
If you wanted to know when the last occurrence was you could save the bar number into an int variable for example called savedBar that you can then use like CurrentBar - SavedBar = barsago of the last occurrence.
-
Hello fatbat,
Thanks for your reply.
You can declare the bool in the area called #region variables, for example:
private bool rsiFlag = false;
In the onBarUpdate() method, the code example previously provided will only change the state of the bool if either of the RSI conditions are met. It would not change on every bar unless the RSI went from <20 to >80 or vice versa from one bar to the next.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
563 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
329 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
547 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
548 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment