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

Trading Multiple Stocks Dynamically

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

    Trading Multiple Stocks Dynamically

    Hoping NT support or any experienced users may be able to help me please. The automated strategy that I would like to build looks like this:
    1. Stock Screener Step: In pre-trading, ~2,000 stocks are monitored (No trading takes place, data resolution doesn't need to be tick level). Based upon rule criteria, by 9.29am ~500 of the ~2,000 stocks are chosen to be 'trade eligible' that day. (500, or the max number that can reliably run each day - TBD)
    2. Live Trading Step: The ~500 stocks are then watched closely with tick data resolution, with trades entered/exited throughout the day.

    I've been able to setup a list of 2,000 stocks and run a strategy against it (basket test) that streamwriter outputs the 500 stocks to trade each day. I've also created a separate strategy that works (basket backtest) against a separate, fixed list of ~500 stocks. Unfortunately I'm a little stuck at:
    A) how to actually run a live automated strategy against multiple stocks at once (not basket backtesting, "basket live running")
    B) how to dynamically stop following/watching the ~1,500 or so stocks that are not selected for trading on a given day, and subscribe to only the 500 chosen. E.g. I can't be subscribed to 2,000 stocks all day everyday, the system will fallover - I think I need to have the system run against 2k, then when 9.29am-9.30am is reached, reset all of the states to load in a new, reduced list of stocks from a file.

    Any advice on A & B would be really helpful please. Ideally if anyone has a super basic Moving Average code example/framework that works on say 5 stocks, that'd be a massive help just to see how it can run. Likewise any code examples showing how to dynamically subscribe/unsubscribe to stocks would be a dream (but don't want to push my luck!). Thanks in advance!

    ChainsawDR

    #2
    Hello ChainsawDR,

    To actually run the strategy live with multiple instruments you would need to edit the strategy and then program those instruments into the AddDataSeries statements. Currently there is no supported means to dynamically load many instruments from NinjaScript so that would be a manual process. https://ninjatrader.com/support/help...ghtsub=adddata

    You can see an example of using more than one series in the SampleMultiInstrument and SampleMultiTimeframe strategies that come with NinjaTrader.

    The selecting of the stocks to watch would also be a manual process, there is not a supported way to stop watching or start watching instruments. If you have a way that you can create in code which tells you which stocks should or should not be watched you could filter a market analyzer but all stocks will still be loaded/subscribed to. The market analyzer can be used to filter based on criteria and that simply hides the rows which don't match the criteria.

    I look forward to being of further assistance.

    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks Jesse, I will take a look at those samples. You mentioned that there are not any supported methods, do you know of any unsupported methods? I assume I'm not the first person to want to take an approach like this so wondering how others are overcoming this.

      Thanks again

      Comment


        #4
        Hello ChainsawDR,

        I am not aware of any means to dynamically load many series like you specified. While technically you can use variables or logic with AddDataSeries the help guide specifically notes that can fail in certain use cases. Because loading data is a very important step for the script and really needs to be accurate there is not really anything we could suggest as an alternative for NinjaScript at this time.



        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Thanks Jesse. Sorry final questions. Do you know if it is feasible/supported to reset the states at certain points? E.g. Run a strategy that has a time based switch built in (one strategy before 9.30am, another after 9.30am). E.g. run at 9am on logic A that produces variables/StreamWriter output at 9.28am, then at 9.30am the strategy terminates/cleans up/disposes of resources, and goes back to the Configure state using logic B. If yes, are there any guides for prompting the program to move to another state?

          Also, the SampleMultiInstrument strategy- am I correct in thinking this wouldn't actually trade multiple instruments, only the 'main instrument' selected on say a chart? Aka using EBAY on a chart and applying a strategy, this would trade ebay and also have data available for MSFT, but entering trades for both MSFT and EBAY today would require a lot more rules and logic to be applied, is this correct?

          Thanks again

          ChainsawDR
          Last edited by ChainsawDR; 08-09-2021, 04:31 PM.

          Comment


            #6
            Hello ChainsawDR,

            There is not a way to reset the script like that, at best you could use variables in OnBarUpdate/ the events to delegate logic based on the ties or other conditions. The OnStateChange method won't be run again unless you re apply the strategy.

            You are correct with the sample also, that is simply using the secondary instrument for data but otherwise all the orders and logic are being done with the primary. You can submit to the secondary as well, you need to remove

            if (BarsInProgress != 0) return;



            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by andrewtrades, Today, 04:57 PM
            1 response
            5 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by chbruno, Today, 04:10 PM
            0 responses
            4 views
            0 likes
            Last Post chbruno
            by chbruno
             
            Started by josh18955, 03-25-2023, 11:16 AM
            6 responses
            436 views
            0 likes
            Last Post Delerium  
            Started by FAQtrader, Today, 03:35 PM
            0 responses
            7 views
            0 likes
            Last Post FAQtrader  
            Started by rocketman7, Today, 09:41 AM
            5 responses
            19 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Working...
            X