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

Updating Bar on close only when CalculateOnBarClose = false

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

    Updating Bar on close only when CalculateOnBarClose = false

    I am a newbie in NT. Most of my knowledge is in TradeStation. So I have a newbie question :

    I have created an indicator that must update on the tick, so I set the CalculateOnBarClose to false.

    Inside this indicator I would also like to update certain things only on Bar close. Can I do that even if CalculateOnBarClose is set to false ?

    If so what do I have to do ?


    Thank you very much for your help

    #2
    balrouche,

    One of our support team trainees will respond to this thread in a little bit. Thank you for your patience in this matter.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      balrouche, NinjaTrader behaves much like TradeStation with regards to CalculateOnBarClose. In NinjaTrader, the bar close isn't known until the last tick comes in. At that point, there is a new bar being created already.

      What this means is the bar close, and the next bar open are nearly identical. So, knowing that little detail, NinjaTrader has an easily applicable setting called FirstTickOfBar.

      What you can do with FirstTickOfBar is check in OnBarUpdate for events you'd like to execute only once per bar:
      Code:
      if (FirstTickOfBar)
      {
          // sample stuff to get last bar's prices
          // keep in mind this is now a new bar
      Print("Most recent Close:\t" + Close[1]);
      Print("Most recent High:\t" + High[1]);
      etc...
      }
      Keep in mind that since it is a new bar, all the bar index references will need to be adjusted (mostly from 0 -> 1). Hopefully this gets you going in the right direction, and let us know if you have any other questions.
      AustinNinjaTrader Customer Service

      Comment


        #4
        BarsSinceSession

        Thank you very much Austin. That was the way I wanted to go. Now I have to do some stuff at the close of the first bar of the session. If I use this will it work :

        If (Bars.BarsSinceSession == 1)
        {
        if (FirstTickOfBar)
        {
        bla bla bla
        }
        }

        Is Bars.BarSinceSession = 1 only at the first tick of the second bar or at the first tick of the first bar ?

        If it is at the first tick of the second bar I should use Bars.BarsSinceSession == 2.

        Thank you

        Comment


          #5
          blarouche, I ran this simple test:
          Code:
          if (Bars.BarsSinceSession == 1)
                  {
                      if (FirstTickOfBar)
                      {
                          Print("Close[1]:\t" + Close[1]);
                          Print("Open[1]:\t" + Open[1]);
                          Print("ToTime:\t" + ToTime(Time[1]));
                      }
                  }
          and it returned the data for the first bar on the chart.

          My coworker just informed me of another method you could use at the first bar:
          Code:
          if (Bars.FirstBarOfSession && FirstTickOfBar)
          AustinNinjaTrader Customer Service

          Comment


            #6
            Thank you

            Many thanks Austin

            Comment


              #7
              Difference between BarsSinceSession and FirstBarOfSession

              Austin,
              Just to let you know the I have noticed a difference in result when I used Bars.FirstBarOfSession and Bars.BarsSinceSession.

              With Bars.FirstBarOfSession I had to use close[0] to refer to First Bar close on the first tick of bar2.
              With Bars.BarsSinceSession I had to use close[1] to refer to First Bar close on the first tick of bar2.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by r68cervera, Today, 05:29 AM
              0 responses
              2 views
              0 likes
              Last Post r68cervera  
              Started by geddyisodin, Today, 05:20 AM
              0 responses
              3 views
              0 likes
              Last Post geddyisodin  
              Started by JonesJoker, 04-22-2024, 12:23 PM
              6 responses
              34 views
              0 likes
              Last Post JonesJoker  
              Started by GussJ, 03-04-2020, 03:11 PM
              12 responses
              3,239 views
              0 likes
              Last Post Leafcutter  
              Started by AveryFlynn, Today, 04:57 AM
              0 responses
              6 views
              0 likes
              Last Post AveryFlynn  
              Working...
              X