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

Gloabal Variables?

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

    #16
    Well yes, the TS zip comes with the source code and all in C++...but, how do we convert it to C#?

    Comment


      #17
      This WORKS:

      [DllImport("GlobalVariable.dll")]
      public static extern int GV_SetInteger(int iLocation, int iVal);

      [DllImport("GlobalVariable.dll")]
      public static extern int GV_GetInteger( int iLocation) ;

      int GV1 = GV_SetInteger(1, 33);
      int GV2 = GV_GetInteger(1);

      Comment


        #18
        Could you show a bit more?

        mktrend,

        I am trying to understand how to use the code snipet you showed.
        For example, on these two lines of code:
        [DllImport("GlobalVariable.dll")]
        public static extern int GV_SetInteger(int iLocation, int iVal);

        Is that the EXACT syntax?
        Do they go before the Using Declarations?
        Do they go after the brace of the 'namespace NinjaTrader.Indicator' statement?
        I have tried several combinations and keep getting compiler errors.

        I assume the GlobalVariables.dll should go in:
        C:\Program Files\NinjaTrader 6.5\bin right?

        I appreciate any direction you can provide. Perhaps a link that I can refer to?


        Thanks,
        Gary

        Comment


          #19
          Originally posted by GaryAlbers View Post
          mktrend,

          I am trying to understand how to use the code snipet you showed.
          For example, on these two lines of code:
          [DllImport("GlobalVariable.dll")]
          public static extern int GV_SetInteger(int iLocation, int iVal);

          Is that the EXACT syntax?
          Do they go before the Using Declarations?
          Do they go after the brace of the 'namespace NinjaTrader.Indicator' statement?
          I have tried several combinations and keep getting compiler errors.

          I assume the GlobalVariables.dll should go in:
          C:\Program Files\NinjaTrader 6.5\bin right?

          I appreciate any direction you can provide. Perhaps a link that I can refer to?


          Thanks,
          Gary
          make sure dll in bin or wherever but both apps address the same path...

          Comment


            #20
            Can somebody please provide a download link for GlobalVariable.dll?
            Please don't post the TS link, I have no access to the TS forum!

            Thank you

            Comment


              #21
              Originally posted by GATT1 View Post
              Can somebody please provide a download link for GlobalVariable.dll?
              Please don't post the TS link, I have no access to the TS forum!

              Thank you
              I just found this thread working on an algorithm to have multiple strategies coordinate to best use my trading capital. You can read the details of that discussion here: http://www.ninjatrader-support2.com/...ad.php?t=12252

              I found the GV file that people are looking for here and I'm attaching it to this message.

              I will try it out and report back. It may take me a few days, I have a lot of work this week.

              Thank you to everyone in this thread for sharing this idea and for posting the code examples. It's very helpful to me.
              Attached Files

              Comment


                #22
                Originally posted by cunparis View Post
                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.
                Yep, you're on the right track! Just have each strategy entering a position to set a Global Variable to 1 and after exiting it to reset it back to 0 and all strategies to check the condition of the flag first and if it's a 1 it means the account is not available...etc.

                A bit more sophisticated approach would be to make a custom event as in any strategy entering and exiting a trade would inform the others about it by raising a custom event.
                I had a thread on this a few days ago!

                here:
                Last edited by mktrend; 01-13-2009, 06:55 AM.

                Comment


                  #23
                  Thanks for posting this info guys!
                  BertrandNinjaTrader Customer Service

                  Comment


                    #24
                    Originally posted by mktrend View Post
                    This WORKS:

                    [DllImport("GlobalVariable.dll")]
                    public static extern int GV_SetInteger(int iLocation, int iVal);

                    [DllImport("GlobalVariable.dll")]
                    public static extern int GV_GetInteger( int iLocation) ;

                    int GV1 = GV_SetInteger(1, 33);
                    int GV2 = GV_GetInteger(1);
                    Utilizing the snippet above or any of the many other functions available in the GV.dll you can send any data or even streams from one ind. strat, to others quite easily. Post if need more help. Make sure the same copy of the dll is referred to and no other copies of the same dll exist in your system files etc.

                    Comment


                      #25
                      Hi,

                      Did using this DLL actually work out for you guys? Do you think it would be appropriate/effective for storing an "available balance" variable across multiple live executing strategies?

                      Thanks,
                      Brandon

                      Comment


                        #26
                        Originally posted by bridenour View Post
                        Hi,

                        Did using this DLL actually work out for you guys? Do you think it would be appropriate/effective for storing an "available balance" variable across multiple live executing strategies?

                        Thanks,
                        Brandon
                        I don't think it's necessary. A static variable seems to do the same thing.

                        This GV is to communicate between different applications, not to communicate inside the same application when other methods (static variable) are possible.

                        Comment


                          #27
                          cunparis,

                          i thought you had said you tried with a static variable but were not successful? thanks for the input!

                          br

                          Comment


                            #28
                            Originally posted by bridenour View Post
                            cunparis,

                            i thought you had said you tried with a static variable but were not successful? thanks for the input!

                            br
                            I was not successful but it had nothing to do with the choice of static variable for GV. The reason I didn't succeed is because when you have several strategies accessing the same value there are timing issues. If you make a lock you have to synchronize the methods so that two strategies don't try to modify the lock at the same time. I eventually gave up because I determined that it's better to do my position sizing differently where I allocate a % of capital to each strategy.

                            It didn't take long to program but testing it took a long time. So my advice is re-examine your need for this and avoid it if possible. If you just want to communicate a msg between two strategies it's easy. but if you want to use some kind of lock where one strategy gets the lock and another strategy waits for it, then this is where it gets hard..

                            Comment


                              #29
                              I just want to share an available balance among strategies. I have several distinct systems that trade reasonably infrequently, and to efficiently use my available funds I need it to be available cross strategy.

                              Unlike yours, mine is not all of none, so I need to recalculate and update the "available balance" each time an entry or exit occurs.

                              The odds of entries and exits happening simultaneously is rather low, so I think I might just give the static a shot and see how it plays out. Worst case it will try to open too many positions and likely get rejected due to margin limits.

                              Thanks for your feedback!

                              Comment


                                #30
                                Originally posted by bridenour View Post
                                I just want to share an available balance among strategies. I have several distinct systems that trade reasonably infrequently, and to efficiently use my available funds I need it to be available cross strategy.

                                Unlike yours, mine is not all of none, so I need to recalculate and update the "available balance" each time an entry or exit occurs.

                                The odds of entries and exits happening simultaneously is rather low, so I think I might just give the static a shot and see how it plays out. Worst case it will try to open too many positions and likely get rejected due to margin limits.

                                Thanks for your feedback!
                                Unless you're trading a very small account size, you will probably find with position sizing and a 2% risk that it's impossible to use all of your money. In this case you may not need to share the account balance.

                                If you are trading a small account size then you could re-examine the % risk you're taking.

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by jclose, Today, 09:37 PM
                                0 responses
                                5 views
                                0 likes
                                Last Post jclose
                                by jclose
                                 
                                Started by WeyldFalcon, 08-07-2020, 06:13 AM
                                10 responses
                                1,414 views
                                0 likes
                                Last Post Traderontheroad  
                                Started by firefoxforum12, Today, 08:53 PM
                                0 responses
                                11 views
                                0 likes
                                Last Post firefoxforum12  
                                Started by stafe, Today, 08:34 PM
                                0 responses
                                11 views
                                0 likes
                                Last Post stafe
                                by stafe
                                 
                                Started by sastrades, 01-31-2024, 10:19 PM
                                11 responses
                                169 views
                                0 likes
                                Last Post NinjaTrader_Manfred  
                                Working...
                                X