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

Communication between two strategies

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

    Communication between two strategies

    What is the easiest/most efficient way to share a value between two strategies on the SAME chart? Can I share a global value? I saw the post about using this on different charts but wasn't sure if it was true for the same chart as well.

    I wasn't sure what was supported under the Ninja Trader implementation and thought I would ask before I beat my head against a rock.

    Thanks/danke

    Cliff
    Last edited by ct; 11-26-2007, 01:04 AM.

    #2
    Unfortunately this is beyond of what we support. However, you might see value in trying the concept of "static" in C#.

    Comment


      #3
      Dierk

      Guten morgan. Thanks for the fast reply.

      ok, I will give it a try. I wasn't sure if "not supported" was "doesn't work" or is just unsupported. Sounds like it may be ok.

      Thanks/danke

      Cliff

      Comment


        #4
        Dierk

        Here is what I received from my technical expert.

        "There is no way to add global variable,
        instead a very simple custom indicator with one property can be developed, which can be set and retrieved from any other indicator or strategy."

        Does it look like this will work to you?

        Comment


          #5
          Statement is incorrect: Since NinjaScript is C# you can add any global/static variable you like by custom coding.

          But again: this is beyond of what we support. Please contact a NinjaScript consultant if you need further support on that matter. http://www.ninjatrader.com/webnew/pa...injaScript.htm

          Comment


            #6
            Dierk

            OK, thanks for the help.

            Cliff

            Comment


              #7
              it´s very easy ct! you create in region vars in [Estrategy1] a var with "public static ....." example:

              #region Variables

              public static bool MessengerInterStrategicVar = false ;

              #endregion


              Now, you call, write or change your var in [Strategy2].

              Example:

              (Put the name of class or strategy1 after var name)

              Strategy1.MessengerInterStrategicVar = true ;

              test with debug print!

              Print (" Var from remote strategy status:" + Strategy1.MessengerInterStrategicVar.ToString());

              woalaa! It can work! I think soo!
              remember to load both strategys in your chart!

              Comment


                #8
                Agamenon

                Kewl. I will give that a try. Many thanks!!!

                Comment


                  #9
                  Agamenon

                  It worked perfect. You are a sheer genius!

                  Comment


                    #10
                    This apparently only works with strategies?

                    I tried the technique on two indicators...the "remote" indicator does not compile since it contains a reference to a variable that's defined in the "primary" indicator.

                    Any way around this? Do I need to define it as a "public static" variable in the "remote" indicator?

                    Comment


                      #11
                      I have not tried this myself, but you could try defining it in UserDefinedMethods, which is a partial base class all of your indicators use.

                      Dierk -- if you're still following this discussion, is OnBarUpdate always called from the same thread or would this code need to be made threadsafe? I've wondered about that for my own uses. From watching the output it looks like the strategies are called one after the other.

                      Comment


                        #12
                        I did no follow this thread in detail but all strategy event methods are executed in the same thread.

                        Comment


                          #13
                          PeteS,
                          I tried this out , and it seemed to work. Here is a code snippet:
                          partial class Indicator
                          {
                          double wrkVal = 0;
                          public double testMethod()
                          {
                          wrkVal = wrkVal + 1.0;
                          return wrkVal;
                          }
                          }


                          With this I can finally access wrkVar from other indicators.

                          bormir

                          Comment


                            #14
                            Bormir, where did you place this?

                            In userdefinedmethods?
                            Last edited by zoltran; 12-20-2007, 09:22 PM.

                            Comment


                              #15
                              zoltran,
                              I made a copy of UserDefinedMethods and named it TestUserMethods. I have attached the whole test file for you to look at. It is interesting. It looks like you can access wrkVar directly from any indicator
                              Attached Files

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Vietanhnguyen2hotmailcom, Yesterday, 10:29 AM
                              4 responses
                              23 views
                              0 likes
                              Last Post Vietanhnguyen2hotmailcom  
                              Started by PhillT, 04-19-2024, 02:16 PM
                              4 responses
                              35 views
                              0 likes
                              Last Post PhillT
                              by PhillT
                               
                              Started by ageeholdings, 05-01-2024, 05:22 AM
                              5 responses
                              37 views
                              0 likes
                              Last Post ageeholdings  
                              Started by reynoldsn, Today, 02:34 PM
                              0 responses
                              13 views
                              0 likes
                              Last Post reynoldsn  
                              Started by nightstalker, Today, 02:05 PM
                              0 responses
                              21 views
                              0 likes
                              Last Post nightstalker  
                              Working...
                              X