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

OnBarUpdate Called Twice using Calculate.OnBarclose

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

    OnBarUpdate Called Twice using Calculate.OnBarclose

    The Definition for the Calculate.OnBarUpdate on the help guide of NT8 goes like this:

    Definition
    Determines how often OnBarUpdate() is called for each bar. OnBarClose means once at the close of the bar


    However the code below shows that it actually is called twice for every bar.
    Does it always run twice ? is the manual wrong ? Can I make it run only once ?
    Code:
    int onBarUpdateCounter = 0;
    protected override void OnBarUpdate()
    { 
    	if (State!=State.Historical)
    	{
    		Print("onBarUpdateCounter: " + ++onBarUpdateCounter + "Current Bar " + CurrentBar);
    	}
    }

    outputs:
    onBarUpdateCounter: 1Current Bar 3855
    onBarUpdateCounter: 2Current Bar 3855
    onBarUpdateCounter: 3Current Bar 3856
    onBarUpdateCounter: 4Current Bar 3856
    onBarUpdateCounter: 5Current Bar 3857
    onBarUpdateCounter: 6Current Bar 3857

    #2
    Hello DerliFerreira,

    Thank you for your note.

    Under State.SetDefaults, is Calculate Set to,

    Code:
    Calculate	= Calculate.OnBarClose;
    I look forward to your reply.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      I realize that I am late to the table, but I am experiencing the same issue with OnBarUpdate being called twice for each bar.
      I have verified that I am using the value that you suggested below. I am using NinjaTrader 8.

      Here is an additional interesting fact: the issue only occurs when specifying a value greater than 1 for the "Price based on" parameters. That is: Last, Minute, 2 (or more)
      Any ideas? Thanks.


      Originally posted by NinjaTrader_AlanP View Post
      Hello DerliFerreira,
      Under State.SetDefaults, is Calculate Set to,
      Code:
      Calculate = Calculate.OnBarClose;

      Comment


        #4
        Hi rgoudie, thanks for your question.

        Do you have a script that you can Export and send to me so I can test? Also please let me know what kind of bars you are using on the chart (including the bar period).

        I look forward to hearing from you.
        Chris L.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by The_Sec, Yesterday, 03:53 PM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by mmenigma, Yesterday, 03:25 PM
        1 response
        11 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by kujista, Today, 05:44 AM
        0 responses
        7 views
        0 likes
        Last Post kujista
        by kujista
         
        Started by ZenCortexCLICK, Today, 04:58 AM
        0 responses
        9 views
        0 likes
        Last Post ZenCortexCLICK  
        Started by sidlercom80, 10-28-2023, 08:49 AM
        172 responses
        2,282 views
        0 likes
        Last Post sidlercom80  
        Working...
        X