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

NT7 - Referrencing GlobalVariables.dll

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

    NT7 - Referrencing GlobalVariables.dll

    Im referencing Gobal Variables.dll (that I took from Tradestation) and trying to follow what mktrend has done in the following post...



    but I am getting the following Error when I compile my script that references it?

    Metadata file 'c:\Users\Morgan\Documents\NinjaTrader 7\bin\Custom\GlobalVariable.dll' could not be opened -- 'An attempt was made to load a program with an incorrect format. '

    I know this DLL works in Tradestation as I have used it myself

    #2
    mefTrader, unfortunately this would be outside of the scope we can support here - did you restart NT fresh after the DLL was copied in?
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Yes I did and still get the same Response

      where should the following code go in Ninja Script (before declarations, in variables section??)


      [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


        #4
        Is the DLL potentially available in more than one location on the system?

        Those would likely go to variables yes.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Yes but I am telling Ninja which one to reference by right clicking on the chart and selecting Reference and then Add...

          Comment


            #6
            Perhaps try without a reference, just by pointing to the DLL's path as shown in other thread.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Using the DLLImport command I am getting the following Error similar to when I was referencing it!

              Error on calling 'OnBarUpdate' method for indicator 'SolasTrendFinderAlgorithm' on bar 14: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

              Comment


                #8
                this is what I have at the head of my code

                #region Using declarations
                using System;
                using System.ComponentModel;
                using System.Diagnostics;
                using System.Drawing;
                using System.Drawing.Drawing2D;
                using System.Xml.Serialization;
                using NinjaTrader.Cbi;
                using NinjaTrader.Data;
                using NinjaTrader.Gui.Chart;
                using System.Runtime.InteropServices;
                using System.Text;
                #endregion

                namespace NinjaTrader.Indicator
                {
                /// <summary>
                /// Algorithm determines when a Trend Breakout Long or Short is happening and signals when to trade with risk management or when not to trade!
                /// </summary>
                public class GlobalVariables
                {
                [DllImport("C:/Users/Morgan/Documents/NinjaTrader 7/bin/Custom/GlobalVariable.dll")]
                public static extern int GVSetInteger(int iLocation, int iVal);

                [DllImport("C:/Users/Morgan/Documents/NinjaTrader 7/bin/Custom/GlobalVariable.dll")]
                public static extern int GVGetInteger( int iLocation) ;

                [DllImport("C:/Users/Morgan/Documents/NinjaTrader 7/bin/Custom/GlobalVariable.dll")]
                public static extern int GVSetNamedInt( string iName, int iVal);

                [DllImport("C:/Users/Morgan/Documents/NinjaTrader 7/bin/Custom/GlobalVariable.dll")]
                public static extern int GVGetNamedInt( string iName, int iVal );
                }

                [Description("Algorithm determines when a Trend Breakout Long or Short is happening and signals when to trade with risk management or when not to trade!")]
                public class SolasTrendFinderAlgorithm : Indicator
                {
                #region Variables
                // Wizard generated variables
                private int brkout_length = 10; // Default setting for Brkout_length
                private int risk_length = 14; // Default setting for Risk_length
                // User defined variables (add any user defined variables below)
                private int enable_AudibleAlerts = 0; //Audible Alerts are off by default
                private int Trend_flo =0;
                private DataSeries PercentR; // Define a DataSeries variable
                private int PerR =0;
                private double StDev =0;
                private int LastBar =0;
                private DataSeries TrStop;
                private double yHOD;
                private double yLOD;

                private double HOD = double.MinValue;
                private double LOD = double.MaxValue;
                private double FIF_H = double.MinValue;
                private double FIF_L = double.MaxValue;
                private double Hourly_H = double.MinValue;
                private double Hourly_L = double.MaxValue;
                private int Trend_15m;
                private int Trend_60m;
                private int Trend_Daily;
                private int interm;
                private const double nonValue = -999.99;
                private string sym_name = "";
                #endregion

                /// <summary>
                /// This method is used to configure the indicator and is called once before any bar data is loaded.
                /// </summary>
                protected override void Initialize()
                Last edited by mefTrader; 07-16-2010, 10:58 AM.

                Comment


                  #9
                  mefTrader, can you please post the 'declarations' you're using, too?
                  BertrandNinjaTrader Customer Service

                  Comment


                    #10
                    Have updated the code above

                    Comment


                      #11
                      I am going to attach the Tradestation Global Variable zip file here too and the documentation to this topic page too
                      Attached Files

                      Comment


                        #12
                        Thanks I tried on my end here with a reference and using directive in the declerations, both giving me the same error you got - are you also working on 64 bit OS? I google for the returned error and seems related to this relatively old DLL being programmed for 32 bit only. Did the other forums memebers using it replied to your already? Did you trey PM'ing them? They would have more experience in this unsupported territory.

                        Thanks
                        BertrandNinjaTrader Customer Service

                        Comment


                          #13
                          ok thanks

                          Am using 64 bit OS too have not tried the 32 bits version...Have tried to send some of them an email

                          Comment


                            #14
                            Tried the 32bit version and got a different error - "Error on calling 'OnBarUpdate' method for indicator 'SolasTrendFinderAlgorithm' on bar 14: Unable to find an entry point named 'GVSetInteger' in DLL 'C:/Users/Morgan/Documents/NinjaTrader 7/bin/Custom/GlobalVariable.dll'."

                            Out of ideas now - really need someone else who has used this successfully in Ninja to give me some ideas!

                            Comment


                              #15
                              Okay seem to have got it to work!

                              You need to run it on the 32 bit version

                              and you need to use GV_

                              Here are my declarations...

                              #region Using declarations
                              using System;
                              using System.ComponentModel;
                              using System.Diagnostics;
                              using System.Drawing;
                              using System.Drawing.Drawing2D;
                              using System.Xml.Serialization;
                              using NinjaTrader.Cbi;
                              using NinjaTrader.Data;
                              using NinjaTrader.Gui.Chart;
                              using System.Runtime.InteropServices;
                              using System.Text;
                              #endregion

                              // This namespace holds all indicators and is required. Do not change it.
                              namespace NinjaTrader.Indicator
                              {
                              /// <summary>
                              /// Algorithm determines when a Trend Breakout Long or Short is happening and signals when to trade with risk management or when not to trade!
                              /// </summary>
                              public class GlobalVariables
                              {
                              [DllImport("C:/Users/Morgan/Documents/NinjaTrader 7/bin/Custom/GlobalVariable.dll")]
                              public static extern int GV_SetInteger(int iLocation, int iVal);

                              [DllImport("C:/Users/Morgan/Documents/NinjaTrader 7/bin/Custom/GlobalVariable.dll")]
                              public static extern int GV_GetInteger( int iLocation) ;

                              [DllImport("C:/Users/Morgan/Documents/NinjaTrader 7/bin/Custom/GlobalVariable.dll")]
                              public static extern int GV_SetNamedInt( string iName, int iVal);

                              [DllImport("C:/Users/Morgan/Documents/NinjaTrader 7/bin/Custom/GlobalVariable.dll")]
                              public static extern int GV_GetNamedInt( string iName, int iVal );
                              }

                              Here is how I used it then in OnBarUpdate...

                              if (Instrument != null)
                              {
                              sym_name = Instrument.MasterInstrument.Name;
                              }
                              if ((Bars.Period.Id == PeriodType.Minute) && (Bars.Period.Value == 15) )
                              {
                              int Trend_15m = GlobalVariables.GV_SetNamedInt(sym_name+"_15m",Tre nd_flo);
                              //int Trend_15m = GlobalVariables.GV_SetInteger(1, Trend_flo);
                              //Print("Date and Time "+Time[0]+"Sym"+sym_name+" Trend_15m "+Trend_flo );
                              }
                              if ((Bars.Period.Id == PeriodType.Minute) && (Bars.Period.Value == 60) )
                              {
                              int Trend_60m = GlobalVariables.GV_SetNamedInt(sym_name+"_60m",Tre nd_flo);
                              //Print("Date and Time "+Time[0]+"Sym"+sym_name+" Trend_60m "+Trend_flo );
                              }
                              if ((Bars.Period.Id == PeriodType.Day) && (Bars.Period.Value == 1) )
                              {
                              int Trend_Daily = GlobalVariables.GV_SetNamedInt(sym_name+"_Daily",T rend_flo);
                              //Print("Date and Time "+Time[0]+"Sym"+sym_name+" Trend_Daily "+Trend_flo );
                              }
                              if ((Bars.Period.Id == PeriodType.Minute) && (Bars.Period.Value == 5) )
                              {
                              int Trend_5m = GlobalVariables.GV_SetNamedInt(sym_name+"_5m",Tren d_flo);
                              }
                              if ((Bars.Period.Id == PeriodType.Tick) && (Bars.Period.Value == 150) ) //GV on a TICK by TICK
                              {
                              Trend_5m = GlobalVariables.GV_GetNamedInt(sym_name+"_5m", -999 ) ; // Get the 15m Trend Setting. Error if -999
                              Trend_15m = GlobalVariables.GV_GetNamedInt(sym_name+"_15m", -999 ) ; // Get the 15m Trend Setting. Error if -999
                              Trend_60m = GlobalVariables.GV_GetNamedInt(sym_name+"_60m", -999 ) ; // Get the 15m Trend Setting. Error if -999
                              Trend_Daily = GlobalVariables.GV_GetNamedInt(sym_name+"_Daily", -999 ) ; // Get the 15m Trend Setting. Error if -999
                              interm = Trend_5m + Trend_15m + Trend_60m + Trend_Daily;
                              Stock_Weighting.Set(interm);
                              Last edited by mefTrader; 07-16-2010, 02:55 PM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by port119, Today, 02:43 PM
                              0 responses
                              1 view
                              0 likes
                              Last Post port119
                              by port119
                               
                              Started by Philippe56140, Today, 02:35 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post Philippe56140  
                              Started by 00nevest, Today, 02:27 PM
                              0 responses
                              1 view
                              0 likes
                              Last Post 00nevest  
                              Started by Jonafare, 12-06-2012, 03:48 PM
                              5 responses
                              3,986 views
                              0 likes
                              Last Post rene69851  
                              Started by Fitspressorest, Today, 01:38 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post Fitspressorest  
                              Working...
                              X