Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CountIF Function not Working

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

    CountIF Function not Working

    Hello,

    I hope my message finds you well. I need some help on the CountIF function, which I don't understand why it is not working.

    Here is the code,

    _BreakBelowLondonSessionLow = CrossBelow(Closes[2], LONDONInitialBalanceLow, 1) || CrossBelow(Lows[2], LONDONInitialBalanceLow, 1);
    _BreakBelowLondonSessionLow &= j2BarCounter1[0] > 180;

    if(_BreakBelowLondonSessionLow)
    {
    BackBrush = Brushes.Pink;
    BarCounterCrossBelowLondonLow = CurrentBars[2];

    }

    _StartingofSession = j2BarCounter1[0] == 180;

    if(_StartingofSession)
    {
    CounterStartSession = CurrentBars[2];

    }


    CountingofCrosses = CountIf(() => _BreakBelowLondonSessionLow, (CurrentBars[2] - CounterStartSession));

    Print(Times[2][0] + " Number of Crosses: " + CountingofCrosses);
    When I ask to print the values, it always give me a value of 0,which is wrong.

    Can you help?
    Thank you​

    #2
    Hello NorwegianCat92,

    You are supplying a value of false and are not supplying a condition comparing series.

    _BreakBelowLondonSessionLow will be true or false when it gets to the method and will not change.

    The condition would need to be supplied.

    CountIf(Func<bool> condition, int period)
    Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.


    CountIf(() => CrossBelow(Closes[2], LONDONInitialBalanceLow, 1) || CrossBelow(Lows[2], LONDONInitialBalanceLow, 1), (CurrentBars[2] - CounterStartSession))
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea,

      Ah Ok, understood! Thank you very much for your help.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Today, 05:17 AM
      0 responses
      50 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      126 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      69 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      42 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      46 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X