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 to get something to run on last bar on chart?

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

    How to get something to run on last bar on chart?

    Howdy.

    I have some various stats I have a script I have run on the end of each day, last bar of that particular session template.

    I.e. for a RTH session template of NQ, it will run on that last bar that occurs at the end of the session. My problem is that it works for every day except the very last session. So if I run the report over 15 days of data, it will collect the first 14 days, but it won't execute on the very last day, until a new day begins.

    Is there a way to get around this? Or is there a way to tell it to run on the very latest bar on the chart?

    The piece of code I am using to run at the end of the day is:
    Code:
    			if(Bars.LastBarOfSession )
    			{	
                                     Do somethign
    			}
    Last edited by forrestang; 12-14-2011, 04:47 PM.

    #2
    Hi forrestang,

    You can work with CurrentBar in relation to Count to identify the last bar on the chart.

    When CalculateOnBarClose = true:
    if (Count - 2 == CurrentBar)

    When CalculateOnbarClose = false:
    if (Count - 1 == CurrentBar)
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Thank you, that seems to be what I needed to trigger that last session run.

      Comment


        #4
        Hi,
        Will Count also work in case of MutiSymbol strategy?

        Regards

        Vivek

        Comment


          #5
          Hello Ankas,

          Thank you for your post.

          Count will work in multi-series indicators and strategies.

          Comment


            #6
            Hello,

            I tried to use marking the last bar with the information from NT-support and I do

            DrawDot("LastBar" + CurrentBar, false, 0, Low[0] - 2 * TickSize, Color.Chartreuse);

            But the dots remain below the bars, I just need a dot below the last bar.

            What do I have to change please?

            Thank you
            Tony

            Comment


              #7
              Originally posted by tonynt View Post
              Hello,

              I tried to use marking the last bar with the information from NT-support and I do

              DrawDot("LastBar" + CurrentBar, false, 0, Low[0] - 2 * TickSize, Color.Chartreuse);

              But the dots remain below the bars, I just need a dot below the last bar.

              What do I have to change please?

              Thank you
              Tony
              Try:
              Code:
              DrawDot("LastBar" , false, 0, Low[0] - 2 * TickSize, Color.Chartreuse);
              If you just want a dot below the last bar on the chart.

              Comment


                #8
                Hello,

                thanks for your help. Seems to work.

                Best regards
                Tony


                Originally posted by forrestang View Post
                Try:
                Code:
                DrawDot("LastBar" , false, 0, Low[0] - 2 * TickSize, Color.Chartreuse);
                If you just want a dot below the last bar on the chart.

                Comment


                  #9
                  Hi,
                  Try out
                  if ( CurrentBar >= ( Count -2 ))
                  DrawDot("LastBar", false, 0, Low[0] - 2 * TickSize, Color.Chartreuse);

                  Regards

                  Vivek

                  Comment


                    #10
                    Hello Tony,

                    Thank you for your post.

                    forrestang is correct here. Removing the CurrentBar from the tag string will mean there is only one tag listed so only one dot drawn. If you add a variable to the tag such as CurrentBar that updates every bar you will get a dot each time the condition to draw the dot occurs.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Mindset, 05-06-2023, 09:03 PM
                    10 responses
                    262 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Started by michi08, 10-05-2018, 09:31 AM
                    5 responses
                    741 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by The_Sec, Today, 02:29 PM
                    0 responses
                    2 views
                    0 likes
                    Last Post The_Sec
                    by The_Sec
                     
                    Started by tsantospinto, 04-12-2024, 07:04 PM
                    4 responses
                    62 views
                    0 likes
                    Last Post aligator  
                    Started by sightcareclickhere, Today, 01:55 PM
                    0 responses
                    1 view
                    0 likes
                    Last Post sightcareclickhere  
                    Working...
                    X