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

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 PhillT, Today, 02:16 PM
                  2 responses
                  3 views
                  0 likes
                  Last Post PhillT
                  by PhillT
                   
                  Started by Kaledus, Today, 01:29 PM
                  3 responses
                  9 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by frankthearm, Yesterday, 09:08 AM
                  14 responses
                  47 views
                  0 likes
                  Last Post NinjaTrader_Clayton  
                  Started by gentlebenthebear, Today, 01:30 AM
                  2 responses
                  14 views
                  0 likes
                  Last Post gentlebenthebear  
                  Started by PaulMohn, Today, 12:36 PM
                  2 responses
                  17 views
                  0 likes
                  Last Post PaulMohn  
                  Working...
                  X