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

Determining when an Instrument has Stopped Trading

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

    Determining when an Instrument has Stopped Trading

    I am trying to find a way to determine if an instrument has stopped trading. One idea I had was to add a second instrument in my code such as ^SP500 which I know will not go away. Then I thought I would find the last bar for ^SP500 using Today(Time[0]) and compare it with the current instrument also using Today(Time[0]) and if they are not equal, I would know the instrument has stopped trading.

    I tied the following code, but it doesn't like the syntax

    if (ToDay(Time[0][0]) < ToDay(Time[1][0]))
    {
    Do something
    }

    Any help would be appreciated.

    #2
    There are potentially a few ways you could approach this.

    The first one that came to mind would be to use OnMarketData() to check for data updates



    You could then pair this with a custom timer such as using DateTime.Now and comparing this to to the DateTime.Now of the last OnMarketData update

    Gets a DateTime object that is set to the current date and time on this computer, expressed as the local time.


    Let me know if I can further assist.
    LanceNinjaTrader Customer Service

    Comment


      #3
      If I understand what you are proposing, you would use OnMarektData() to find the date of the last change to the data using DateTime.Now. Wouldn't this give a false warning on weekends and market holidays?

      Comment


        #4
        How would you want holidays/weekends to be handled? In the end it would be up to you to decide how long the market needs to be inactive before triggering the condition. It would also require a custom timer event as the default methods in NinjaScript are only called when the market sends data.

        This falls into unsupported territory but if you would like I can try and find an un-supported sample of using a custom timer event.

        What are you trying to have the script do when the market is no longer active?

        Let me know if I can further assist.
        LanceNinjaTrader Customer Service

        Comment


          #5
          I am trying to generate an Alert in a Market Analyzer window when one of the stocks in my list has stopped trading. An example would be LCC which quit trading last week because it merged with another company. If I run a market analyzer screen on the weekend, I wouldn't want to be alerted if the stock has not stopped trading on the exchange. Sorry maybe I wasn't very clear in my original post.

          The reason I wanted to use something like ^SP500 to compare instruments against, was when EOD data is updated ^SP500 would be guaranteed to be updated. So if I can find the Today(Time[0]) of ^SP500 and compare it Today(Time[0]) of my instrument, it is easy to tell if they don't match. But maybe there is a better way. I just don't see it.

          Comment


            #6
            Ok I understand now sorry about that.

            I would think your original approach would work but just needs a minor syntax change from Time to Times

            if (ToDay(Times[0][0]) < ToDay(Times[1][0]))
            {
            //do something
            }

            This would compare the date of the primary series (which ever instrument its applied to) to the secondary series (which I'm assuming you would set to the SP500)

            Let me know if this doesn't resolve your issue.
            LanceNinjaTrader Customer Service

            Comment


              #7
              Thanks. That resolved my issue.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by rocketman7, Today, 02:12 AM
              5 responses
              23 views
              0 likes
              Last Post rocketman7  
              Started by trilliantrader, 04-18-2024, 08:16 AM
              7 responses
              28 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Started by samish18, 04-17-2024, 08:57 AM
              17 responses
              66 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Started by briansaul, Today, 05:31 AM
              1 response
              15 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by PaulMohn, Today, 03:49 AM
              1 response
              12 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Working...
              X