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

Account Verification Script

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

    Account Verification Script

    I am testing a strategy and want to make sure that it is running on the correct simulated account. When the strategy is running on my chart an enabled I want to make sure it is running on a particular simulated account, for example "Sim101". I know you can manually set it in the strategy parameters but I want a backup. I would like the script to verify it is running on that account only. Any help would be appreciated. I looked at this link but couldn't get the script at the bottom to run on the strategy.



    #2
    Hello EminiMES,

    Thank you for your post.

    I recently saw another forum thread that seemed to be attempting the same thing in their script:
    Hello, I am developing a strategy that I need to run on several instruments and several different time frames, but I don't want to add Data Series into a single strategy, I want to run each one on a different Chart. But with the same account, then I must always Select the same account for all strategies. I am running a Filter


    What they are doing is saving an account, based on its name in the Account.All collection, to the myAccount variable. Then, they compare myAccount.Name to Account.Name which would be the name of the account the strategy is running on. If these two names do not match each other, you can call CloseStrategy() to disable the strategy. You could try the following to save a specific account name to myAccount in State.SetDefaults, then you could make the comparison between myAccount.Name and Account.Name where you would like in your strategy, such as State.DataLoaded or at the beginning of OnBarUpdate():
    Code:
    private Account myAccount;
    
    protected override void OnStateChange()
    {
        if (State == State.SetDefaults)
        {
            // Find our Sim101 account
            lock (Account.All)
                  // save the account named Sim101 to myAccount (feel free to change this name to any account name you'd like)
                  myAccount = Account.All.FirstOrDefault(a => a.Name == "Sim101");
        }
    }
    
    protected override void OnBarUpdate()
    {​
            if (myAccount != null)
            {
                 if (myAcccount.Name != Account.Name)
                 {
                      CloseStrategy("strategyName");
                 }
            }
     }​
    ​
    Please let us know if we may be of further assistance.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      That works..... thanks

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Haiasi, 04-25-2024, 06:53 PM
      2 responses
      17 views
      0 likes
      Last Post Massinisa  
      Started by Creamers, Today, 05:32 AM
      0 responses
      5 views
      0 likes
      Last Post Creamers  
      Started by Segwin, 05-07-2018, 02:15 PM
      12 responses
      1,786 views
      0 likes
      Last Post Leafcutter  
      Started by poplagelu, Today, 05:00 AM
      0 responses
      3 views
      0 likes
      Last Post poplagelu  
      Started by fx.practic, 10-15-2013, 12:53 AM
      5 responses
      5,408 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Working...
      X