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 the current open of a building Bar?

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

    How to get the current open of a building Bar?

    Hi Ninjas,

    A simple situation. A Script that runs with CalculateOnBarClose = True, then when a new Bar is beginning, I'd like to call its current Open. Is it as simple as calling Open[0] setting previously CalculateOnBarClose = False ?

    #2
    Hi Pstrusi,

    Yes, in order to get the most current bar being built you will need to have the script run with CalculateOnBarClose set to false. You can then filter it out with FirstTickOfBar.

    This will be true when a new bar is built.

    http://www.ninjatrader.com/support/h...ttickofbar.htm
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Very useful response, thanks Cal

      Comment


        #4
        But I have this doubt: in order to get the proper signals from the Script, this must evaluate the Close, Open and Median of the last closed Bar; if I use tick by tick Bar, how can I call this?

        Allow me to explain clearly the situation:

        The Script evaluates Bar by Bar ( CalculateOnBarClose = True ) But when a signal entry is received, the Script must trigger an order at the price of the FirstTick of the next bar, so this is why I'm asking
        Last edited by pstrusi; 12-16-2013, 07:20 AM.

        Comment


          #5
          Pstrusi,

          You can reference the last bar's price series by using a bar index 1.
          I.E. Close[1] will reference the closing price of one bar ago.

          Code:
          OnBarUpdate()
          {
               if(FirstTickOfBar)
               {
                   //strategy logic here
               }
          }
          Cal H.NinjaTrader Customer Service

          Comment


            #6
            Not sure how, cause I'm still using CalculateOnBarClose=False. Do you mind to show me how to set and call this serie 1?

            If I'm using CalculateOnBarClose=False, any new Bar Object will be filtered through the tick by tick method, right? then how can I set a Bar object series that carries Close, Open and Median that I need for my calculations?
            Last edited by pstrusi; 12-16-2013, 07:49 AM.

            Comment


              #7
              Pstrusi,

              Example of this in use is below -
              Code:
              protected override void OnBarUpdate()
                      {
                          if(FirstTickOfBar)
              		{
              			if(SMA(14)[1] > SMA(7)[1])
              			{
              				EnterLongLimit( 5, Close[1], "Long1");
              			}
              				
              		}
              	}
              This filters out the FirstTickOfBar, which is also the last tick of the closed bar, meaning that the if statement will only be true when a bar closes with the first tick of the new bar.
              Cal H.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_Cal View Post
                Pstrusi,

                Example of this in use is below -
                Code:
                protected override void OnBarUpdate()
                        {
                            if(FirstTickOfBar)
                		{
                			if(SMA(14)[1] > SMA(7)[1])
                			{
                				EnterLongLimit( 5, Close[1], "Long1");
                			}
                				
                		}
                	}
                This filters out the FirstTickOfBar, which is also the last tick of the closed bar, meaning that the if statement will only be true when a bar closes with the first tick of the new bar.
                I see your logic, the tick before the FirstTick will be the Close of the last Bar, but that means too that: Median[1] and Open[1] will be the correct values for the whole Last Bar ? or will these values be the same as Close[1] cause they're just reference to the that tick?

                Comment


                  #9
                  They will be the last closed bars' values.
                  You can confirm this by using Print(Close[1]); in the logic there to show the value of the Close[1] that it is grabbing.
                  Cal H.NinjaTrader Customer Service

                  Comment


                    #10
                    I imagined that. Allow me to remind my simple request:

                    I got a script that evaluates closed Bar by Closed Bar ( CalculateOnBarClose = True ), once the last closed Bar is evaluated, the script triggers an Limit Order ( BUY or SELL ) that it should be at the same price of the FirstTickofBar ( obvious the next active Bar ), so as you can see the conflict is obvious because I'd need two opposite CalculateOnBarClose ( True and False )

                    So my question:

                    How could I achieve this ?

                    Comment


                      #11
                      The only solution to me is simply to add or substract a fix price change to the Close[0]. The risk that orders remain unfilled will depend on your price change. However if any programming ideas let me know

                      Thanks anyway

                      Comment


                        #12
                        the conflict is obvious because I'd need two opposite CalculateOnBarClose ( True and False )
                        This is not possible. However, this is why the FirstTickOfBar is there. This function only returns true when the first tick of a new bar comes through. After that, anything held in that if statement will not be calculated until the next new bar.

                        This allows you to simulate a CalculateOnBarClose set to true and run your script on a bar by bar calculation while running it set to false on the chart.
                        Cal H.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by DJ888, 04-16-2024, 06:09 PM
                        6 responses
                        18 views
                        0 likes
                        Last Post DJ888
                        by DJ888
                         
                        Started by Jon17, Today, 04:33 PM
                        0 responses
                        1 view
                        0 likes
                        Last Post Jon17
                        by Jon17
                         
                        Started by Javierw.ok, Today, 04:12 PM
                        0 responses
                        6 views
                        0 likes
                        Last Post Javierw.ok  
                        Started by timmbbo, Today, 08:59 AM
                        2 responses
                        10 views
                        0 likes
                        Last Post bltdavid  
                        Started by alifarahani, Today, 09:40 AM
                        6 responses
                        41 views
                        0 likes
                        Last Post alifarahani  
                        Working...
                        X