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

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 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
              1 view
              0 likes
              Last Post Jon17
              by Jon17
               
              Started by Javierw.ok, Today, 04:12 PM
              0 responses
              6 views
              0 likes
              Last Post Javierw.ok  
              Started by timmbbo, Today, 08:59 AM
              2 responses
              10 views
              0 likes
              Last Post bltdavid  
              Started by alifarahani, Today, 09:40 AM
              6 responses
              41 views
              0 likes
              Last Post alifarahani  
              Working...
              X