Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Lookback period

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

    Lookback period

    Hello,Support!

    How do i set conditions for the lookback period for say 10 bars?So 10 bars back - if any bar out of 10 is true during the period.

    Thank you!

    #2
    Hello outsource, and thank you for your question.

    For this sort of thing, it is best to use a loop. I will give an example,

    Code:
    [FONT=Courier New]for (int i = 0; i < 10; i++)
    {
        if (Close[i] > 50)
        {
            Print("Close broke 50");
        }
    }[/FONT]
    If you would like to loop over all your bars, use "CurrentBar" instead of "10".

    If you would like code to process once, you will need a boolean, like this,

    Code:
    [FONT=Courier New]bool broke50 = false;
    for (int i = 0; i < 10; i++)
    {
        if (Close[i] > 50)
        {
            broke50 = true;
        }
    }
    if (broke50)
    {
        Print("Close broke 50");
    }[/FONT]
    Please let us know if there is anything else we can help with.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_JessicaP View Post
      Hello outsource, and thank you for your question.

      For this sort of thing, it is best to use a loop. I will give an example,

      Code:
      for (int i = 0; i < 10; i++)
      {
          if (Close[i] > 50)
          {
              Print("Close broke 50");
          }
      }
      If you would like to loop over all your bars, use "CurrentBar" instead of "10". Please let us know if there is anything else we can help with.
      Hi,Jessica,

      thank you for your reply.I need this logic for a strategy.I`m not sure where i put the code you provided,in a strategy.

      Comment


        #4
        It is the kind of thing that goes inside OnBarUpdate. It will probably need to be modified depending on what your condition is to work though.

        If you would like some more detailed help, please send a code sample to platformsupport[at]ninjatrader[dot]com , replace [at] and [dot] where appropriate, and we will be able to help more.

        When you reply, please reference this unique number :

        1506907
        Jessica P.NinjaTrader Customer Service

        Comment


          #5
          So what i actually need is this:

          Two bars - bar.a bar.b

          ten bars back, it could be 10 bar.a or 10 bar.b, or an assortment of bar.a bar.b,so the first 3 bars - bar.a,next two bars - bar.b.10 bars back - either or bar.a/bar.b or mix of them.

          I hope it`s clear

          thank you!

          Comment


            #6
            I try something like this:

            this.xp.Voodoo[1] == 1 || this.xp.Voodoo[2] == 1 || this.xp.Voodoo[Math.Min(CurrentBar, 3)]
            == 1

            with || statement,but in this way it recognises only 1 bar out of bar in the period.What i need is it to be able to recognise all 10,for e.g.

            I didn`t put it correctly in the intro,sorry.Not any,but i need all of the 10 bars to fall into one category.

            I can put all combination via && and || statements i guess,but i think it would be a real mess

            Comment


              #7
              The loop for checking every member looks very similar to the loop for checking any member. Using your code,

              Code:
              [FONT=Courier New]bool pass = true;
              for (int i = 0; i < 10; i++)
              {
                  if ( this.xp.Voodoo[i] != 1 )
                  {
                      pass = false;
                  }
              }[/FONT]
              In this example, the variable I called "pass" will only be true if every value for the most recent 10 bars is equal to 1.
              Jessica P.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_JessicaP View Post
                The loop for checking every member looks very similar to the loop for checking any member. Using your code,

                Code:
                [FONT=Courier New]bool pass = true;
                for (int i = 0; i < 10; i++)
                {
                    if ( this.xp.Voodoo[i] != 1 )
                    {
                        pass = false;
                    }
                }[/FONT]
                In this example, the variable I called "pass" will only be true if every value for the most recent 10 bars is equal to 1.
                Can i apply the || statement here?

                bool pass = true;
                for (int i = 0; i < 10; i++)
                {
                if ( this.xp.Voodoo[i] != 1 || this.xpb.Voodoo[i] != 1)
                {
                pass = false;
                }
                }

                So the two values within 10 bars are being scanned

                Comment


                  #9
                  You certainly can. This would be the equivalent to saying "if either xp.Voodoo or xpb.Voodoo have any value other than 1 in their last 10 bars, count this as a failure"
                  Jessica P.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  648 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  369 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  108 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  572 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  573 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X