Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Is it possible to limit total position size for all strategies?

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

    Is it possible to limit total position size for all strategies?

    I see the help for AccountSize:

    Code:
        protected override  void Initialize()  
    { 
        AccountSize =  10000; 
    }
    I'm wondering if I have a strategy running on 2 different instruments, can I configure it so that it will only buy 1 contract at a time for all strategies? For example, if I have $10k account and I'm trying futures, I will only be able to buy 1 contract at a time. I'm not sure how to configure this.

    #2
    Hi cunparis,

    Accessing your brokerage account values is not supported in the current 6.5 release, however we will add it in our upcoming NinjaTrader 7 release.

    Also - it is not possible to push the current strategy position over to another strategy, therefore both cannot 'talk' to each other...

    If you only want to trade for example one contract per signal, you could explicitly code this in with -

    Code:
    EnterLong(1)
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Bertrand,

      I guess this is another feature request for NT7... but something like GetStrategies(), which returns a set of all currently (started) strategies would be very helpful.

      We should then be able to cast the objects in the strategy to the native class type, and then make calls back and forth.

      Comment


        #4
        Thanks for the input heech, I will make sure it is forwarded to our development team!
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Bertrand View Post
          Hi cunparis,

          Accessing your brokerage account values is not supported in the current 6.5 release, however we will add it in our upcoming NinjaTrader 7 release.

          Also - it is not possible to push the current strategy position over to another strategy, therefore both cannot 'talk' to each other...

          If you only want to trade for example one contract per signal, you could explicitly code this in with -

          Code:
          EnterLong(1)
          The problem is once a strategy enters a long position, I don't want the other strategies to enter any positions. My account size won't allow it. I can't figure out how to do this.

          The solution of just trading one strategy doesn't work for me because I don't get many trades so I like to trade ES & NQ so that I get more trades.

          Comment


            #6
            Hi cunparis,

            Then I would suggest coding it into a MultiInstrument strategy, so you have one strategy and have the option to add 2 different entry signals and go from there...

            Please see this link - http://www.ninjatrader-support.com/H...struments.html
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Another possibility.. use C# to read/write a file on the local hard-drive. Look into C# file handling examples (widely available online... just google). Your two strategies can coordinate that way.

              Comment


                #8
                Originally posted by NinjaTrader_Bertrand View Post
                Hi cunparis,

                Then I would suggest coding it into a MultiInstrument strategy, so you have one strategy and have the option to add 2 different entry signals and go from there...

                Please see this link - http://www.ninjatrader-support.com/H...struments.html
                This would make it really complicated because each strategy has its own conf, and each strategy runs on several timeframes. So making it into one big strategy would make it hard to backtest.

                All that is really 1 strategy that I run multi-instrument. I have another strategy that I'm working on, so as you can see once one has several different strategies that are each multi-instrument and multi-timeframe it'd be really complicated to combine them all into one big strategy.

                Heech - I thought of this, but there could be race conditions if two strategies tried to go long at the same time. Worst case I'd end up with 2 contracts OR the broker would refuse the 2nd order due to insufficient margin. This seems more elegant than the monolithic strategy suggestion. I will look into this. I suppose the real way to do it would be using a database and transactions. That's way beyond my C# knowledge.

                Comment


                  #9
                  cunparis,

                  We cannot offer you any other solutions at this point in time. Sometimes you just have to buck down and code it out if that is the behavior you want.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NinjaTrader_Josh View Post
                    cunparis,

                    We cannot offer you any other solutions at this point in time. Sometimes you just have to buck down and code it out if that is the behavior you want.
                    That's fine, you do quite a lot as it is.

                    Maybe with NT 7 being able to get the account balance that would solve the problem. Hopefully.

                    I think I'll code heech's idea of writing to a file. Seems simple enough.

                    Comment


                      #11
                      Originally posted by cunparis View Post
                      I suppose the real way to do it would be using a database and transactions. That's way beyond my C# knowledge.
                      Yep, as I mentioned in a different thread, I just had an epiphany and decided that's the behavior I need.

                      FWIW, working with a simple database like MySQL is pretty trivial. And if nothing else, engineers who can code up a simple+reliable query/insert system for you should be a dime a dozen. I'll probably code it myself, but if you want help with something like this, look into something like rentacoder... many C# programmers in the developing world who'll work for cheap. ($100-$250 for what you want?)

                      Comment


                        #12
                        Originally posted by heech View Post
                        Yep, as I mentioned in a different thread, I just had an epiphany and decided that's the behavior I need.

                        FWIW, working with a simple database like MySQL is pretty trivial. And if nothing else, engineers who can code up a simple+reliable query/insert system for you should be a dime a dozen. I'll probably code it myself, but if you want help with something like this, look into something like rentacoder... many C# programmers in the developing world who'll work for cheap. ($100-$250 for what you want?)
                        I'm a Java developer but so far I've been able to figure everything out in C# all by myself. Well myself and google. So hitting MySQL in Java or PHP is quite easy, but C# I'd have to learn the APIs. The equivalent of JDBC for Java. I'll look into and if it's not much more effort than writing to a file then I can try that. I think it'd be cleaner than a file, and it'd be transactional.

                        Thanks for sharing your ideas. You seem to be a bit further along than I am. I'm going to look for your other threads.

                        Comment


                          #13
                          Originally posted by cunparis View Post
                          I'm a Java developer but so far I've been able to figure everything out in C# all by myself. Well myself and google. So hitting MySQL in Java or PHP is quite easy, but C# I'd have to learn the APIs. The equivalent of JDBC for Java. I'll look into and if it's not much more effort than writing to a file then I can try that. I think it'd be cleaner than a file, and it'd be transactional.

                          Thanks for sharing your ideas. You seem to be a bit further along than I am. I'm going to look for your other threads.
                          As it happens, I'm a Java guy too. My experience with C# is limited to this + another trading platform, about 2 months worth. The learning curve hasn't been bad, Microsoft did a good job.

                          I'm actually not that comfortable in raw JDBC, having always used a framework (Hibernate) in my past professional life. I'm thinking about using a framework in C# too... let's trade notes, if you find anything useful.

                          Comment


                            #14
                            Originally posted by heech View Post
                            Another possibility.. use C# to read/write a file on the local hard-drive. Look into C# file handling examples (widely available online... just google). Your two strategies can coordinate that way.
                            Exactly, this is what I do with all my strategies now so they can talk to each other.

                            Not perfect code but quick example:


                            string dailylimitlogfile = @"c:\windows\temp\ninja\dailylimit (" + Time[0].Month + "-" + Time[0].Day + "-" + Time[0].Year + ").txt";
                            string longpositionlogfile = @"c:\windows\temp\ninja\position_es_long (" + Time[0].Month + "-" + Time[0].Day + "-" + Time[0].Year + ").txt";
                            string shortpositionlogfile = @"c:\windows\temp\ninja\position_es_short (" + Time[0].Month + "-" + Time[0].Day + "-" + Time[0].Year + ").txt";

                            -------------------------

                            // create file to indicate daily limit reached

                            TextWriter dailylimitlog = new StreamWriter(dailylimitlogfile);
                            dailylimitlog.WriteLine(DateTime.Now + " - Daily limit reached");
                            dailylimitlog.Close();

                            --------------------------

                            // when flat
                            // delete position file
                            if (File.Exists(longpositionlogfile)) File.Delete(longpositionlogfile);

                            ---------------------------

                            // when about to enter new position
                            if (File.Exists(shortpositionlogfile)) { Print (logprefix + "In a short position it seems, doing nothing."); return; }

                            if (File.Exists(dailylimitlogfile)) { Print (logprefix + "Daily limit reached on another strategy it seems, doing nothing."); return; }

                            ---------------------------

                            // when entered position
                            // create file to indicate in long position for es

                            TextWriter position = new StreamWriter(longpositionlogfile);
                            position.WriteLine(DateTime.Now + " - In long position");
                            position.Close();

                            Comment


                              #15
                              Originally posted by ctrlbrk View Post
                              Exactly, this is what I do with all my strategies now so they can talk to each other.

                              Not perfect code but quick example:
                              Thank you for posting your code. I was thinking last night while in the shower: Can't I just use a static variable to hold this information? Do I really need to use files? I can make a class full of static members to hold the information that needs to be shared. Since it's static, it's available to all the strategies.

                              The question is each strategy run in the same "JVM" (not sure what the C# equivalent is), or is each one totally separate (with its own copy of the static variables)? If they're separate then the file approach is the next choice.

                              heech - I love Hibernate and the ORM idea in general. But in this case if I only had 1 table I'd just use JDBC to keep it simple. I imagine .NET has something similar to JDBC for simplicity.

                              I have to do a test for the static idea and if it doesn't work then my next goal is the file and eventually database.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by kempotrader, Today, 08:56 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post kempotrader  
                              Started by kempotrader, Today, 08:54 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post kempotrader  
                              Started by mmenigma, Today, 08:54 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post mmenigma  
                              Started by halgo_boulder, Today, 08:44 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post halgo_boulder  
                              Started by drewski1980, Today, 08:24 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post drewski1980  
                              Working...
                              X