I will also like a method of reset for trend bars thank you
Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
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
}
Paul H.NinjaTrader Customer Service
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.
Paul H.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Kaledus, Today, 01:29 PM
|
0 responses
3 views
0 likes
|
Last Post
by Kaledus
Today, 01:29 PM
|
||
Started by PaulMohn, Today, 12:36 PM
|
1 response
16 views
0 likes
|
Last Post Today, 01:23 PM | ||
Started by yertle, Yesterday, 08:38 AM
|
8 responses
37 views
0 likes
|
Last Post
by ryjoga
Today, 01:22 PM
|
||
Started by rdtdale, Today, 01:02 PM
|
1 response
6 views
0 likes
|
Last Post Today, 01:13 PM | ||
Started by alifarahani, Today, 09:40 AM
|
3 responses
19 views
0 likes
|
Last Post Today, 12:47 PM |
Comment