Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CountIf Question

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

    CountIf Question

    Hi,
    I'm trying to use CrossAbove() within the CountIf function.
    This is the example from the help files for CountIf:

    // If in the last 10 bars we have had 8 up bars then go long
    if (CountIf(() => Close[0] > Open[0], 10) > 8)
    EnterLong();


    I'm trying to do this:

    if (CountIf(() => CrossAbove(Close, SMA(20), 1), 10) > 2)
    {
    Value[0] = 1;
    Draw.Text(this, "ClusterYes" + CurrentBar, @"inflectionPoint", 0, (Low[0] + (-50 * TickSize)) );
    }


    it compiles, but I don't get any results
    Any reason you can point to?
    thanks,
    David

    #2
    Hello David,

    Thanks for your post.

    Just to make sure we are looking at this the same way, the Countif would be true if it finds greater than two crossaboves in the last 10 bars. The cross above is the close price crossing above the 20 period SMA.

    Is that what you intended?

    Comment


      #3
      Hi Paul,
      Yes, basically I'm looking for a yes/no answer to an excess of a threshold number of sma crosses within the last x bars.

      Comment


        #4
        here's an example of the event I'm looking to verify. you can see the cluster of blue and pink triangles where there was a relatively high frequency of sma crosses over a small number of bars. I'm trying to make a simple 1 or 0 heads-up indicator so that i can track this type of event over a number of instruments in the data analyzer
        Attached Files
        Last edited by trader3000a; 01-26-2022, 12:03 PM.

        Comment


          #5
          Hello David,

          Thanks for your reply.

          Please check your "Log" tab of the Ninjatrader control center and look for any error messages related.

          I copied your code into an indicator and tested it by drawing a vertical line when the Countif condition was true. As you can see in the screenshot it seems to work as intended.

          Click image for larger version

Name:	Trader3000a-2.PNG
Views:	814
Size:	96.8 KB
ID:	1187201

          Comment


            #6
            Hi Paul,

            Thanks. We got it going. It looks like I omited the:

            if (CurrentBar < 20) return;

            I guess I don't really understand that piece yet.
            Much apreciated!

            David

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            608 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            355 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            105 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            560 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            561 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X