Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

number of shares

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

    number of shares

    I've just started Auto trading using IB. I'm having a problem with the strategy executing the correct number of shares. It seems there are several places this number can be set and I'm probably missing one I need to consider. Longer term I need to code so that the strategy enters a consistant dollar amount of shares like #Shares=5000/Last Price, but for now I don't know C+ so I have to calculate the number by hand each morning when I enter the strategy based on the previous close which will roughly give me what I want. So in the Strategy Wizard I set a User Defined Input called Shares with a default of 10 and a minimum of 1. On the Conditions and Actions page /Parameters /Quantity>User Defined Inputs > selected Shares which shows after exiting as EnterLong(Shares,""). Then when setting up the Strategy before the market I select New Strategy in the Control Center window, set the value of "Shares" under Parameters to my calculated number, adjust other settings as needed and put "Set order quantity" to "by strategy" -- should this give me the desired number of shares or will my entry here be overpowered by something somewhere else? Today I had two trades go at 1 share each rather than the expected number, but I'm not sure I had everything set up as described at that point. Just want to know what will happen on the next signal. Thx.

    #2
    Setting it up like that should be fine.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thanks -- looks like it worked right with a later signal. When I set up in the morning I want to set up the Strategy, have it execute thru IB and record the trades on a chart as well as in the Control Center. My impression is that if I set up in the Control Center I will not have the chart text and markings. If I set up the strategies on the charts so as to get these I won't have to do anything else -- is that right?

      Comment


        #4
        That is right.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          I don't know if this is accurate but it seems to me that if one could use a variable rather than a user defined input to set the number of shares then maybe I could define the variable as say 5000/Last to have my strategy buy $5000 worth of stock. That would give us non-code folks a way to work this -- seemed from the board like there was some interest in this sort of position sizing. Is there a chance this option could be added?

          Comment


            #6
            bkout,

            What you are trying to do is doable via coding. There is no way around it. You make yourself a variable. Store in 5000/Close[0]. Cast this variable into an integer and then use it for quantity when you call your EnterLong().

            Code:
            someVariable = 5000 / Close[0];
            EnterLong((int) someVariable);
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              thanks Josh, I hope that will make sense to me in short order. Would you kindly point me to the best resourse to start learning some basic coding? As of now I have no idea where to put those lines or what "cast" means (same as define???)

              Comment


                #8
                The best place to start is through the tutorials in the Help Guide. Then you can dabble into the Reference Sample section of the forums. As far as C# goes, I would recommend googling some resources or picking up a book.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  position sizing based on dollar amount

                  After weeks of calculating my share numbers for a given dollar position using another program and then entering it by hand I found that this can be done in Ninja without having to do code as this thread said I would have to. See: http://www.ninjatrader-support2.com/...osition+sizing

                  Comment


                    #10
                    Not sure what you mean. If you are trying to auto trade with an account size you need to run calculations. Especially if you want to take into account new available buying power as you acquire more or less PnL.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      Since my systems don't typically trade more than once or twice a day the change from P&L in Account size are not a problem and using this method is much easier than having to go to an extenal sourse to do share size calculations. Now next question -- is there a way to build a certain Account size into a strategy (and have it bring up the Account size methodology by default) rather than have to set it each time the strategy is re-started? Again I know all this could be done by code but since I don't know the code I'm looking for the easiest workaround.

                      Comment


                        #12
                        bkout,

                        Unfortunately it would require code. To set the account size you need to add this line in your Initialize() method:
                        Code:
                        AccountSize = 5000;
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          Checking on something. If I managed to have some kind soul tell me where and how to drop that account size line into the strategy code, is it correct that from that point on I could only make any changes by code changes and would not be able to use the wizard? BTW for the "wish list" -- I often want to do another version of a strategy with just a minor change. Rather than have to do a lot of cutting and pasting in creating a new strategy it would be great to be able to create an instant clone of the Strategy (say "Strategy1") and then go edit it.

                          Comment


                            #14
                            bkout,

                            Making any code changes would require you to unlock the code and that means being out of the Wizard.

                            If you want to make a copy of a strategy do this:
                            1. Open the original in the Wizard.
                            2. Press View Code
                            3. Right click -> Save As -> type in a new name
                            4. Close NinjaScript Editor
                            5. Open the new file in the Wizard
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #15
                              That's great thanks Josh! Just to be clear on the other question -- once the code is changed and saved. Then in the future can I go back into the strategy with the wizard or no?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by ScottW, Today, 06:09 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post ScottW
                              by ScottW
                               
                              Started by Board game geek, 10-29-2023, 12:00 PM
                              14 responses
                              244 views
                              0 likes
                              Last Post DJ888
                              by DJ888
                               
                              Started by Waxavi, 04-19-2024, 02:10 AM
                              4 responses
                              56 views
                              0 likes
                              Last Post sonia0101  
                              Started by cmtjoancolmenero, Today, 03:58 PM
                              0 responses
                              9 views
                              0 likes
                              Last Post cmtjoancolmenero  
                              Started by Segwin, 05-07-2018, 02:15 PM
                              11 responses
                              1,778 views
                              0 likes
                              Last Post aligator  
                              Working...
                              X