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!
See more
See less

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?
    Paul H.NinjaTrader Customer Service

    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:	519
Size:	96.8 KB
ID:	1187201
          Paul H.NinjaTrader Customer Service

          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 warreng86, 11-10-2020, 02:04 PM
            7 responses
            1,360 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by Perr0Grande, Today, 08:16 PM
            0 responses
            5 views
            0 likes
            Last Post Perr0Grande  
            Started by elderan, Today, 08:03 PM
            0 responses
            9 views
            0 likes
            Last Post elderan
            by elderan
             
            Started by algospoke, Today, 06:40 PM
            0 responses
            10 views
            0 likes
            Last Post algospoke  
            Started by maybeimnotrader, Today, 05:46 PM
            0 responses
            14 views
            0 likes
            Last Post maybeimnotrader  
            Working...
            X