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

Backtetsing multiple instruments in Ninjascript

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

    Backtetsing multiple instruments in Ninjascript

    Hello,

    I am trying to backtest strategy on EOD data on 100s of stock. The strategy should select 4 stocks from the list with the lowest RSI indicator, i.e. scan all stocks in the lists and then buy only 4 stocks with the lowest RSI.

    My struggle is that the strategy analyzer goes instrument by isntrument. Takes first instrument and runs it through the script through whole time frame then moving to another instrument. This way I cannot select those with lowest RSI on that particular day as the strategy analyzer takes only one instrument on that day before moving to the next day. I would rather need to go day by day. Take all instruments on the first day, select instruments with lowest RSI then move to the next day.

    Would you have an example of a similar script? I searched the forum with no success.

    Thank you
    Michal

    #2
    Hi Michal, thanks for writing in.

    You would need to write the RSI value to a .txt file for other instances of the backtests to see the value. We have an example here showing how to read and write to a txt file:

    https://ninjatrader.com/support/help..._propertie.htm

    Best regards,
    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hi ChrisL, thanks for your hint.

      I would be able to read RSI values from the file. But the strategy is a bit more complicated. My intentions is to buy max. 4 stocks with RSI<10. Let's assume on Day 1 there are 3 stocks which satisfy the criteria. On Day 2 there are 6 more stocks which meets the criteria. But only 1 stock with the lowest RSI should be bought (since 3 stocks are already held from Day 1) .

      1) How do write in script a check which tells how many stocks are held from previous day?

      2) Assume that RSI is <10 for stock A on Day 1 and the stock is bought. On Day 2 RSI is again <10 for stock A but since the stock was already bought the previous day, backtest should ignore a buying signal (and instead buy a different stock which has RSI<10).

      Thanks
      Michal

      Comment


        #4
        Hello, thanks for your reply.

        1. You can read the Positions or PositionsAccount object to get the position information for the strategy itself, or from the Account. If you override OnExecutionUpdate you can also track each execution going through the strategy.

        2. An alternative approach would be to have one strategy that adds the other instruments with AddDataSeries() since each instrument is involved with the trade. This would be more straightforward than inter-strategy communication. See this guide on multi-instrument scripts:
        https://ninjatrader.com/support/help...nstruments.htm

        Best regards,
        -ChrisL
        Chris L.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Jonafare, 12-06-2012, 03:48 PM
        5 responses
        3,986 views
        0 likes
        Last Post rene69851  
        Started by Fitspressorest, Today, 01:38 PM
        0 responses
        2 views
        0 likes
        Last Post Fitspressorest  
        Started by Jonker, Today, 01:19 PM
        0 responses
        2 views
        0 likes
        Last Post Jonker
        by Jonker
         
        Started by futtrader, Today, 01:16 PM
        0 responses
        8 views
        0 likes
        Last Post futtrader  
        Started by Segwin, 05-07-2018, 02:15 PM
        14 responses
        1,792 views
        0 likes
        Last Post aligator  
        Working...
        X