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 Hwop38, 05-04-2026, 07:02 PM
      0 responses
      174 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Started by CaptainJack, 04-24-2026, 11:07 PM
      0 responses
      329 views
      0 likes
      Last Post CaptainJack  
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      252 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      356 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      182 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Working...
      X