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

How do you find the bar number of the last named trade?

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

    How do you find the bar number of the last named trade?

    I am a fairly new Ninjatrader script developer, but this should be pretty simple. Is there an easier way?

    This doesn't seem to work:

    CurrentBar - BarsSinceEntry("BP5EntryLong")

    note: BP5EntryLong is the signal name given to a previous entry trade.

    shouldn't that work?

    Once given the Bar number shouldn't I be able to reference it with the Open/High/Low/Close functions like:

    Low[CurrentBar - BarsSinceEntry("BP5EntryLong")]

    Which also doesn't seem to work.

    Thanks,
    Glen

    #2
    Hello,

    Thank you for the question.

    The BarsSinceEntry method will return a bars ago value so this would already be the amount of bars ago. The reason the code you are trying is not working is that you are essentially double subtracting from the current bar.

    You should be able to use only BarsSinceEntry to get an amount of bars between the current bar and the entry bar.

    Please try Low[BarsSinceEntry("BP5EntryLong")] instead.

    Also you can use Print() to check the values of items like your equation to ensure you are getting the values you expect.

    For this you could try doing the following to check this:

    Click Tools -> Output Window.

    in the script in OnBarUpdate place the following line:

    Print(CurrentBar - BarsSinceEntry("BP5EntryLong"));

    This would output to the output window and show you the value of the equation. In this case you would still only want to use BarsSinceEntry I just wanted to demonstrate how to Print objects out.


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks, seems to work fine. ;-)

      Comment


        #4
        Bars.BarsSinceSession from looking at chart

        How do I tell what bar number (Bars.BarsSinceSession) I am looking at on my chart? I would like to do something like this for debugging purposes:
        if( Bars.BarsSinceSession > 100 & Bars.BarsSinceSession < 110 )
        {
        Print(some data);
        }

        Comment


          #5
          Oops. I meant to start a new thread with this. Not sure how to change it.

          Looks like the ruler measures in bars.

          Comment


            #6
            Hello,

            Thank you for the question.

            If you are just looking to Print out the bar you would want to use CurrentBar

            If you wanted to visualize this on the chart instead of printing you could use a drawing object.

            For example you could do something like the following for a easy way to visualize it:

            Code:
            if (Bars.BarsSinceSession > 100 & Bars.BarsSinceSession < 110)
            {
            	DrawDot("tagName" + CurrentBar, true, 0, Close[0], Color.Red);
            }
            Please let me know if I may be of additional assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Originally posted by bernie_c View Post
              Oops. I meant to start a new thread with this. Not sure how to change it.

              Looks like the ruler measures in bars.
              Hi Bernie

              Further to Jesse's great advice, may I suggest that you may like to see the actual CurrentBar values over the bars on the chart, as I often do myself:

              if (Bars.BarsSinceSession > 100 & Bars.BarsSinceSession < 110)

              DrawText("CurrentBar Text" + CurrentBar, CurrentBar.ToString(), 0, High[0] + 5 * TickSize, Color.Black);


              Obviously, you can adjust the 5 in '5 * TickSize' or set this as an int variable.
              Last edited by arbuthnot; 02-28-2015, 04:10 AM.

              Comment


                #8
                Thanks Jesse and arbuthnot. Not exactly what I was after, but I will certainly use both of these techniques in my adventures with NS.

                What I was after was an existing tool in an active chart indicator, mine or other, where you could click on any bar to find out its bar number. The best I could find was the ruler in the drawing tools pull-down menu.

                Comment


                  #9
                  Originally posted by bernie_c View Post
                  Thanks Jesse and arbuthnot. Not exactly what I was after, but I will certainly use both of these techniques in my adventures with NS.

                  What I was after was an existing tool in an active chart indicator, mine or other, where you could click on any bar to find out its bar number. The best I could find was the ruler in the drawing tools pull-down menu.
                  Bernie - that's going to be difficult: certainly for me! If it's possible, it's seriously advanced.

                  The code I gave you will print the bar number above every bar so you'd instantly be able to get this information...

                  Would you like me to set this up as in indicator you can download? It's not exactly what you were looking for at the outset but it's effectively doing the job.

                  Hear from you.

                  Cheers,

                  Ed

                  Comment


                    #10
                    No thanks arbuthnot, I already did it. Your snippet worked great. I will use the ruler tool when I can though, as it nonintrusive.

                    Comment


                      #11
                      Glad it works.

                      By the way, you can change the appearance of the text, esp. to make it clearer on a white background, by doing something like:

                      DrawText("My text" + CurrentBar, true, CurrentBar.ToString(), 0, High[0] + 5 * TickSize, 0, Color.Black, new Font ("Arial", 10, FontStyle.Bold), StringAlignment.Center, Color.Black, Color.White, 10);

                      You'll find out more if you look up 'DrawText' in Help.

                      Cheers,

                      Ed

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by PaulMohn, Today, 03:49 AM
                      0 responses
                      6 views
                      0 likes
                      Last Post PaulMohn  
                      Started by inanazsocial, Today, 01:15 AM
                      1 response
                      8 views
                      0 likes
                      Last Post NinjaTrader_Jason  
                      Started by rocketman7, Today, 02:12 AM
                      0 responses
                      10 views
                      0 likes
                      Last Post rocketman7  
                      Started by dustydbayer, Today, 01:59 AM
                      0 responses
                      4 views
                      0 likes
                      Last Post dustydbayer  
                      Started by trilliantrader, 04-18-2024, 08:16 AM
                      5 responses
                      23 views
                      0 likes
                      Last Post trilliantrader  
                      Working...
                      X