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

How to use NinjaTrader.Cbi.License object as a method parameter

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

    How to use NinjaTrader.Cbi.License object as a method parameter

    Hello.

    I made my own Test_class and put it to separate .cs file
    And I'd like to check MashineID in constructor.
    Code:
    [COLOR=Blue]using [/COLOR]NinjaTrader.Cbi;
    [COLOR=Blue]namespace [/COLOR]i_Lib_Test
    {
        [COLOR=RoyalBlue][COLOR=Blue]public class[/COLOR] [/COLOR]Test_class
        {
            [COLOR=Blue]public [/COLOR]Test_class( NinjaTrader.Cbi.License licenseObject )
            { 
            }
        }
    }
    Then I tried to create an instance of Test_class object, but it don't work:

    Code:
    Test_class tc = new Test_class( this.Cbi.License );
    Test_class tc = new Test_class( NinjaTrader.Cbi.License );
    Test_class tc = new Test_class( License );
    Can You, please, tell what object I have to use as argument?
    (I'm sure using just Licenes.MashineID string as argument is useless, am I wrong?).
    Last edited by fx.practic; 09-07-2015, 02:04 PM.
    fx.practic
    NinjaTrader Ecosystem Vendor - fx.practic

    #2
    Originally posted by fx.practic View Post
    Hello.

    I made my own Test_class and put it to separate .cs file
    And I'd like to check MashineID in constructor.
    Code:
    [COLOR=Blue]using [/COLOR]NinjaTrader.Cbi;
    [COLOR=Blue]namespace [/COLOR]i_Lib_Test
    {
        [COLOR=RoyalBlue][COLOR=Blue]public class[/COLOR] [/COLOR]Test_class
        {
            [COLOR=Blue]public [/COLOR]Test_class( NinjaTrader.Cbi.License licenseObject )
            { 
            }
        }
    }
    Then I tried to create an instance of Test_class object, but it don't work:

    Code:
    Test_class tc = new Test_class( this.Cbi.License );
    Test_class tc = new Test_class( NinjaTrader.Cbi.License );
    Test_class tc = new Test_class( License );
    Can You, please, tell what object I have to use as argument?
    (I'm sure using just Licenes.MashineID string as argument is useless, am I wrong?).
    Just use the string.

    ref: http://ninjatrader.com/support/forum...ead.php?t=1478

    Comment


      #3
      Originally posted by koganam View Post
      I want put main calculation in separate class compiled to DLL. That class will be "black box" - just gives buy / sell signals.

      And strategy code I want leave opened.

      In this case anyone can edit strategy code and change
      Code:
      Test_Class ts = new Test_class( NinjaTrader.Cbi.License.MashineID);
      to constant string:
      Code:
      Test_Class ts = new Test_class( "[COLOR=DarkRed]666777666777666777666777666777666777[/COLOR]");
      fx.practic
      NinjaTrader Ecosystem Vendor - fx.practic

      Comment


        #4
        Originally posted by fx.practic View Post
        I want put main calculation in separate class compiled to DLL. That class will be "black box" - just gives buy / sell signals.

        And strategy code I want leave opened.

        In this case anyone can edit strategy code and change
        Code:
        Test_Class ts = new Test_class( NinjaTrader.Cbi.License.MashineID);
        to constant string:
        Code:
        Test_Class ts = new Test_class( "[COLOR=DarkRed]666777666777666777666777666777666777[/COLOR]");
        So create a static class to check and report for you.

        ref: http://ninjatrader.com/support/forum...27&postcount=5

        You might want to read the entire thread for the subtle nuances.

        Comment


          #5
          koganam, thank You for Your answers!

          I read the thread, but I have misunderstanding.

          My situation: I want give to another person 2 files:
          1) BuySell.dll that contain Test_class;
          2) MyStarategy.cs, that contain this code:
          Code:
          [COLOR=Blue]using [/COLOR]BuySellSignals;
          
              [COLOR=Blue]public class[/COLOR] MyStartegy : Strategy
              {        
                  [COLOR=Blue]private [/COLOR]BuySellSignals_class Buy_Sell_Object;
          
                  [COLOR=Blue]protected override void[/COLOR] OnStartUp()
                  { 
                      Buy_Sell_Object = [COLOR=Blue]new [/COLOR]BuySellSignals_class( NinjaTrader.Cbi.License.MashineID );
                  }    
                  
                  [COLOR=Blue]protected override void[/COLOR] OnBarUpdate()
                  {
                      [COLOR=Blue]switch[/COLOR]( Buy_Sell_Object( Open[0], High[0], Low[0], Close[0] ) )
                      {
                          [COLOR=Blue]case [/COLOR]"[COLOR=DarkRed]buy[/COLOR]":  EnterLong();
                          [COLOR=Blue]case [/COLOR]"[COLOR=DarkRed]sell[/COLOR]": EnterShort();                
                      }            
                  }
              }
          }
          In that case, independently of BuySell.dll code and access modifiers inside it, any user can replace in any text editor "NinjaTrader.Cbi.License.MashineID" to constant string.

          So, I want to use as a parameter something bigger than just string.
          fx.practic
          NinjaTrader Ecosystem Vendor - fx.practic

          Comment


            #6
            Hello fx.practic,

            Could you please clarify what you mean when you say the following:
            So, I want to use as a parameter something bigger than just string.
            From the example provided, you could put the code that checks the license key in your BuySellSignals_class and have it return null (or similar) if the machine ID provided to it is not valid.

            Then you would just recompile the BuySell.cs assembly and add in a null reference check inside the OnBarUpdate code of your MyStrategy.cs file.

            Please let me know if you have any questions.
            Michael M.NinjaTrader Quality Assurance

            Comment


              #7
              Originally posted by fx.practic View Post
              koganam, thank You for Your answers!

              I read the thread, but I have misunderstanding.

              My situation: I want give to another person 2 files:
              1) BuySell.dll that contain Test_class;
              2) MyStarategy.cs, that contain this code:
              Code:
              [COLOR=Blue]using [/COLOR]BuySellSignals;
              
                  [COLOR=Blue]public class[/COLOR] MyStartegy : Strategy
                  {        
                      [COLOR=Blue]private [/COLOR]BuySellSignals_class Buy_Sell_Object;
              
                      [COLOR=Blue]protected override void[/COLOR] OnStartUp()
                      { 
                          Buy_Sell_Object = [COLOR=Blue]new [/COLOR]BuySellSignals_class( NinjaTrader.Cbi.License.MashineID );
                      }    
                      
                      [COLOR=Blue]protected override void[/COLOR] OnBarUpdate()
                      {
                          [COLOR=Blue]switch[/COLOR]( Buy_Sell_Object( Open[0], High[0], Low[0], Close[0] ) )
                          {
                              [COLOR=Blue]case [/COLOR]"[COLOR=DarkRed]buy[/COLOR]":  EnterLong();
                              [COLOR=Blue]case [/COLOR]"[COLOR=DarkRed]sell[/COLOR]": EnterShort();                
                          }            
                      }
                  }
              }
              In that case, independently of BuySell.dll code and access modifiers inside it, any user can replace in any text editor "NinjaTrader.Cbi.License.MashineID" to constant string.

              So, I want to use as a parameter something bigger than just string.
              I do not understand what you have written and how it relates to the code to which I referred you.

              The class for checking the MachineID has only one purpose: to check that the MachineID of the running computer is in the list maintained inside the MachineID-checking class. So how does changing the comparator in another class have any meaning, unless that, now fixed, comparator is already on the approved list inside the MachineID-checking class?

              Addendum:
              And if you are going to expose the check in another class which can be edited to replace the MachineID in the first place, then that same person can edit out the check completely, no matter what you think you are doing in the checking class.
              Last edited by koganam; 09-08-2015, 02:37 PM.

              Comment


                #8
                2 NinjaTrader_MichaelM:Wow! It's rely work!

                Code:
                [COLOR=Blue]namespace[/COLOR] Lib_BuySelSignals
                {    
                    [COLOR=Blue]public class[/COLOR] BuySelSignals_class
                    {
                        [COLOR=Blue]public [/COLOR]BuySelSignals_class()
                        {
                            [COLOR=Blue]string [/COLOR]masine_id = NinjaTrader.Cbi.License.MachineId;    
                        }
                    }
                }
                Some time ago I tried to call Open, High, Low, Close, Time dataseries from my own classes, and got error. So, I decided that NT objects and classes are unaccessible from custom classes.

                And now I see NinjaTrader.Cbi.License can be called with no problem.

                Thank You.


                2 koganam:
                I thought in this way:
                Can user create new string object (that contains fixed MachineID)? - Yes, he can.
                Can user create, for example new NinjaTrader object? - No, he can't - only one NT instance can be running.
                Can user create NinjaTrader.Cbi or NinjaTrader.Cbi.License object? - I don't know. But, if he can, it must be march more difficult that create fake string.

                But now I see there no need to do it. As for, as I understand, NinjaTrader.Cbi.License is a static class ant it can be accessible from custom libraries.

                Thank You.
                fx.practic
                NinjaTrader Ecosystem Vendor - fx.practic

                Comment


                  #9
                  Hello fx.practic,

                  Thank you for the update. I am glad to hear everything is working for you now.

                  Please let us know if you have any questions or if we may be of further assistance anytime.
                  Michael M.NinjaTrader Quality Assurance

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by jclose, Today, 09:37 PM
                  0 responses
                  4 views
                  0 likes
                  Last Post jclose
                  by jclose
                   
                  Started by WeyldFalcon, 08-07-2020, 06:13 AM
                  10 responses
                  1,413 views
                  0 likes
                  Last Post Traderontheroad  
                  Started by firefoxforum12, Today, 08:53 PM
                  0 responses
                  10 views
                  0 likes
                  Last Post firefoxforum12  
                  Started by stafe, Today, 08:34 PM
                  0 responses
                  10 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