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

Allowing only one instance of a strategy?

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

    Allowing only one instance of a strategy?

    I have a strategy that I am leasing out. I want to make sure that this strategy can be running only once. In other words, I do not want someone with multiple accounts to be able to place this strategy on all of them at once. My license is for one account only. I know that the strategy tap keeps a log of each active strategy. Is there a way to check this log and if my strategy is already loaded then I could trigger an alert message and halt the second attempt to load my strategy. Any code examples would be greatly appreciated. Thanks

    #2
    Hello,

    Thank you for your forum post.

    Unfortunately this is unsupported. The only way I can think of you to do this is to hard code in the customers account name and check the Account name before allowing the user to start the strategy. This could be hard coded in the strategy before you send it out to the customer.

    Account.Name in NinjaTrader 7

    AccountName in NinjaTrader 6.5

    To get the account name the strategy is running on.


    Let me know if I can be of further assistance.

    Comment


      #3
      I am hoping someone can give me a better work around than that. In the mean time, I suggest that you offer a solution to this in a future upgrade. All you would need is a method that checks the names of the strategies running on the strategy tab in control center. Otherwise, savy traders could trade their buddies accounts with my strategy without them having to pay for it.

      Comment


        #4
        Hello,

        Would love to forward to development however not sure I understand.

        Why will the solution descibed below not work for what you just mentioned?

        The solution you mention I would think is less then ideal since the user may want to start muliple strategies on the same account for different instruments. With checking the strategy names running this would make this impossible. However with checking the account name as I described you would be able to limit the user from trading another persons account as you mention.

        Please clarify so that I can get on the same track.

        Comment


          #5
          You are thinking small and I am thinking big. If it was just a couple of users, no problem. The method you are suggesting would require me to resend to every user individual upgrades or inhancements to my stragegy. As it stands now, they just download the latest version from my website. The same one for all is the best solution. Don't you think???

          Comment


            #6
            By the way, my strategy will only work on one instrument. It calls out to an atm strategy. If they want to test a different atm strategy on sim and run on live, this could be done via the shadow atm strategy.

            Comment


              #7
              Hello,

              Understood.

              I will forward this to development. Another idea as a workaround for now I have is to write to a text file when the strategy is started to name of the account or something like this. Then you can track it, then do something if he has started it on another account. Then OnTermination you would remove the account name from the text file. This is something I might consider doing if it was me. You could also then limit how many times he starts the strategy.



              Let me know if I can be of further assistance.

              Comment


                #8
                Now, that might work. I will study the thread. Thank you and I do hope a method for limiting how many instances will be added in the future.

                Comment


                  #9
                  You could use the techniques used to force an application to be single instance.
                  something like createmutex etc...

                  mutex = newMutex(true, "Global\\"+sstratetegyname, out bCreatedNew);

                  andreas
                  www.zweisteintrading.eu

                  Comment


                    #10
                    Interesting idea; I am not familiar with it. Will an exception error trigger on second attempt to start?

                    Comment


                      #11
                      you do:


                      static Mutex mutex;

                      ....


                      bool isalreadyrunning(){
                      mutex = newMutex(true, "Global\\"+strdpaulwStrategy, out bCreatedNew);
                      if (bCreatedNew) mutex.ReleaseMutex();
                      return !bCreatedNew;

                      }


                      for more details do a search on MSDN or google. keywords C# Mutex single Instance

                      Comment


                        #12
                        Originally posted by zweistein View Post
                        you do:


                        static Mutex mutex;

                        ....


                        bool isalreadyrunning(){
                        mutex = newMutex(true, "Global\\"+strdpaulwStrategy, out bCreatedNew);
                        if (bCreatedNew) mutex.ReleaseMutex();
                        return !bCreatedNew;

                        }


                        for more details do a search on MSDN or google. keywords C# Mutex single Instance
                        I have just now gotten around to trying your suggested code. I get the following error: The type or namespace Mutex cannot be found.

                        I may be placing the code in the wrong place in the strategy.

                        Comment


                          #13
                          Originally posted by NinjaTrader_Brett View Post
                          Hello,

                          Understood.

                          I will forward this to development. Another idea as a workaround for now I have is to write to a text file when the strategy is started to name of the account or something like this. Then you can track it, then do something if he has started it on another account. Then OnTermination you would remove the account name from the text file. This is something I might consider doing if it was me. You could also then limit how many times he starts the strategy.



                          Let me know if I can be of further assistance.
                          Brett, I am having trouble using the suggested Mutex code by another member. I have looked at the file sample on using a text file. I have never worked with this before. If I just want a file created on the first start of my strategy, then wouldn't I have to delete the file on the close of my strategy? All I would need is a simpe text file to record how times it is open. Is there an on strategy close method that I can use to delete the text file or just set the value in the file to zero? If you would have the time to give me an example of the code I would need, I would greatly appreciate it. Thanks.

                          Comment


                            #14
                            dpaulw, unfortunately we do not have any sample code for deleting files or advanced file manipulation techniques.

                            You would not have to delete the file upon close of the strategy. Every time the strategy opened up the file for writing, you could just add more text to it.

                            When an indicator/strategy is "closed" the OnTermination() method is called, and you could use this method to manipulate your files.
                            AustinNinjaTrader Customer Service

                            Comment


                              #15
                              I know this is simple, but the logic seems to be stumping me. I am trying to use the text file idea along with onstartup() and ontermination(). My logic is working on the second attempt at strating my strategy, but fails upon the second. I use ontermination() to reset my values. On the second attempt to startup I through a log exception and disable that strategy. The disable must be terminating and reseting my values. So, on the third attempt my text file is reset back to beginning and the third attempt will succeed in running.

                              This has to simple, but it sure is stumping me. Any help from anyone would be greatly appreciated.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by mintos, 04-02-2024, 08:22 PM
                              4 responses
                              29 views
                              0 likes
                              Last Post mintos
                              by mintos
                               
                              Started by Felix Reichert, 04-26-2024, 02:12 PM
                              10 responses
                              68 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by PaulMohn, 04-24-2024, 03:49 AM
                              4 responses
                              36 views
                              0 likes
                              Last Post PaulMohn  
                              Started by lightsun47, Today, 11:37 AM
                              1 response
                              9 views
                              0 likes
                              Last Post NinjaTrader_Zachary  
                              Started by vitaly_p, Yesterday, 05:09 PM
                              4 responses
                              36 views
                              0 likes
                              Last Post vitaly_p  
                              Working...
                              X