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

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 funk10101, Today, 12:02 AM
              1 response
              10 views
              0 likes
              Last Post NinjaTrader_LuisH  
              Started by GLFX005, Today, 03:23 AM
              1 response
              6 views
              0 likes
              Last Post NinjaTrader_Erick  
              Started by nandhumca, Yesterday, 03:41 PM
              1 response
              12 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by The_Sec, Yesterday, 03:37 PM
              1 response
              11 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by vecnopus, Today, 06:15 AM
              0 responses
              1 view
              0 likes
              Last Post vecnopus  
              Working...
              X