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

FirstTickofBar CalculateOnBarClose

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

    FirstTickofBar CalculateOnBarClose

    protected override void OnBarUpdate()
    {
    if(FirstTickOfBar)
    Print(CurrentBar.ToString() + "firsttickofbar:" + Close[0].ToString());
    }

    When the CalculateOnBarClose is set as True, the output is
    0firsttickofbar:1955.25
    1firsttickofbar:1958.25
    2firsttickofbar:1961.75
    3firsttickofbar:1964.75
    4firsttickofbar:1969
    5firsttickofbar:1970
    6firsttickofbar:1969.25
    7firsttickofbar:1975
    8firsttickofbar:1977.5
    9firsttickofbar:1979.75
    10firsttickofbar:1976
    11firsttickofbar:1976
    12firsttickofbar:1974.5
    13firsttickofbar:1976.5
    14firsttickofbar:1978.25
    15firsttickofbar:1971
    16firsttickofbar:1959.75
    17firsttickofbar:1959.75
    18firsttickofbar:1960.25
    19firsttickofbar:1947
    20firsttickofbar:1944.5
    21firsttickofbar:1930.5
    22firsttickofbar:1933

    When the CalculateOnBarClose is set as False, the output is
    0firsttickofbar:1955.25
    1firsttickofbar:1958.25
    2firsttickofbar:1961.75
    3firsttickofbar:1964.75
    4firsttickofbar:1969
    5firsttickofbar:1970
    6firsttickofbar:1969.25
    7firsttickofbar:1975
    8firsttickofbar:1977.5
    9firsttickofbar:1979.75
    10firsttickofbar:1976
    11firsttickofbar:1976
    12firsttickofbar:1974.5
    13firsttickofbar:1976.5
    14firsttickofbar:1978.25
    15firsttickofbar:1971
    16firsttickofbar:1959.75
    17firsttickofbar:1959.75
    18firsttickofbar:1960.25
    19firsttickofbar:1947
    20firsttickofbar:1944.5
    21firsttickofbar:1930.5
    22firsttickofbar:1933
    23firsttickofbar:1934.25

    Why CalculateOnBarClose=false input one more bar? The above simulation is based on historical data only.

    Thanks.

    #2
    Hello,

    Thank you for the question.

    This would be expected, I have created a simple example based on yours that more clearly shows this difference. Please see the attached photos for the Dot placement regarding the bars. This test was done using 10 bars to load for simplicity.

    Code:
    if(FirstTickOfBar)
    {
    	Print(CurrentBar.ToString() + "firsttickofbar:" + Close[0].ToString());
    	DrawDot(CurrentBar.ToString(), true, 0, Close[0], Color.Lime);	
    }
    I look forward to being of further assistance.
    Attached Files
    JesseNinjaTrader Customer Service

    Comment


      #3
      I have another question about FirstTickOfBar.
      When I set CalculateOnBarClose as False, why does the following code not output "rest of ticks"?

      Is this beacause I use the historical data?
      When I set CalculateOnBarClose as False, the OnBarUpdate() will be triggered tick by tick. Why does the rest ticks not trigger the statement in the else part?

      Thank you.


      Code:
      if(FirstTickOfBar)
      {
          Print(CurrentBar.ToString() + "firsttickofbar:" + Close[0].ToString());
          DrawDot(CurrentBar.ToString(), true, 0, Close[0], Color.Lime);    
      }
       else
           Print("rest of ticks");

      Comment


        #4
        Hello,

        In historical data there would be no Intrabar data to trigger this condition more than once, for example if you are on a 1 minute time frame, OnBarUpdate would only be executed once per 1 minute or bar. With CalculateOnBarClose = false, this would still only happen once per minute or bar through the historical data

        Once you are in realtime, you would get the First tick, along with subsequent OnBarUpdate calls for each tick.

        In historical data it is hard to test first tick of bar if you are also looking for other ticks, you could instead try using Market Replay, Simulated data feed or Realtime data for testing.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Shansen, 08-30-2019, 10:18 PM
        24 responses
        938 views
        0 likes
        Last Post spwizard  
        Started by Max238, Today, 01:28 AM
        0 responses
        3 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by rocketman7, Today, 01:00 AM
        0 responses
        2 views
        0 likes
        Last Post rocketman7  
        Started by wzgy0920, 04-20-2024, 06:09 PM
        2 responses
        27 views
        0 likes
        Last Post wzgy0920  
        Started by wzgy0920, 02-22-2024, 01:11 AM
        5 responses
        32 views
        0 likes
        Last Post wzgy0920  
        Working...
        X