• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy running against a basket of stocks

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

    Strategy running against a basket of stocks

    Hi NT Team,
    I wonder if you could give me a little direction on where to start my search. I designed a strategy in Ninjascript which is scanning a basket of stocks for certain criterias to enter. Every time a setup is found i want the strategy to enter a trade but only with a fraction of the account size. Let say I have a 25k account and I want the max position per symbol to not be bigger than 5k and then keep monitoring the basket for another opportunity... ideally having 5 different 5k positions/symbols out of a basket of stock (i predefined before). Can this be accomplished? If yes how? Any advice would be appreciated.
    Thanks

    #2
    Hello JBU1314,

    Thank you for your note.

    Yes, this would be possible. Towards the bottom of the link below, you'll see an example of getting a cash value of the account,
    http://ninjatrader.com/support/helpG...ount_class.htm

    I have put together a sample strategy which when applied will save the value of the SIM101 account to a variable, divide that variable by 5 (20%), divide the closing price of the stock the strategy is applied to, round down, then print the amount of shares which would be 1/5th of your account size. You could then pass sharesToBuy to your EnterLong() method for example, for what you are looking to do. I wrote this I wrote this with equities in mind.

    To Import a NinjaScript into NinjaTrader 8 do the following:
    From the Control Center window select Tools -> Import-> NinjaScript...
    Find the file location.

    Please let us know if you need further assistance.
    Attached Files
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Thank you very much!

      Comment


        #4
        Hi Alan, I would have a follow up to that threat. I implemented that into my strategy and modified it a litte bid to fit my futures strategies.
        My goal is to increase position size with increasing Account Value based on respective margin requirements. The formula below seems to make sense and seems to work but can i backtest that? The system always works with the base 100k from the Sim101 account. I would like to say start with a 25K account and see how far it goes over time and how many positions will be opened?

        lock (Account.All)
        account = Account.All.FirstOrDefault(a => a.Name == "Sim101");

        xAccountSize= Account.Get(AccountItem.CashValue, Currency.UsDollar);
        int sharesToBuy= (int)Math.Floor((xAccountSize/MarginRequirement));

        base.EnterLong(sharesToBuy,"B"+CurrentBar);

        Comment


          #5
          Hello JBU1314,

          Because you can’t call historical account values, you would need to modify the code for it to work within the strategy analyzer/backtest. What you can do is set a starting account value variable and have it adjusted plus or minus for each winning trade.

          I have modified the initial strategy I provided, which will allow you to set the initial account size variable and run a backtest in the strategy analyzer.

          I applied the strategy on AMZN daily series from 1997 through today, and you can see how the shares traded is adjusted as account equity grows.

          Please let us know if you need further assistance.
          Attached Files
          Alan P.NinjaTrader Customer Service

          Comment


            #6
            Thank you very much Alan, very much appreciated!

            Comment


              #7
              Hi Alan, the file works great with Stocks but it seems I am not able to make it work with Futures (ES, NQ). Any advice?

              Comment


                #8
                Hello JBU1314,

                Correct, I used the closing stock price divided by (Account Size *.2), to give you how many shares to buy. You would have to account for margin with futures.

                I have provided a sample strategy which checks if your account size is greater than the instruments initial margin requirement, which you could modify to provide you with the number of contracts you could buy.

                Please let us know if you need further assistance.
                Attached Files
                Alan P.NinjaTrader Customer Service

                Comment


                  #9
                  Thank you for the prompt response Alan! As usual highly appreciated.
                  This approach does only work in live markets now right?

                  Comment


                    #10
                    Hello JBU1314,

                    That is correct, the sample would only work in a live environment as you can’t call historical account values in a backtest. You would have to use the concept in the previous sample to modify the code to use a starting account value if you wanted to use it in a backtest. Also, similar to how you can’t call historical account values, you would not be able to call historical contract margin values, thus you would be assuming these never changed in the backtesting period. This may or may not have been the case.

                    Please let us know if you need further assistance.
                    Alan P.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by D Trader, Yesterday, 09:43 AM
                    1 response
                    8 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by cassiano_sanches, 07-10-2020, 07:37 PM
                    1 response
                    14 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by terminatorT1000, 07-10-2020, 06:40 PM
                    2 responses
                    31 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by Giudiver, 07-10-2020, 04:29 PM
                    2 responses
                    16 views
                    0 likes
                    Last Post Giudiver  
                    Started by rtwave, Today, 04:11 PM
                    0 responses
                    4 views
                    0 likes
                    Last Post rtwave
                    by rtwave
                     
                    Working...
                    X