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

Got stuck trying to use script to check HardDrive ID for licensing

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

    Got stuck trying to use script to check HardDrive ID for licensing

    Hi,

    I'm new in the area that I'm working in, but I've been able to get some code working in Visual Studio C# where using the System.Management.dll I could make the program check for the hard drive serial, then return it to me to use later.

    Then, I made another program that checks the same things, and if it matches the same serial the first program produced, then it thinks "this computer is licensed to use this program etc"

    I've found out how to successfully add the reference to System.Management to my code and it all compiles, etc. But when I compile it, the output window subtly displays a line with this error:

    "AssemblyResolveEvent handlers cannot return Assemblies loaded for reflection only"

    and the code doesn't run in the strategy analyzer window.

    I have no idea what the line in quotes means, but I can tell it doesn't like what I'm trying to do with system.management and the device ID checking. But can anyone please elaborate to me what it's problem is?

    This is the code I'm using to try to check the device ID:


    ManagementObject HardDisk = new ManagementObject(@"win32_logicaldisk.deviceid=""" + "C" + @":""");
    HardDisk.Get();
    string VolumeSerial = dsk["VolumeSerialNumber"].ToString();


    if (VolumeSerial == "[whatever the hard drive serial you want may be]")
    Print("YOU HAVE THE RIGHT COMPUTER FOR THIS CODE");
    else
    Print("License doesn't match hard drive ID");

    #2
    Nevermind, I found out what it was:

    I had to use the .NET 2.0 version of System.Management and not the 4.0 version

    The answer was found by google searching the error message, then finding another ninjatrader support forum thread that said a similar discussion with the answer, found here: http://www.ninjatrader.com/support/f...ad.php?t=47205

    Comment


      #3
      Glad to hear and thanks for letting us know.
      BertrandNinjaTrader Customer Service

      Comment


        #4
        Oh hi, it's me again!

        I thought I should add this to this thread to preserve the backstory, etc. Anyway, I've got the strategy all ready to go and I've tried exporting it as a .zip, intending to move it over to my laptop to try out the hardwareID recognition, etc. However, this has come up:

        While exporting the zip, this warning popup says "Please be aware that the exported NinjaScript Archive File can only be imported if the target PC has the following assembly(s) loaded: NcatTrendHeatMap, System.Management.

        The heatmap is from a ninjacator of the month thing I was sent and shouldn't even have anything to do with the strategy I'm exporting. As for System.Management, this was an assembly I had to add manually in references by rightclicking the script editor, clicking references, and clicking Add, then looking up windows/.net framework/2.0 or whatever and adding System.Management.dll. Will I have to instruct everybody I have use this strategy that they should do this process themselves?

        And can someone please tell me why is the heatmap ninjacator interfering?

        Thanks!

        *Edit: Yeah, it even tells me the same thing when I try to export other strategies I used to be able to export successfully. I'd like to know more about why unrelated strategies are so mysteriously tied to each other, and if I'm really going to have to get people to install the system.management assembly on each installation - thanks!
        Last edited by RunnrX; 03-18-2013, 12:31 AM.

        Comment


          #5
          RunnrX, this would be unfortunately expected as far as the referencing goes - for distribution please therefore export from a 'clean' development system that would only have the default NT references added - then the extra custom 3rd party DLL's you have installed now would not be included as expected references on the target machines.
          BertrandNinjaTrader Customer Service

          Comment


            #6
            Thanks for letting me know. One issue is that my strategy itself uses System.Management.dll for a hardware ID check at Initialize, so I would think I'd have to have everyone add that reference themselves,

            however,

            I tried exporting the strategy as an assembly instead of as the regular editable .zip file, and I did not get the warning message and I was able to run it on the other computer without having to do any extra installation work other than to import the strategy. That at least puts me back to where I want to be, with having a simple to distribute strategy, but I wish I understood the technical reasons behind what's going on (I'll learn that as I go)

            I keep finding weird discoveries.. like last night when I ran both strategies on each computer with the same sample dates, the same instrument, the same settings, the same "adjust for splits" option selected, both on exitonclose=false, etc etc, same free Kinetick data feed (you name it), and their P&L outcome still differed by $10 over a 1 year daily chart test. For now I'm just calling that acceptable mysterious variance and leave it at that for now.

            Thanks!

            Comment


              #7
              Correct, if you export non compiled / source code > the reference would not be added or need to be in the export.

              Are both PC's you tested with setup in same time zone? Would you see the same still on a fresh set of data downloaded? For further inspection, the list of executions for both runs would need to be compared, so you can see where the difference stems from.
              BertrandNinjaTrader Customer Service

              Comment


                #8
                About the data discrepancies, yes you're right. I had both PCs using the same strategy, same datafeed, same settings, but for one it got $12,450 in PL and the other got -$3000

                Then I noticed that the trade execution prices were wildly different, and that made me realize that the new PC wasn't told to adjust historical prices for stock splits, an unexpected issue. After switching that, the two P&L results were still a few thousand apart, so I reloaded all historical data and that got them to only be $10 apart from each other which was in totally acceptable range.

                Ok, I think that does it for me for now. It's surprising how many things one needs to take into consideration when making and distributing strategies, but once you see the issue it isn't forgotten so at least for me this has been a progressive learning experience. Thank you for all your help NinjaTrader_Bertrand!

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by f.saeidi, Yesterday, 02:09 PM
                3 responses
                18 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by Jltarrau, Today, 05:57 AM
                1 response
                5 views
                0 likes
                Last Post NinjaTrader_LuisH  
                Started by kujista, Today, 06:23 AM
                0 responses
                2 views
                0 likes
                Last Post kujista
                by kujista
                 
                Started by traderqz, Yesterday, 04:32 PM
                1 response
                12 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by f.saeidi, Today, 05:56 AM
                1 response
                5 views
                0 likes
                Last Post Jltarrau  
                Working...
                X