Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Current Bar and OnBarUpdate

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

    Current Bar and OnBarUpdate

    Hi

    I am a newbie and have searched for the answer to my question and found a few relevant but ultimatly unhelpful posts for NT7.

    Nothing for NT8.

    To simplify my scenario to something completely basic I would like to detect on the open tick of a new bar whether the close of the old bar is less than the open of the current bar.

    So something like
    if(CurrentBar.Oper>Close[0]){
    }

    From what I could see in NT 7 this was not possible - which seems strange to me as I would have thought that this logic would be pretty common. Maybe I have missed something.

    Any suggestions on a way to achieve this?

    Many thanks,

    Jon

    #2
    Hello JonE1974,

    If you were to use the following

    if(Open[0]>Close[1])
    {

    }
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Hello JonE1974,

      If you were to use the following
      Code:
      if(Open[0]>Close[1])
      {
      //DoSomething
      }
      And run the strategy with Calculate set to OnEachTick, do you get the results you desire?

      I would encourage you to use the strategy builder as you learn NinjaScript, which allows you to view the code to see how the builder writes it.

      Strategy Builder NT8:
      https://www.youtube.com/watch?v=HCyt...We0Nf&index=10

      Strategy Builder Section of our Helpguide:
      http://ninjatrader.com/support/helpG...er_screens.htm

      Please let us know if you need further assistance.
      Alan P.NinjaTrader Customer Service

      Comment


        #4
        Hi Alan

        Yes I've been using the builder to create the code then modifying by hand - familiar with normal c#.

        Wouldn't using the Open[0] > Close[1] be the same as looking at the prior 2 candlesticks?

        Or does on each tick make Open[0] reference the active candle?

        I'll have a try with the code in the morning.

        Regards

        Jon

        Comment


          #5
          Hi Jon,

          When Calculate is set to .OnEachTick or .OnPriceChange, the [0] index for a series will reference the currently building and open bar.

          When Calculate is set to .OnBarClose, the [0] index will reference the most recently completed bar.

          http://ninjatrader.com/support/helpG...taIsReferenced

          http://ninjatrader.com/support/helpG.../calculate.htm
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Thanks for the help, that clarifies things.

            Regard

            Jon

            Comment


              #7
              Actually this doesnt seem to work as expected.

              It still references the wrong bar. When I have it set to calc on each tick (using a strategy wiard to ensure it is setup properly) I use the following at the start of the OnBarUpdate function to check and see if there are multiple events being raised - I would expect to see loads for the same time and only the first should have the true state - but I only see one per time and that is set to true
              Print(Time[0].ToString("dd/MM/yyyy") + "," + Time[0].ToString("HH:mm:ss")+ IsFirstTickOfBar);

              Could this be because I am using a backtest and not live data?

              If so how would you do this kind of thing with backtesting?

              Regards

              Jon

              Comment


                #8
                Hello Jon,

                The close time of the bar is not affected. The bar will still close at the same time.

                The Calculate option only causes OnBarUpdate() to trigger each time a tick is received or the price is changed.

                If you are printing the close time of the bar (Time[0]) instead of the current time (DateTime.Now) I would expect that it would print the same time stamp repeatedly until the bar closes.


                When processing historical data and backtesting, TickReplay is required for Calculate to function for .OnEachTick or .OnPriceChange.

                From the help guide:
                "On a historical data set, only the OHLCVT of the bar is known and not each tick that made up the bar. As a result, State.Historical data processes OnBarUpdate() only on the close of each historical bar even if this property is set to OnEachTick or OnPriceChange. You can use TickReplay or a Multi-time frame script to obtain intrabar data."
                http://ninjatrader.com/support/helpG.../calculate.htm
                Last edited by NinjaTrader_ChelseaB; 08-28-2017, 10:24 AM.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Chelsea,

                  Well spotted thanks for that.

                  The TickReplay looks like it will help me with the backtesting.

                  Thanks for the help,

                  Jon

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Pbarrionuevo, Today, 04:30 PM
                  0 responses
                  2 views
                  0 likes
                  Last Post Pbarrionuevo  
                  Started by vantojo, Today, 01:39 PM
                  0 responses
                  16 views
                  0 likes
                  Last Post vantojo
                  by vantojo
                   
                  Started by Rubens_2020, Today, 01:48 PM
                  1 response
                  10 views
                  0 likes
                  Last Post NinjaTrader_Kate  
                  Started by kempotrader, Today, 01:34 PM
                  1 response
                  23 views
                  0 likes
                  Last Post NinjaTrader_ChrisL  
                  Started by bc24fl, Today, 01:50 PM
                  1 response
                  11 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Working...
                  X