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:	521
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 proptrade13, Today, 11:06 AM
            1 response
            5 views
            0 likes
            Last Post NinjaTrader_Clayton  
            Started by quantismo, 04-17-2024, 05:13 PM
            4 responses
            31 views
            0 likes
            Last Post quantismo  
            Started by love2code2trade, 04-17-2024, 01:45 PM
            4 responses
            32 views
            0 likes
            Last Post love2code2trade  
            Started by cls71, Today, 04:45 AM
            2 responses
            10 views
            0 likes
            Last Post eDanny
            by eDanny
             
            Started by kulwinder73, Today, 10:31 AM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_Erick  
            Working...
            X