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

Bar Numbers

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

    Bar Numbers

    While coding in Strategy Builder if you are using the close of a bar then Bar 1 will be the latest closed bar and Bar 2 before it and so on, correct? In back testing is a trade taken a bar later? Like say when a new bar opens and the conditions are met I see the trade taken on the following bar.
    Thank you.

    #2
    Hello Trader17,

    Thanks for your post.

    To clarify how the strategy performs under different conditions:

    If your strategy is set to Calculate.OnBarClose (which is the default behavior unless you select otherwise) then the strategy code is executed at the end of the just closed bar which is identified by [0]. The previous bar is [1] and the bar before that is [2] and the bar that is forming is unknown to the strategy. The strategy would perform the same on live data or historical data.

    If your strategy is set to Calculate.OnPriceChange or Calculate.OnEachTick, then the strategy code is executed on each change in price or on each incoming tick and this changes the references so [0] is now pointing to the currently forming bar, [1] is pointing to the just closed bar, [2] the bar before that, etc. This is how the strategy would perform on live or market replay data. In terms of Historical data, even though the strategy would be set to Calculate.OnPriceChange or Calculate.OnEachTick, it will perform the same as Calculate.OnBarClose.

    When a strategy is operating under Calculate.OnBarClose, the code is executed at the end of the bar and if the code places an order, the order would be filled on the next bar. You may want to use a Draw.Dot() in your code section where you place an order as this would show the bar where the code placed the order and then on the next bar you would see the order filled.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Now it makes sense. I thought the bar that just closes is one and the one before it 2 and so on. That is why I was seeing the skip of a bar before execution.
      Thanks.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by gentlebenthebear, Today, 01:30 AM
      3 responses
      15 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by PhillT, Today, 02:16 PM
      2 responses
      6 views
      0 likes
      Last Post PhillT
      by PhillT
       
      Started by Kaledus, Today, 01:29 PM
      3 responses
      10 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by frankthearm, Yesterday, 09:08 AM
      14 responses
      47 views
      0 likes
      Last Post NinjaTrader_Clayton  
      Started by PaulMohn, Today, 12:36 PM
      2 responses
      17 views
      0 likes
      Last Post PaulMohn  
      Working...
      X