Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Buy the strongest stock

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

    Buy the strongest stock

    Hi,

    I would like to ask for help in developing NinjaScript code for the following (automated) trading strategy.



    1. my universe contains 7 different stocks

    2. EOD screening these 7 stocks
    3. determine the stock with the highest RSI(14) value
    4. buying/holding the stock with the highest RSI(14) and selling a possible position in one of the other 6 stocks

    I have been searching the forum, but could not find anything like this.

    Please tell me, did someone before me developed this kind of code in NinjaScript?

    Thanks!
    Aad

    #2
    Hello Aad,

    Welcome to the NinjaTrader Support Forums!

    I do not believe anyone has done this exact approach but there are others that are going to be very similar to this, in programming at least.

    We actually have a sample strategy that comes inside of NinjaTrader that can help you get started on your strategy that you want to create. It is called the "SampleMultiInstrument" strategy that you may view by going to Tools -> Edit NinjaScript -> Strategies.

    In this sample it is going to be adding the "MSFT" Microsoft 1 Minute series to the script and getting the ADX of both the Instrument that the strategy is set to and the MSFT 1 Minute series.

    You may modify this to add your instruments that you are looking for and use the RSI instead of the ADX for your conditions is all.

    We also have a Help Guide article that goes over this in more detail at the following link that you may view.


    Let us know if you have any further questions.
    JCNinjaTrader Customer Service

    Comment


      #3
      Buy the strongest stock

      I was trying the following, but this doesn't seem to work?
      Could you please point me in the right direction?

      Purpose:
      1. three instruments of three different asset classes:
      SPY (SP500 ETF), RJI (commodities ETF), BTTRX (bonds fund ETF)

      2. On a daily basis calculate the ratio of RSI(SPY/RJI,14 days), RSI(SPY/BTTRX, 14 days), RSI(RJI/BTTRX, 14 days) and determine the stongest instrument, so the strongest asset class.

      3. Then take a long position is the strongest instrument.

      4. Sell any other position that was taken in a earlier stage by this strategy.

      primary instrument is SP500 daily

      protected override void Initialize()
      {

      Add("BTTRX", PeriodType.Day, 1);
      Add("RJI", PeriodType.Day, 1);

      EntriesPerDirection = 1;
      EntryHandling = EntryHandling.UniqueEntries;



      Add(RSI(Close/BarsArray[1], 14, 0));

      CalculateOnBarClose = true;
      }

      Thanks.
      Aad

      Comment


        #4
        Hello Aad,

        This does not work because you cannot pass in two series at the same time. You may want to create a separate DataSeries object and calculate the ratio for each pair and then pass that DataSeries object to the RSI.

        You may view our Help Guide at the following link for an example on how to declare a DataSeries object and setting the values.
        JCNinjaTrader Customer Service

        Comment


          #5
          Thanks, JC.
          Because I am not a programmer I hope I can understand who to do this.

          The online help is great.
          Does NinjaTrader offer a downloadable pdf, to be able to print this completely, so I can have this on paper?

          Thanks again.

          Have a nice day,
          Aad

          Comment


            #6
            Hello Aad,

            Yes, you can download our Help Guide in a PDF format at the following link.


            Just a note, that it is over 1000+ pages so typically we do not recommend printing it out but you are more than welcome to if you like, it will just take up a lot of resources is all. The PDF version you can view offline at anytime.
            JCNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            627 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            359 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            105 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            562 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            567 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X