Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CurrentBar and DrawLine

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

    CurrentBar and DrawLine

    Hi,
    I've seen some script using CurrentBar in the DrawLine() function for int StartBarsAgo and int endBarsAgo. Usually it was used to subtract a variable.

    Would you mind explaining how CurrentBar would work in those situations?

    Kay Wai

    #2
    Hi kaywai,

    Thank you for your post.

    The CurrentBar represents the bar number (from left to right) of the most recent bar, so if 100 bars have been painted on a chart, the CurrentBar = 100.
    More info at - http://www.ninjatrader-support.com/H...tml?CurrentBar

    If the CurrentBar is used, for example, in starBarsAgo for DrawLine(), the line would always start at the beginning of the chart. When there are 98 bars, the line will start 98 bars ago, when there are 99 bars, it will start 99 bars ago etc.

    If we have, for example, CurrentBar - 10, the line will start 10 bars after the start of the chart.
    TimNinjaTrader Customer Service

    Comment


      #3
      Thanks Tim! That is a good place for me to begin.

      Comment


        #4
        Guys, Can you please take a look at the green lines?

        This is the code i have which is placed in OnBarUpdate():-

        Code:
        if ((BTBar > 0))
        {
        DrawLine("BT" + CurrentBar.ToString(), BTBar, doubleY, 0, doubleY, Color.Green, DashStyle.Dash, 2);
        }
        
        Don't see any "dashes" there...just a thin line at the start which thickens as it extends and thins out at the end...

        Please assist. Thx!
        Attached Files
        Last edited by kaywai; 03-10-2010, 09:56 AM.

        Comment


          #5
          This is the rest of the code...

          Code:
          private void BuyTDST()
          {
          BTBar = HighestBar(High,9);
          doubleY = High[BTBar];
          if (Close[9] > High[BTBar])
          {
          doubleY = Close[9];
          BTBar = 9;
          }
          }
          

          Comment


            #6
            Hi kaywai,


            It appears as though you are plotting the line repeatedly (+CurrentBar creates a new tag, and line with each new bar), making it hard to see the dash style.
            Last edited by NinjaTrader_Tim; 03-10-2010, 01:02 PM.
            TimNinjaTrader Customer Service

            Comment


              #7
              Tim, I removed (BTBar > 0)...No change to my chart...green line still like it was...

              just to share with you, i had initially placed the DrawLine instruction in the private void BuyTDST(), but I couldn't get the line to extend to like it is now. By some stroke of luck i just took that line out and placed it in OnBarUpdate()...i got the length almost right but the green line didn't look too good...
              Last edited by kaywai; 03-10-2010, 12:16 PM.

              Comment


                #8
                Hi kaywai,

                Did you delete and re-apply the indicator (not just reload)?

                Please post a screenshot of the chart.
                TimNinjaTrader Customer Service

                Comment


                  #9
                  Hi Tim, I had just exited NT when I saw your message. I just went in again and this is what I got for the green lines...
                  Attached Files

                  Comment


                    #10
                    Hi kaywai,

                    Please see my comment in post #6 in parenthesis.

                    (+CurrentBar creates a new tag, and line with each new bar)
                    Last edited by NinjaTrader_Tim; 03-10-2010, 01:02 PM.
                    TimNinjaTrader Customer Service

                    Comment


                      #11
                      Hi Tim,

                      If I remove "+CurrentBar.ToString()", I won't get to see past occurences of the green line, right? I only get the most recent. the code is like this:-

                      Code:
                      DrawLine("BT", BTBar, doubleY, 0, doubleY, Color.Green, DashStyle.Dash, 2);
                      
                      The green line is drawn from somewhere but definitely not BTBar. (chart a)

                      if i replace the code with this:-

                      Code:
                      if (tdstBar > 0)
                      DrawLine("BT", CurrentBar-tdstBar, doubleY, 0, doubleY, Color.Green, DashStyle.Dash, 2);
                      
                      where tdstBar = CurrentBar at the time of calculation of BTBar, it is more presentable but I still only get the most recent green line. (chart b)

                      ideally, i would like to see the charts like in chart c but with the lines drawn properly (the original coding)...would you mind helping?
                      Attached Files

                      Comment


                        #12
                        Hi kaywai,

                        A few options...

                        1. You can add something to the tag to create new iteration of the line, but you will need to find a way to add something only once for each new line.

                        So each time there is a new line, add something to the tag.

                        You may want to print the values to find where they are changing anchor points.
                        More info at - http://www.ninjatrader-support.com/H...ide.html?Print

                        2. You can remove lines programatically, with RemoveDrawObject().
                        More info at - http://www.ninjatrader-support.com/H...moveDrawObject
                        TimNinjaTrader Customer Service

                        Comment


                          #13
                          Tim, I wish I knew how to use tags and automate tagging. Is there any literature on how to use tagging?

                          I know where and why the values are changing anchor points in most cases but for chart A where I removed "CurrentBar.ToString()" from the tag, the green line seemed arbitrary. Chart B and Chart C anchor point shifts are all ok.

                          My issue is I want to draw a simple line for variable BTBar to where it ends as per chart C. Where it ends on Chart C is the same as Chart B...

                          Comment


                            #14
                            Hi kaywai,

                            You can add tagging in the same way in your first post...

                            "BT" + CurrentBar.ToString()

                            You will need to do this less often, however. Ask yourself, "what does each time the lines changes have in common?"

                            Right now you are creating a new line every time the CurrentBar changes.
                            TimNinjaTrader Customer Service

                            Comment


                              #15
                              Tim, ideally I would the line like to "extend" as each bar is created and to stop when certain conditions are fulfilled.

                              I suppose to have the line from extending after certain conditions are fulfilled, i would 1) have to remove the old line and redraw it...but i think i need to get the first part solved first...

                              Hence, if i have a unique tag created for each green line drawn (how do i do that?) i could remove the old line by calling that particular tag and removing it and then redraw the line with the fixed parameters...

                              the problem is i don't know how to achieve it!!!

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by twitch251, Today, 05:14 PM
                              1 response
                              4 views
                              0 likes
                              Last Post NinjaTrader_ShawnB  
                              Started by robforee2, Today, 05:07 PM
                              0 responses
                              1 view
                              0 likes
                              Last Post robforee2  
                              Started by blar58, Today, 03:16 PM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_Melissa  
                              Started by alcorr247, Today, 02:52 PM
                              2 responses
                              7 views
                              0 likes
                              Last Post robforee2  
                              Started by Radano, Today, 02:30 PM
                              1 response
                              4 views
                              0 likes
                              Last Post NinjaTrader_ChrisL  
                              Working...
                              X