Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Need help with some C# Counting Code
Collapse
X
-
Hello Dwight292,
Thanks for your post and welcome to the NinjaTrader forums!
You didn't mention what the counter is counting. I suspect you want to count the number of bars that pass after the first condition to then be a condition to then trigger the second counter which again I will assume is counting bars that pass.
In the example below, the assumptions are that you want to count on bars and that you are using Calculate.OnBarClose. The counters would be declared as private integers and for the purposes of the example will call them counter1 and counter2, which are initialized to 0. In addition, a couple of variables would be declared as bools and initialized as false and are called startcounter1 and startcounter2.
if (Close[0] < Close[4] && counter1 == 0)
{
startcounter1 = true; // set a bool true
}
if (Startcounter1)
{
counter1++; // increment counter1
}
if (counter1 >= 9 && Close[0] <= Low[2]) // check for 2nd trigger
{
startcounter2 = true; // start the 2nd counter
}
if (startcounter2)
{
counter2++; // increment counter2
}
Depending on what you are trying to do, you would also likely want to reset the counters and the bools and would need a condition to do that.
if (some condition to reset counters)
{
startcounter1 = false;
startcounter2 = false;
counter1 = 0;
counter2 = 0;
}
-
Not really clear if the 2 conditions need to occur at the same time, but this may give you a pointer to what you want to achieve
if ( Close[0] < Close[4] )
{
Count1++;
if ( Close[0] <= Low[2] && Count1 >= 9 )
Count2++;
}
Leave a comment:
-
Need help with some C# Counting Code
I'm trying to code a counter in Ninjatrader which uses C# as its programming language.
I would like this counter to commence counting upon the completion of the first counter and once it commences counting to consider only the new condition when counting.
So, the first counter commences when Close[0] < Close[4]. The second counter commences ONLY after the first counter has reached 9 and its condition for counting is Close[0] <= Low[2].
I don't know how to write the part of the code where the second counter commences counting and its counts are independent of the first counter reaching 9.
MyBKExperienceLast edited by Dwight292; 01-11-2019, 10:52 PM.Tags: None
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by kujista, Today, 12:59 AM
|
0 responses
1 view
0 likes
|
Last Post
![]()
by kujista
Today, 12:59 AM
|
||
Started by Gerik, Today, 12:14 AM
|
0 responses
2 views
0 likes
|
Last Post
![]()
by Gerik
Today, 12:14 AM
|
||
Started by Bionian, Yesterday, 11:47 PM
|
0 responses
2 views
0 likes
|
Last Post
![]()
by Bionian
Yesterday, 11:47 PM
|
||
Started by adambrul, Yesterday, 11:34 PM
|
0 responses
1 view
0 likes
|
Last Post
![]()
by adambrul
Yesterday, 11:34 PM
|
||
Started by benjamind10, Yesterday, 07:27 PM
|
0 responses
4 views
0 likes
|
Last Post
![]()
by benjamind10
Yesterday, 07:27 PM
|
Leave a comment: