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

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.
    Emily C.NinjaTrader Customer Service

    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.
        Emily C.NinjaTrader Customer Service

        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 aligator, 01-06-2022, 12:14 PM
            4 responses
            233 views
            0 likes
            Last Post john_44573  
            Started by reynoldsn, Today, 05:56 PM
            0 responses
            4 views
            0 likes
            Last Post reynoldsn  
            Started by bortz, 11-06-2023, 08:04 AM
            51 responses
            1,989 views
            0 likes
            Last Post aligator  
            Started by dmking, 11-12-2019, 12:31 PM
            4 responses
            4,150 views
            0 likes
            Last Post jasonw
            by jasonw
             
            Started by roblogic, Today, 04:31 PM
            0 responses
            10 views
            0 likes
            Last Post roblogic  
            Working...
            X