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 DanielSanMartin, Yesterday, 02:37 PM
              2 responses
              12 views
              0 likes
              Last Post DanielSanMartin  
              Started by DJ888, 04-16-2024, 06:09 PM
              4 responses
              12 views
              0 likes
              Last Post DJ888
              by DJ888
               
              Started by terofs, Today, 04:18 PM
              0 responses
              11 views
              0 likes
              Last Post terofs
              by terofs
               
              Started by nandhumca, Today, 03:41 PM
              0 responses
              7 views
              0 likes
              Last Post nandhumca  
              Started by The_Sec, Today, 03:37 PM
              0 responses
              3 views
              0 likes
              Last Post The_Sec
              by The_Sec
               
              Working...
              X