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

How to set the Instrument to trade in a strategy Prorammatically on the fly?

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

    How to set the Instrument to trade in a strategy Prorammatically on the fly?

    Hello ,

    I want my Strategy to decide in realtime and set the name of the STOCK to trade programmatically from the code ?
    Is it possible ?

    My idea I want my strategy to be able to read from a text file the name of the stock that will be traded , and all this realtime
    without giving the Stock name when create the strategy

    thanks

    Ron

    #2
    Hello Ron,

    Unfortunately, indicators and strategies cannot modify the Data Series.

    You can add series, such as other instruments, with Add(), and place orders to that series BarsInProgressIndex.
    (edited to show NinjaTrader 7 help guide links)





    While its unsupported to do so, its also possible to send keys to the window to change the instrument.
    The RolloverIndications uses this code.
    This RollOverIndicator was built to allow traders to see the date and offset applied to their futures historical data visually on the chart. Knowing what data is loaded in your charts is key information that any trader should be aware of and this indicator is designed to make this information easier to get too. The […]


    The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.
    Last edited by NinjaTrader_ChelseaB; 09-28-2020, 08:27 AM.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea ,

      So in NT7 and NT8 you can't change the DataSeries Instrument programmatically ? correct ?

      My Idea is to build trading strategy and use a scanner (maybe market anlyzer can help here) the scanner will find me the best candidates to trade in

      realtime , after i have my 5 symbols i want to give that to my strategy automatically not having to choose manually the stocks to trade .

      currently I'm using NT7 with my strategies , do you recommend moving to NT8 it's better options for what i'm want to do ?

      Tell me if you have any idea or direction how can i do this .


      Thanks

      Ron
      Last edited by ronbary; 09-28-2020, 03:59 AM.

      Comment


        #4
        Hello Ron,

        That is correct, indicators and strategies cannot modify the Data Series.

        Yes, the Market Analyzer is used as a scanner to add rows of instruments and then an indicator column.



        With window linking this can change the instrument on a chart when selecting an instrument in the Market Analyzer.



        For a Strategy to do this internally, it would be necessary to add all of the instrument series with Add(), and just place orders to the BarsInProgressIndex of any specific one of the series.


        I do always recommend using the latest release of the flagship application, currently 8.0.22.2.

        However, the answer is basically the same with one addition. NinjaTrader 8 has a BarsRequest() that can request out of sync data from an Account directly. This means some data could be loaded for a list of instruments and some logic run on that data. The strategy however, would still only be able to internally use data and place orders to series from AddDataSeries().
        If you wanted to go full Addon and not have a NinjaScript Strategy, you could actually loop through any instruments you want, and start and stop data subscriptions and place orders to any instrument you would like. The difficulty is that the NinjaScript Strategy tools are not available, like series or being able to call indicators. All code and calculations has to be local to the addon.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi Chelsea ,


          after going over your answer , I see that I can add dynamically the Data series and execute trades on it with NT7 ? correct

          please check the following example and tell me if I got it right it should work ?


          Using NT7 :



          From Initialize() we can add another Bars Object for example for Symbol microsoft "MSFT like this


          protected override void Initialize()

          {

          // Add an MSFT 1 minute Bars object to the strategy

          Add("MSFT", PeriodType.Minute, 1);

          }



          Then if I want to Execute Orders on the new Instrument ( MSFT ) that I just created I need to do the following :




          protected override void OnBarUpdate()

          {

          if (BarsInProgress == 1)
          {

          // this will enter BUY ORDER on my Data Series on MSFT , just an example

          EnterLongLimit(1 , true, 100 , GetCurrentAsk(), "Long-SIGNAL");

          }

          }




          So my questions :

          1) I got it right this might work ?

          2) can i read from the Strategy C# code a text file ? I want to read a text file that will hold

          Symbols of stocks that will be seperated by comma , then the strategy alone will decide on which stock to execute

          the order , Is it possible ?


          thanks

          Ron

          Comment


            #6
            Hello Ron,

            Yes, adding all of the instrument series with Add(), and placing orders to the BarsInProgressIndex of the added series would place orders to that instrument.

            Below is a link to the reference sample that demonstrates using StreamReader.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hi Chelsea ,

              cool , so I can see for now all can be done using NT7 , i will stay with it for now , it would take me a while until learning how to code my strategy with
              NT8 , I will try it one day

              and about the StreamReader I will check it out , so this can be solutionhow to read from external file the symbol to trade in a strategy ? correct

              Great many thanks ,

              Ron

              Comment


                #8
                Hello Ron,

                Yes the StreamReader is a class used to read from a text file.
                Chelsea B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by rtwave, 04-12-2024, 09:30 AM
                4 responses
                31 views
                0 likes
                Last Post rtwave
                by rtwave
                 
                Started by yertle, Yesterday, 08:38 AM
                7 responses
                29 views
                0 likes
                Last Post yertle
                by yertle
                 
                Started by bmartz, 03-12-2024, 06:12 AM
                2 responses
                22 views
                0 likes
                Last Post bmartz
                by bmartz
                 
                Started by funk10101, Today, 12:02 AM
                0 responses
                7 views
                0 likes
                Last Post funk10101  
                Started by gravdigaz6, Yesterday, 11:40 PM
                1 response
                9 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Working...
                X