• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bool Series - exclude individual bars from the bool

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

    Bool Series - exclude individual bars from the bool

    Hello,

    I am trying to simplify some code and would be grateful for some assistance.

    Let's say I write a bool series that says none of the last 21 bars can be dojis - call it noDojisB20ToB0[0] = true. Then in sections of the code I may want individual bars within that last 20 to be a doji. Rather than writing the entire code again to exclude all bars from being dojis except say bar[5], can I do something like:

    if(noDojisB20ToB0[0] == true && dojiBar[5] == true)
    {Action}

    This does not appear to work at the moment because the bool series part of the code has already made dojiBar[5]==false, and I am now trying to make it true without having to rewrite all the other 19 dojis which are false. Is there a way of doing this?

    Thank you.

    #2
    Hello GeorgeW,

    Thank you for your note.

    So I can best answer your question, could you please provide more detail or a imagine of a situation which would have no Doji within the last 20 bars but also have a doji 5 bars ago?

    I look forward to your reply.

    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Hello AlanP,

      Thanks for your response.
      The same set of 20 bars would not have no dojis but also have a doji on bar 5. What I am trying to express in the code is that most of the time I may be looking for a situation where there are no dojis in the last 20 bars, so I have coded the bool series for that. In other parts of the code I may want to find one or two dojis at specific points within the last 20 bars - let's say I want to find 2, but none in the other 18 positions. I do not then want to rewrite 18 dojiBar[#] to [#]== false and the 2 I want to find as true. Is it possible to use the bool series noDojisB20ToB0[0] == true and then somehow filter out say dojiBar[5]==true?

      Comment


        #4
        Hello GeorgeW,

        Thank you for the reply.

        The description provided is a little hard for me to understand but I believe you are asking how to avoid duplicating this if statement, is that correct? If so, a loop for that purpose.


        For example:

        Code:
        bool found = false;
        int location = -1;
        for(int i = 0; i < 10; i++)
        {
           if(dojiBar[i] != false)
           {
               found = true;  //assign an out of scope variable true when the loop condition is met
               location = i; //store the index that was found
               break; //stop the loop once the target bool is found
           }
        }
        
        if(found) //do something because the loop has found a result
        Can you confirm if I have understood the question correctly?


        I look forward to being of further assistance.
        Last edited by NinjaTrader_Jesse; 11-26-2018, 08:05 AM.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Thank you Jesse,

          Avoiding duplicating the entire if statement just to exclude one or two of the bars from being false for the dojiBar is exactly what I am trying to do. So if I am looking for the dojiBar[5] != false but the others remain false, where would I place the [5]?
          Thanks for your help.
          Last edited by GeorgeW; 11-24-2018, 12:31 AM.

          Comment


            #6
            Hello GeorgeW,

            Thank you for the post.

            Will the [5] be constant or always [5]? If you want to avoid creating the same syntax over and over, a loop would be best for that purpose but that depends on how you specifically want to use it.

            The previous example I provided loops over a range of values, 10 in that example, and then checks each BarsAgo if it is true or false. If you always want to check 5 bars ago, you could just use [5] for the BarsAgo to be checked as you had provided.

            Another way to approach this question so that we are both at the same understanding would be to output your bool series as prints and then we can identify from the prints how to form the condition.

            For example, using a print like the following:

            Code:
            Print(CurrentBar + " " + dojiBar[0]);
            We are just outputting the current bar to know a place in time and the bool series value at that time. If you can identify from the prints one of these situations and then except those prints, that would help me understand the specifics of this question better.

            Alternatively, are you able to create the condition by repeating the syntax to work how you wanted? If so, can you post that as an example? Working from something that already does what you want would be the best case as we could just explore alternate ways to do that.

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Thanks for your response, Jesse. Will see what I can do with it when I get some time.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by ralett, Today, 11:44 AM
              1 response
              13 views
              0 likes
              Last Post NinjaTrader_Spencer  
              Started by DMDINAZ, Today, 11:03 AM
              1 response
              8 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by sukhob, Today, 10:14 AM
              4 responses
              10 views
              0 likes
              Last Post sukhob
              by sukhob
               
              Started by beaacontreras, Today, 09:27 AM
              1 response
              21 views
              0 likes
              Last Post NinjaTrader_PatrickG  
              Started by fxSol, 03-17-2019, 04:17 AM
              5 responses
              28 views
              0 likes
              Last Post NinjaTrader_ChristopherS  
              Working...
              X