Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

countif error

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

    countif error

    hello
    i have a multi timeframe strategy and get error when i use countif

    07/05/2009 4:59:34 PM Strategy Error on calling 'OnBarUpdate' method for strategy 'forexZLR': 'CountIf' can't be run on multi series strategies.



    Code:
    [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]private[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]bool[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] IsADXTrending()
    {
    [/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// check if adx is trending
    [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]bool[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] _ADXTrending = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
    [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (CountIf([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]delegate[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] { [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ADX(14)[1] < ADX(14)[2]; }, 3) >= 3)
    {
    _ADXTrending = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
    }
    [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]else
    [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]{
    _ADXTrending = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
    }
    [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] _ADXTrending;
    }
    [/SIZE]
    what r my options

    #2
    You while need to create your own loop that checks the bars you want and then just increment a counter each time your conditions are met.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Josh,

      I might be having a similar problem.

      This works:

      if (dsSpread[0] > dsSpread[1]
      && dsSpread[1] > dsSpread[2]
      && dsSpread[2] > dsSpread[3]
      && dsSpread[3] > dsSpread[4]
      && dsSpread[4] > dsSpread[5]
      && dsSpread[5] > dsSpread[6])
      {
      EnterShort();
      }

      //But this doesn't? Why? I don't get a compile error, just dead air.

      if (CountIf(delegate {return dsSpread[0] > dsSpread[1];}, 6) >= 6)
      {
      EnterShort();
      }

      END:
      dsSpread is a DataSeries that stores the value of the difference between two futures contracts. So my value is derived from two different instruments.

      I really enjoyed the elegance of CountIf verses a counter. Is this CountIf limited solely to the primary instrument?


      Thanks,

      Comment


        #4
        Unfortunately CountIf() will not work in a multi-series strategy.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Josh View Post
          Unfortunately CountIf() will not work in a multi-series strategy.
          Josh,

          It might not hurt to make a note of that in the documentation.

          Also, the CountIf works, but not with my DataSeries. It will work with the Close[] DataSeries. Also, my DataSeries is just a stored result from calculating the difference between the two instruments. Are you saying that the CountIf "knows" my value is derived from the difference between the two instruments and as such will not work?

          Again, in the same strategy, CountIf works if I plug a dataSeries like Close[].


          Thanks,

          Comment


            #6
            r2kTrader,

            Thanks for the suggestion. It should already be in the documentation in red. CountIf will not work in multi-instrument or multi-time frame strategies.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Josh View Post
              r2kTrader,

              Thanks for the suggestion. It should already be in the documentation in red. CountIf will not work in multi-instrument or multi-time frame strategies.
              You mean right at the beginning where someone who was reading would see it before even considering the use of the function?

              I don't know, I just looked at the help for CountIf and it really isn't very clear , I mean putting the NOT part in bold red was distracting. Nobody ever pays attention to bold red. Try to pick up the slack eh Josh. I mean really, bold red? Try to come up with something that might get people's attention, lol.


              Definition
              Counts the number of occurrences of the test condition over the look back period expressed in bars. This method will NOT work on multi-instrument or multi-time frame strategies.

              Comment


                #8
                Josh,

                On a serious note, how come it works in multi when I plug a dataseries like Close[]?

                Ah, I think I remember. It will "work" but not consecutively as it needs a DataSeries to function properly, otherwise it is just a test of false/true but does not store and count.

                Comment


                  #9
                  Right. I would not know the behavior of it in a multi-series strategy. Please use counters if you wanted to increment something instead.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by r2kTrader View Post
                    You mean right at the beginning where someone who was reading would see it before even considering the use of the function?

                    I don't know, I just looked at the help for CountIf and it really isn't very clear , I mean putting the NOT part in bold red was distracting. Nobody ever pays attention to bold red. Try to pick up the slack eh Josh. I mean really, bold red? Try to come up with something that might get people's attention, lol.


                    Definition
                    Counts the number of occurrences of the test condition over the look back period expressed in bars. This method will NOT work on multi-instrument or multi-time frame strategies.
                    Just my 2 cents:
                    For me the documentation is clear, but makes the function much less useful. I suggest to implement it without such limitation.

                    Comment


                      #11
                      xTrader1,

                      Thanks for sharing your thoughts. It is on our list of future considerations.
                      Josh P.NinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      649 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      370 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by Mindset, 02-09-2026, 11:44 AM
                      0 responses
                      109 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                      0 responses
                      573 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      576 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X