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

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:
        [FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] ((BTBar > [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]))
        {
        DrawLine([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"BT"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] + CurrentBar.ToString(), BTBar, doubleY, [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], doubleY, Color.Green, DashStyle.Dash, [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]2[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]);
        }
        [/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][/SIZE][/FONT]
        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:
          [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]private [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] BuyTDST()[/SIZE][/FONT]
          [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
          [SIZE=2][FONT=Courier New]BTBar = HighestBar(High,[/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]9[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
          [SIZE=2][FONT=Courier New]doubleY = High[BTBar];[/FONT][/SIZE]
          [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (Close[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]9[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]] > High[BTBar])[/SIZE][/FONT]
          [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
          [SIZE=2][FONT=Courier New]doubleY = Close[[/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]9[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]];[/SIZE][/FONT]
          [SIZE=2][FONT=Courier New]BTBar = [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]9[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
          [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
          [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
          [/SIZE][/FONT]

          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:
                      [FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]DrawLine([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"BT"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], BTBar, doubleY, [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], doubleY, Color.Green, DashStyle.Dash, [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]2[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]);
                      [/SIZE][/FONT][/SIZE][/FONT]
                      The green line is drawn from somewhere but definitely not BTBar. (chart a)

                      if i replace the code with this:-

                      Code:
                      [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (tdstBar > [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])
                      DrawLine([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"BT"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], CurrentBar-tdstBar, doubleY, [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], doubleY, Color.Green, DashStyle.Dash, [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]2[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]);
                      [/SIZE][/FONT][/SIZE][/FONT]
                      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 DJ888, 04-16-2024, 06:09 PM
                              4 responses
                              12 views
                              0 likes
                              Last Post DJ888
                              by DJ888
                               
                              Started by terofs, Today, 04:18 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post terofs
                              by terofs
                               
                              Started by nandhumca, Today, 03:41 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post nandhumca  
                              Started by The_Sec, Today, 03:37 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post The_Sec
                              by The_Sec
                               
                              Started by GwFutures1988, Today, 02:48 PM
                              1 response
                              9 views
                              0 likes
                              Last Post NinjaTrader_Clayton  
                              Working...
                              X