Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to call OnBarUpdate function 3 seconds before candle is rendered.

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

    How to call OnBarUpdate function 3 seconds before candle is rendered.

    I want to run OnBarUpdate function before 3 seconds the candle is rendered. For example the base timespan is 1min, i want to make run OnBarUpdate function on 57s, ie 1min-3s.

    #2
    Hello Mykhailo,

    Thank you for your post and welcome to the NinjaTrader forum community.

    OnBarUpdate() is an event-driven method, so there is no way to call it manually. It is called based on the Calculate property for the script, which can be set to call OnBarUpdate() either On Bar Close, On Price Change, or On Each Tick. More information may be found at the links below:What is your reasoning for wanting to call OnBarUpdate() 3 seconds before the candle completes? Once I have a better idea of what you are looking to achieve, I would be glad to assist you further.

    I look forward to your reply.

    Comment


      #3
      Thank you for your quick replay. My problem is want to set strategy logics before bartime(in seconds) from rendering new candle. So I want to use dataseries like
      if (State == State.Configure) {
      AddDataSeries(BarsPeriodType.Second, 1);
      }

      And i displayed time on bottom right corner, but it was not accurate. Times sometimes skips two or three.
      Is there any way to do so?

      Comment


        #4
        Originally posted by Mykhailo View Post
        Thank you for your quick replay. My problem is want to set strategy logics before bartime(in seconds) from rendering new candle. So I want to use dataseries like
        if (State == State.Configure) {
        AddDataSeries(BarsPeriodType.Second, 1);
        }

        And i displayed time on bottom right corner, but it was not accurate. Times sometimes skips two or three.
        Is there any way to do so?
        If you call AddDataSeries() to add a 1 second series, then you could access the timestamps of the 1-second bars via Times[1][barsAgo]


        You could then potentially create a condition that checks if the 1-second timestamp is a certain value that would be 3 seconds prior to the close of the main series.

        For more information on working with multi-series scripts:


        Please let us know if we may be of further assistance.

        Comment


          #5
          protected override void OnStateChange()
          {​
          if (State == State.Configure)
          {
          AddDataSeries(BarsPeriodType.Second, 1);
          }
          }​


          protected override void OnBarUpdate()
          {

          if (BarsInProgress == 0){

          } else if (BarsInProgress == 1) { // 1s chart
          Print( Times[1][0]);
          }
          //Add your custom strategy logic here.
          }



          When i run this code, i got such result.

          2024-03-13 19:29:00
          2024-03-13 19:29:04
          2024-03-13 19:29:05
          2024-03-13 19:29:07
          2024-03-13 19:29:08
          2024-03-13 19:29:09
          2024-03-13 19:29:13
          2024-03-13 19:29:14
          2024-03-13 19:29:16
          2024-03-13 19:29:17
          2024-03-13 19:29:20
          2024-03-13 19:29:21
          2024-03-13 19:29:23
          2024-03-13 19:29:25
          2024-03-13 19:29:26
          2024-03-13 19:29:28
          2024-03-13 19:29:30


          but i want to get every all seconds. current TF is 1min.

          Comment


            #6
            Hello Mykhailo,

            It may be there was not any volume during that second and no bar was formed.

            If you open a new chart with a 1 second data series, are you seeing the missing 1 second bars on the chart?

            Are you able to reproduce this on an ES 06-24 chart?
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Yesterday, 05:17 AM
            0 responses
            54 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            131 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            73 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            44 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            49 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X