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

Check "BoolSeries mybool" for true/false

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

    Check "BoolSeries mybool" for true/false

    Hello. How to check "BoolSeries mybool" for true/false. When I wrote "if(mybool==true) do something", NT report bag, that I can't use "==" for BoolSeries.

    #2
    Hello. How to check "BoolSeries mybool" for true/false. When I wrote "if(mybool==true) do something", NT report bag, that I can't use "==" for BoolSeries.
    If you do indeed have a series of bool values, then I think you need to declare in Variables:

    myBoolSeries = new BoolSeries(this);

    See Help:

    http://www.ninjatrader.com/support/h...ries_class.htm


    If, on the other hand, you have a simple boolean, declaring in Variables:

    private bool mybool = true;

    In OnBarUpdate(), this works with, e.g.

    if (mybool == false
    &&...)

    Hope this helps.

    Comment


      #3
      Code:
      #region Variables
      ....
      private BoolSeries myBool;
      ....
      protected override void Initialize()
      {.....
      myBool = new BoolSeries(this);
      .....
      protected override void OnBarUpdate()
      {....
      myBool.Set(true);
      ......
      if(myBool==true) do smth
      NT said I can't use "==" for BoolSeries.

      Comment


        #4
        Sorry, Alex
        Code:
        myBoolSeries = new BoolSeries(this)
        is what should go in Initialize. I trust you did this.

        You were right about your declaration in Variables.

        It's getting late in my part of the world so I fear to make another mistake...

        Comment


          #5
          Originally posted by alexstox View Post
          Code:
          #region Variables
          ....
          private BoolSeries myBool;
          ....
          protected override void Initialize()
          {.....
          myBool = new BoolSeries(this);
          .....
          protected override void OnBarUpdate()
          {....
          myBool.Set(true);
          ......
          if(myBool==true) do smth
          NT said I can't use "==" for BoolSeries.
          A BoolSeries is a series. You cannot compare a series to a variable. You want to compare a value in the series to a variable. That means that you must specify the index for the comparison. e.g.,
          Code:
          if (myBool[0] == true) ...
          Even more elegant:
          Code:
          if (myBool[0]) ...
          Last edited by koganam; 02-09-2014, 04:19 PM.

          Comment


            #6
            Originally posted by koganam View Post
            A BoolSeries is a series. You cannot compare a series to a variable. You want to compare a value in the series to a variable. That means that you must specify the index for the comparison. e.g.,
            Code:
            if (myBool[0] == true) ...
            Even more elegant:
            Code:
            if (myBool[0]) ...
            But there is only one BoolSeries in script - myBool. Even so I should use myBool[0]?

            Comment


              #7
              Originally posted by alexstox View Post
              But there is only one BoolSeries in script - myBool. Even so I should use myBool[0]?
              I am not sure what that has to do with it. My original response explained it. A series is exactly that: a series of values. You need to specify which of the values you want to reference. It has nothing to do with how many series are defined.

              Comment


                #8
                Hello Alexstox,

                Thank you for your post and to koganam and arbuthnot for their assistance.

                The BoolSeries is a series of booleans, the index is referencing the latest value when you call [0]. Tying it the bar series with myBoolSeries = new BoolSeries(this); allows us to call the value of previous bars as well via the index. So [1] would be the previous value before the most recent, and [2] would be the value before that.

                Comment


                  #9
                  OK. So, if I need last value, I should use [0]

                  Comment


                    #10
                    Hello Alexstox,

                    That is correct.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by bortz, 11-06-2023, 08:04 AM
                    47 responses
                    1,603 views
                    0 likes
                    Last Post aligator  
                    Started by jaybedreamin, Today, 05:56 PM
                    0 responses
                    8 views
                    0 likes
                    Last Post jaybedreamin  
                    Started by DJ888, 04-16-2024, 06:09 PM
                    6 responses
                    18 views
                    0 likes
                    Last Post DJ888
                    by DJ888
                     
                    Started by Jon17, Today, 04:33 PM
                    0 responses
                    4 views
                    0 likes
                    Last Post Jon17
                    by Jon17
                     
                    Started by Javierw.ok, Today, 04:12 PM
                    0 responses
                    12 views
                    0 likes
                    Last Post Javierw.ok  
                    Working...
                    X