I will also like a method of reset for trend bars thank you
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Variables.
Collapse
X
-
Hello Emma1,
Thanks for your reply.
The words "set" and "reset" could be applied to an integer based counter or could be applied to a bool variable.
for example, in pseudo code:
if (condition to determine a trend is true)
{
myTrend = true; // set a bool variable called myTrend to true
}
else
{
myTrend = false; // reset bool when no longer a trend
myHighCounter = 0; // reset integer high bar counter variable to zero for next trend
myLowCounter = 0; // reset integer low bar counter variable to zero for next trend
}
if (myTrend)
{
// some function to check if current bar is a high bar
myHighBarCounter++; //increment an int variable called myHighCounter
// some function to check if current bar is a low bar
myLowBarCounter++; //increment an int variable called myLowCounter
}
Comment
-
Thank you Paul. One way I define an up trend is when plot 1 of my custom indicator exceeds the value of the most recent swing high of plot 1, and I define a downtrend when plot 2 drops below the most recent swing low of plot 2. I don't have a screenshot, but my primary questions are:
1) Where do I define my variable "Trend" so it persists from bar to bar. Would it be for example created under State.Setdefaults or State.Configure?
2) Is under OnBarUpdate() the best place to test for the Trend conditions and set the Trend variable value?
Comment
-
Hello Emma1,
Thanks for your reply.
If your variable 'Trend" is only to be used in the indicator then you could create it at the class level (I place mine just before OnStateChange() for ease of reading).
Yes, you can certainly use OnBarUpdate() for your trend coding. If you create your variable at the class level, then you could also create other methods outside of OnBarUpdate() and be able to access the variable.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
576 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
334 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
553 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
551 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment