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

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 maybeimnotrader, Yesterday, 05:46 PM
      5 responses
      24 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by NRITV, Today, 01:15 PM
      0 responses
      4 views
      0 likes
      Last Post NRITV
      by NRITV
       
      Started by quantismo, Yesterday, 05:13 PM
      2 responses
      16 views
      0 likes
      Last Post quantismo  
      Started by frankthearm, Today, 09:08 AM
      6 responses
      27 views
      0 likes
      Last Post frankthearm  
      Started by adeelshahzad, Today, 03:54 AM
      5 responses
      33 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Working...
      X