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

    #46
    mkmtrend do you some example code that uses this ?

    Comment


      #47
      Hey everyone,

      There seems to be a lot of good programmers following this thread so I thought I would ask a somewhat related question that no one has answered in another thread:

      What is the best way, and is it possible, to pass data from one class to another in NT. My situation: Create a form when a strategy starts that runs asynchronously, but that displays data from the strategy.

      I have working code in a simple c# application, but when I port it over to NT, I get a object reference null error - as if the class had no been instantiated. I am not sure how NT works under the hood and therefore I can't really debug. I am just wondering if anyone else has experience in doing what I want to do - maybe there is a simpler way to pass data (without falling back on global variables...)

      Here is the link to my other post:


      Feel free to answer in the other post.

      Thanks in advance!

      Comment


        #48
        Well, I need a little Help with this:

        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);
        I allways get an Error ' There is no Definition for Length.' That Error occurs in the Ninjacript generated code. especialy by checking the Variables for the class 'GlobalVariables'. I did not undstand, why the DllImport shall be in an own class (I read this in an other thread for NT7). But everytime when i put the DllImport in in the class GVSendDouble : Indicator, I get other Errors....


        Code:
        #region Using declarations
        ...
        using System.Runtime.InteropServices;
        ...
        #endregion
        
        
        namespace NinjaTrader.Indicator
        {
            /// <summary>
            /// Testindicator for sending double values to GlobalVariable.dll
            /// </summary>
        	
        	public class GlobalVariables
        	{
        		#region ImportDLLFunctions
        		[DllImport("C:/Programme/NinjaTrader 6.5/bin/GlobalVariable.dll")] 
        		public static extern int GVSetDouble(int iLocation, double iValue);
        		#endregion
        	}
        	
            public class GVSendDouble : Indicator
            {
                #region Variables
                ...
                // User defined variables (add any user defined variables below)
        			public int GV = 0;
                #endregion
        
               
                protected override void Initialize()
                {
                    Add(new Plot(Color.FromKnownColor(KnownColor.ActiveCaption), PlotStyle.Line, "Plot0"));
                    Add(new Line(Color.FromKnownColor(KnownColor.GrayText), 20, "Border"));
                    CalculateOnBarClose	= true;
                    Overlay				= false;
                    PriceTypeSupported	= false;
        			
                }
        
              
                protected override void OnBarUpdate()
                {
                   
                    Plot0.Set(ADX(length));
        	    GV = GVSetDouble(Location, ADX(length));
                }
        
                #region Properties
                ....
                #endregion
            	}
        }
        #region NinjaScript generated code. Neither change nor remove.
        ....
        #endregion
        please help....

        Comment


          #49
          I don't see you have length defined in any way, neither variables nor properties...
          BertrandNinjaTrader Customer Service

          Comment


            #50
            Oh, they are defined as inputs. I deleted them in the code, to make it smaller.

            -Without the seperate class and without the DLLImport everything is fine - exept the functioncall of the dll.

            -I first put he DllImport into the class GVSendDouble. Then I always get Errors...

            -Then I Found a Thread from NT7 whre the DllImport was put in a seperate class. I do this also. After that, I got the described Errors. The Definition of Length is there - in the class GVSendDouble. But the NinjaScript generated code just check for Variable in the class GlobalVariables and NOT in GVSendDouble...

            If I now delete the class GlobalVariables, I get Errors of unknown namespace in Ninjascript generated code. How do I remove this class. Is it raly nessesairy?

            Comment


              #51
              Ok. I delete the whole Indicator and rewrite it new. I put the DllImport in the class GVSendDouble - and now I can compil the indicator without errors... Seems, that the Editor cause the problems....

              Comment


                #52
                I am new to programming. How exactly would I implement this code below?

                =========

                Originally Posted by mktrend
                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


                  #53
                  kingohen, can you please clarify? I am not sure what most of that code you posted is.
                  AustinNinjaTrader Customer Service

                  Comment


                    #54
                    Sample

                    Hello Kinoghen,

                    here is a little sample for you: A Multicolored SMA. One sends the Values to GlobalVariable.dll and one get the values.
                    this sample is written for NT7 and don't work in NT6.5 (NT6 don't know PlotsColor).

                    GlobalVarable should be in the folder Ninja Trader 7/bin/Custom in your own Files folder.
                    Attached Files

                    Comment


                      #55
                      I'm trying to follow the sample code and am having problems. Much of it is working but I'm not understanding the values passed.


                      In the sender chart, the line of code is:

                      "StoreInDll = GV_SetNamedDouble(VarName + "SMA", MovAvg[0]);"

                      and the sent value stored in the GV is: "MovAvg[0]"

                      In the receiver chart, the line of code is:

                      "MovAvg.Set(GV_GetNamedDouble(VarName + "SMA", Close[0] - 10));"

                      What is confusing me is that the sent MovAvg[0] is not equal to the received Close[0] - 10.

                      What I would have thought to happen is the Sender would send "MovAvg'0]" and the receiver would receive that value by stuffing a variable name with it. To me it appears the receiver is calculating the local value of Close[0] - 10. This is not the same as MoveAvg[0].


                      Is the code correct? or is it in an unfinished state?
                      Shouldn't the receiver have a variable name to receive the calculated value from the sender?

                      Thanks for any insight anyone can offer...


                      taddypole...

                      Comment


                        #56
                        Hello Teddypole,

                        The code is correct.
                        Two things you should know:
                        With the MovAvg.Set you set the value of the Dataseries MovAvg. This is your variable.

                        The formula Close[0]-10 set the errorcode. If the GVget don't get a Value from the dll, this value is set. I normaly use a fixed Value like -1 so I can see a problem with the Transfer. If the Value of the plotted MovAvg is = Close[0]-10 then the GVGet don't got a Value. If the Value is not this Value, the Value is the SMA out of the dll.

                        Jens

                        The transfer with GV.dll work only life and not with historical data. For use with historical data, you have to store all needed data with a timestamp in the dll - for example a name like ES-dd-mm-yy-hh-mm. The get-comand have to use the sam name while calculating historical data.
                        And: If you send data like SMA from 10 min and get it in a 1-min chart, it may be possible, that the first up to 10 values out of the dll are equal to the errorcode, because there is no value set in the dll. The value is normaly set End OF Bar from the 10 min chart - if you don't use intrabar calculation. If you do this, this plots intresting values...
                        Last edited by xenayoo; 04-08-2012, 01:03 PM.

                        Comment


                          #57
                          Hi Jens,

                          Yes, I found the manual for the GlobalVariable.dll and it shows the form of the Get Named Double as:

                          DoubleDuty = GVGetNamedDouble( “Super Algorithm”, ErrorCode ) ;

                          So yes, I now realize that second term is to return the errorcode if the call fails.

                          Fortunately my needs are quite simple. I just want to share some static settings across several indicators on the same chart. I have it working now and it is just what I was looking for.

                          thanks,

                          taddypole...
                          Last edited by Taddypole; 04-08-2012, 02:17 PM.

                          Comment


                            #58
                            Has this stopped working for anyone else?

                            I made a program about a year ago which used the GlobalVariable.dll and it worked just fine. When I recently made a new program to use it I now get an error in my log.

                            "...An attempt was made to load a program with an incorrect format..."

                            Just to make sure I wasn't typing something wrong I imported my old system that I know worked in NT7. It now gets this same error. (Also note, the GV.dll files use different names so im sure they weren't conflicting)

                            If there wasn't something in NT changed that would affect this I'm wondering if it was the MicroTrend framework I tried out. Do you think doing a clean install of NT could help?

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

                            Comment


                              #59
                              Well I think I just realized I'm using 64bit now instead of 32 and I'm guessing this is the issue, is there a 64bit GV.dll available?

                              Comment


                                #60
                                Hello,
                                the GV.dll is a very old project - from Omega Tradestation Support Forum written in Microsoft VS6 C. I use Win XP32 and the dll works fine most of the time. I normaly Write a Special dll for my Projekts.
                                May Be, i can help you to compile a New dll for your win64 System. First you have to find out, how to Compile for 64 Bit (using Microsoft Vs2012 Express).

                                Jens

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by fx.practic, 10-15-2013, 12:53 AM
                                5 responses
                                5,403 views
                                0 likes
                                Last Post Bidder
                                by Bidder
                                 
                                Started by Shai Samuel, 07-02-2022, 02:46 PM
                                4 responses
                                94 views
                                0 likes
                                Last Post Bidder
                                by Bidder
                                 
                                Started by DJ888, Yesterday, 10:57 PM
                                0 responses
                                6 views
                                0 likes
                                Last Post DJ888
                                by DJ888
                                 
                                Started by MacDad, 02-25-2024, 11:48 PM
                                7 responses
                                158 views
                                0 likes
                                Last Post loganjarosz123  
                                Started by Belfortbucks, Yesterday, 09:29 PM
                                0 responses
                                8 views
                                0 likes
                                Last Post Belfortbucks  
                                Working...
                                X