• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Print function if no data

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

    Print function if no data

    Dear NT team

    I run strategies across hundreds of symbols. I may not have data for some of them. I would like to create a Print() function within my strategies that it prints the Instrument.FullName plus a warning into the output window if there is no data all (i.e. if it never access a certain BarsInProgress). How do I achieve this?

    Thank you in advance
    whotookmynickname

    #2
    Hi whotookmynickname,

    Because NinjaScript strategis are event driven, meaning that methods in the script will be triggered when data is received or a bar is closed, the only way I can think of to accomplish this would be to use a timer.

    The timer could then check the length of each added data series by looping through BarsArray.

    I would be very careful with this. Using a timer is not support by NinjaTrader.

    Attached is a sample of a script that uses a timer.
    Attached Files
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea

      Thank you for the suggestion. Is there no easier way to check if there is any data at all?
      I can do the opposite (OnStartUp, or on the first OnBarUpdate -> Print), but that would work only if there is data.

      whotookmynickname

      Comment


        #4
        Hi whotookmynickname,

        You can get the count of a BarsArray element in OnStartUp(). This is the number of bars of historical data.

        This would only work once though..

        Code:
        protected override void OnStartUp()
        {
        Print(BarsArray[0].Count);
        }
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by whotookmynickname View Post
          Hi Chelsea

          Thank you for the suggestion. Is there no easier way to check if there is any data at all?
          I can do the opposite (OnStartUp, or on the first OnBarUpdate -> Print), but that would work only if there is data.

          whotookmynickname
          No, there is not. Event-driven means you need an event to drive the process, hence the Timer() that you can use to be the event driver, essentially independent of NinjaTrader processing itself.

          Comment


            #6
            Hi whotookmynickname,

            koganam is correct here. I did a test with OnStartUp and this does require a bar before triggered.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hello community,

              Adding updated scripts.
              Attached Files
              Chelsea B.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Aporshnev, Today, 01:47 AM
              1 response
              6 views
              0 likes
              Last Post NinjaTrader_Marco  
              Started by caveat_lector, Today, 12:12 AM
              1 response
              6 views
              0 likes
              Last Post Atm Card  
              Started by ksarin, Yesterday, 04:31 PM
              2 responses
              9 views
              0 likes
              Last Post Atm Card  
              Started by pharofx, Yesterday, 09:30 PM
              1 response
              19 views
              0 likes
              Last Post Atm Card  
              Started by swcooke, Yesterday, 08:39 PM
              1 response
              9 views
              0 likes
              Last Post Atm Card  
              Working...
              X