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

Query about NT chart bar closure and indicator behavior

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

    Query about NT chart bar closure and indicator behavior

    Does the current bar on NT chart close at the last fraction of the last second of the current bar or it closes at the first tick of the next bar?

    Apparently, the later is correct. I have an indicator that upon a certain condition (for example A=B), it prints the current hour, minute, second and millisecond. This indicator is calculated at each tick. When the condition is achieved during the current bar, it keeps printing like this:

    Condition achieved 09:45:55:345
    Condition achieved 09:45:56:727
    Condition achieved 09:45:57:127
    Condition achieved 09:45:57:856 .......... and so on

    Definitely there is interruption if A!=B during the bar period. Like this; which is also normal

    Condition achieved 09:45:25:345
    Condition achieved 09:45:26:727
    Condition achieved 09:45:44:127
    Condition achieved 09:45:45:856

    However the problem resides here: Several times, I see this kind of prints:

    Condition achieved 09:45:55:345
    Condition achieved 09:45:56:727
    Condition achieved 09:45:57:127
    Condition achieved 09:46:00:856

    A print showing a calculation that is triggered by the first tick of the next bar. This induces a big confusion and is problematic since the condition A=B is calculated and checked with information from both the previous bar and the first tick of the new bar. Is this the case? Apparently it is. Would you please clarify?




    #2
    Please note that the the DateTime.Now is at the top of the OnBarUpdate function, this means that there is no delay between the instance at which the calculations was triggered and the printing to the output.

    Comment


      #3
      Hello MSerag,

      In realtime the first tick of the bar will close the previous bar.​

      I would not suggest using your PC clock DateTime.Now for testing NinjaScript, you can instead reference the bar times by using Time[0]. The Print would show the same bar time being printed while the bar is not closed, once the first tick of the bar happens you will see a new bar time printing because the bar closed.

      If you need to use OnEachTick processing I would suggest looking at how the indicator BuySellVolume works. That uses extra logic to accommodate using OnEachTick processing.

      JesseNinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by TraderBCL, Today, 04:38 AM
      2 responses
      7 views
      0 likes
      Last Post TraderBCL  
      Started by martin70, 03-24-2023, 04:58 AM
      14 responses
      105 views
      0 likes
      Last Post martin70  
      Started by Radano, 06-10-2021, 01:40 AM
      19 responses
      606 views
      0 likes
      Last Post Radano
      by Radano
       
      Started by KenneGaray, Today, 03:48 AM
      0 responses
      4 views
      0 likes
      Last Post KenneGaray  
      Started by thanajo, 05-04-2021, 02:11 AM
      4 responses
      471 views
      0 likes
      Last Post tradingnasdaqprueba  
      Working...
      X