Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Why does != PeriodType.Tick Give me unexpected results?

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

    Why does != PeriodType.Tick Give me unexpected results?

    I want to show an error message on screen and return if the user applies my indicator to the wrong chart type or size.

    The documentation gives this code as an example of BarsPeriod.ID

    Code:
    if (BarsPeriod.Id == PeriodType.Tick && BarsPeriod.Value >=  100)
        {
            //  Indicator calculation logic here
         }
    I tried:

    Code:
    if (BarsPeriod.Id != PeriodType.Tick && BarsPeriod.Value !=  100)
        {
            //  Error message code goes here
         }
    I don't get what I expect... if I remove

    Code:
    BarsPeriod.Id != PeriodType.Tick
    I get the eror message as expected when the chart period is not the one specified, but

    ... if I leave both conditions in place, the indicator applies itself to the chart, and doesn't display the error message regardless of chart type or period.

    Why?
    Last edited by Crassius; 04-09-2012, 03:08 PM.

    #2
    Crassius,

    if (BarsPeriod.Id == PeriodType.Tick && BarsPeriod.Value != 100)

    This condition checks if the chart is of type "tick" AND the barsperiod value is not equal to 100. Are you trying to negate this statement?

    To negate an and statement, you need to use the following De'Morgan's law.

    NOT ( Condition1 AND Condition2 ) is the same as ( NOT Condition1 OR NOT Condition2 )

    So you would want to use :

    (BarsPeriod.Id != PeriodType.Tick || BarsPeriod.Value != 100)

    or you can use :

    if ( ! (BarsPeriod.Id == PeriodType.Tick && BarsPeriod.Value == 100) )

    What sort of charts are you trying to prevent?
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Thanks... I learned something new. Got it.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      579 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      334 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      554 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      551 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X