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

all bars to now from X bars ago

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

    all bars to now from X bars ago

    Hey guys,

    Is there any way to select every bar from X bars ago to now, so say I want to compare something like so:

    Compare[0] > BarsAgo[x] // Including every bar in between

    Or do I have to do it manually, so:

    if(compare[0] > compare[1] && compare[0] > compare[2] && compare[0] > compare[3] etc etc?)

    Because that seems really labour intensive? Surely there's a way to select Bar[10] + every bar in between?

    Cheers

    #2
    Jumper, you could look into using a loop command here to have the index iterate through 0 to 10 for example for your expression.

    BertrandNinjaTrader Customer Service

    Comment


      #3
      What kind of loop would be best for that though?

      Comment


        #4
        A for one for example, just press F2 to get a snippet offered.

        for (int index = 0; index < 10; index++)
        {
        closeSum += Close[index];
        }
        BertrandNinjaTrader Customer Service

        Comment


          #5
          So I want to do it with volume, so it would be something like:

          for (int vol = 0; vol <= 10; vol++)
          {
          if (Volume[0] > Volume[vol])
          BarColor = Color.Magenta;
          }

          Doesn't seem to be working though, still don't understand how to compare the current bar with all previous X bars.

          EDIT: Not a SUM of all previous X bars by the way, each individual volume of each bar. Just thought I'd make that clear

          Comment


            #6
            Yes, the sum was just an example for the looping technique. Since you want to compare each bar with the previous > your index used would need to reflect this (vol and vol-1). You then can run for example a count in that loop for how often your condition was hit and if it's not hit reset that to 0 to reflect this would need to happen on consecutive bars.

            Outside the loop you could then run a condition checking for the counter state and taking action based on it's value.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Thanks for the reply Bertrand, but I'm afraid your post has confused me a little, don't quite understand what you mean?

              On another project, how can I draw a line to the right of the chart(infinite) on the high and low of a bar?

              So say I want to do:

              if (condition)
              {
              DrawLine(High[0], Infinite)
              }

              That type of thing? Because I need to set a start and end point don't I for DrawLine? What do I put for these values if I want it to be from the high and low of the bar that meets the condition to infinite(always there)?

              Thanks!

              Comment


                #8
                Originally posted by Jumper View Post
                Thanks for the reply Bertrand, but I'm afraid your post has confused me a little, don't quite understand what you mean?

                On another project, how can I draw a line to the right of the chart(infinite) on the high and low of a bar?

                So say I want to do:

                if (condition)
                {
                DrawLine(High[0], Infinite)
                }

                That type of thing? Because I need to set a start and end point don't I for DrawLine? What do I put for these values if I want it to be from the high and low of the bar that meets the condition to infinite(always there)?

                Thanks!
                A line which continues to the hard right edge of the chart is called a Ray. Use DrawRay().

                Comment


                  #9
                  And what to put in for all the arguments of DrawRay()? Anchor1Y AnchorTime etc.

                  Comment


                    #10
                    Originally posted by Jumper View Post
                    And what to put in for all the arguments of DrawRay()? Anchor1Y AnchorTime etc.
                    Here's an example call from the helpguide you could use to get started -

                    if (CurrentBar < 10) return;

                    DrawRay("tag1", 10, Close[0], 0, Close[0], Color.LimeGreen);

                    That would be just a horizontal ray starting 10 bars ago.
                    BertrandNinjaTrader Customer Service

                    Comment


                      #11
                      if (Volume[0] > 5000)
                      {
                      DrawRay(CurrentBar + "high1", High[0], Close[0], 0, Close[0], Color.LimeGreen);
                      DrawRay(CurrentBar + "low1", Low[0], Close[0], 0, Close[0], Color.Red);
                      }

                      Getting a bunch of errors, cannot convert double to int, best overloaded method match etc etc.

                      Comment


                        #12
                        Right, would expect - there's no overload suitable for what you passed in, would suggest closely working with intellisense to know what parameters are expected in the call. For example this should compile for you in contrast :

                        if (Volume[0] > 5000)
                        {
                        DrawRay(CurrentBar + "high1", 1, High[0], 2, Close[0], Color.LimeGreen);
                        DrawRay(CurrentBar + "low1", 1, Low[0], 2, Close[0], Color.Red);
                        }
                        BertrandNinjaTrader Customer Service

                        Comment


                          #13
                          That compiles but it draws lines at huge ridiculous angles? I just want flat horizontal lines from the high/low prices of that bar. The lines from that code are nearly vertical.

                          Comment


                            #14
                            That depends on the price values you pass in to draw at, it will run through them and thus create the angles...

                            Those would be horizontal for example -

                            if (Volume[0] > 5000)
                            {
                            DrawRay(CurrentBar + "high1", 1, Close[0], 0, Close[0], Color.LimeGreen);
                            DrawRay(CurrentBar + "low1", 1, Close[0], 0, Close[0], Color.Red);
                            }

                            ...as in both cases the same Y price value is used.
                            BertrandNinjaTrader Customer Service

                            Comment


                              #15
                              So will that draw from the high/lows? or the open/close of the bar?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by ghoul, Today, 06:02 PM
                              3 responses
                              14 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by jeronymite, 04-12-2024, 04:26 PM
                              3 responses
                              44 views
                              0 likes
                              Last Post jeronymite  
                              Started by Barry Milan, Yesterday, 10:35 PM
                              7 responses
                              20 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by AttiM, 02-14-2024, 05:20 PM
                              10 responses
                              180 views
                              0 likes
                              Last Post jeronymite  
                              Started by DanielSanMartin, Yesterday, 02:37 PM
                              2 responses
                              13 views
                              0 likes
                              Last Post DanielSanMartin  
                              Working...
                              X