Announcement

Collapse
No announcement yet.

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.

    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];
        }

        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.

            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.

                    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);
                        }

                        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.

                            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 Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              602 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              347 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              103 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              559 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              558 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X