• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Need help with some C# Counting Code

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • NinjaTrader_PaulH
    replied
    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;
    }


    Leave a comment:


  • IanC28
    replied
    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:


  • Dwight292
    started a topic Need help with some C# Counting Code

    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.


    MyBKExperience
    Last edited by Dwight292; 01-11-2019, 10:52 PM.

Latest Posts

Collapse

Topics Statistics Last Post
Started by kujista, Today, 12:59 AM
0 responses
1 view
0 likes
Last Post kujista
by kujista
 
Started by Gerik, Today, 12:14 AM
0 responses
2 views
0 likes
Last Post Gerik
by Gerik
 
Started by Bionian, Yesterday, 11:47 PM
0 responses
2 views
0 likes
Last Post Bionian
by Bionian
 
Started by adambrul, Yesterday, 11:34 PM
0 responses
1 view
0 likes
Last Post adambrul  
Started by benjamind10, Yesterday, 07:27 PM
0 responses
4 views
0 likes
Last Post benjamind10  
Working...
X