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

Coordinating different strategies

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

    Coordinating different strategies

    I've got 3 different strategies doing different things, each with multiple instruments. I'd like them to be able to talk to each other, mainly checking the global profit/loss and checking who else is long/short before executing a particular instrument.

    Now, I understand I can code all three strategies into 1 strategy, but I feel that will be a real mess. What other options do I have? Is there any support in ninjatrader to storing values in the database, which I then can call up? My last option is using Matlab to do that bit, but again it turns a bit messy.

    #2
    >> I'd like them to be able to talk to each other
    Unfortunately this is not supported.

    Comment


      #3
      I think static variables should do the trick. Of course you'd have to take care of the usual concurrency/synchronization issues.

      Comment


        #4
        terenyi,

        I wasn't sure whether using static variables would work... is everything really in the same VM? I've been able to run different versions (not just instances, but different versions) simultaneously of the strategy in a chart, strategy, and analyzer. How would I know which instance of the strategy I'm "talking" to when I access static variables?

        kegrande,

        Lightbulb! It didn't occur to me to add my own database to allow multiple NT instances to communicate to each other. I've just been using static text files... a database would so much more stable!

        Comment


          #5
          @heech:

          I'm not sure what you mean by instances. If you mean separate instances of NT (maybe even on different machines) then of course you'd have to use a different approach (using a database sounds good).

          But if you are just running one instance of NT then all strategy instances within the NT instance share the same static variables. If you want to indentify each strategy instance then you could use a static map which contains an entry for each strategy instance.

          Comment


            #6
            Originally posted by terenyi View Post
            But if you are just running one instance of NT then all strategy instances within the NT instance share the same static variables. If you want to indentify each strategy instance then you could use a static map which contains an entry for each strategy instance.
            Sorry for not using the proper terminology... I'm not really sure what the proper terminology is in the C# world. When I refer to different "instances", I'm actually referring to what in the Java world would be Class objects, loaded by the classloader.

            I'm 99% sure I've been able to run a strategy in a chart, make significant changes to the class, recompile, and then simultaneously run the strategy in a different chart... strategy analyzer, etc. And if that's the case, these two active strategies belong to two different simultaneously loaded classes (that happen to have the same name). I don't know you could correctly change the static variables on them.

            How does that work?

            Comment


              #7
              First of all I wouldn't recommend doing this "multiple versions" thing. I'm sure this will cause trouble at some point. And I also don't know why you would want to do that. If you really need different versions then use different classes (e.g. MyStrategy, MyStrategyV2). You could put shared code in a base class. If you also put the static variables in the shared base class then all strategy "versions" (in reality just different classes) would share the same static variables.

              Comment


                #8
                Originally posted by terenyi View Post
                First of all I wouldn't recommend doing this "multiple versions" thing. I'm sure this will cause trouble at some point. And I also don't know why you would want to do that. If you really need different versions then use different classes (e.g. MyStrategy, MyStrategyV2). You could put shared code in a base class. If you also put the static variables in the shared base class then all strategy "versions" (in reality just different classes) would share the same static variables.
                terenyi,

                I'm not saying that I'm intentionally doing that. I'm just pointing out that it's a fact it's possible, and that's why I'm suspicious you're actually going to see/change the "correct" version of the static class variables, even if you only have a single version of the class loaded.

                Anyways, this is all theoretical talk. Have you tried it? If it works, great, I'll consider integrating it as well.

                Comment


                  #9
                  I think you probably shouldn't get into a situation where an "old version" needs to keep running. It sounds like you are mixing production and development environment. But that is just my humble opinion. You of course know best what you are doing.

                  And I don't know how the behaviour would be in such a case. I guess you'll have to test it.

                  I personally have used static variables successfully for some tasks. For others I'll use a database since the data stored in variables is not persistent.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by iceman2018, Today, 05:07 PM
                  0 responses
                  4 views
                  0 likes
                  Last Post iceman2018  
                  Started by rhyminkevin, Today, 04:58 PM
                  0 responses
                  23 views
                  0 likes
                  Last Post rhyminkevin  
                  Started by lightsun47, Today, 03:51 PM
                  0 responses
                  6 views
                  0 likes
                  Last Post lightsun47  
                  Started by 00nevest, Today, 02:27 PM
                  1 response
                  14 views
                  0 likes
                  Last Post 00nevest  
                  Started by futtrader, 04-21-2024, 01:50 AM
                  4 responses
                  49 views
                  0 likes
                  Last Post futtrader  
                  Working...
                  X