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

accounts

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

    accounts

    Code:
    [COLOR=#ffffff]  [/COLOR]myAccount=Account.All.FirstOrDefault(a=>a.Name==[COLOR=#800000]"Sim101"[/COLOR]);
    Can someone help me understand every bit of this?
    It doesnt say very much in the help file.
    Is it account.connection or account.positions
    a???? wtf is a? thanks!!

    #2
    Hello ezrollin,

    This would be how to find the Sim101 account object and assign this to a variable named myAccount which has the variable type of Account.

    Account.All is a collection of all of the connected accounts.

    .FirstOrDefault() is a method to get the first element in a collection where the lambda expression matches.

    (a => a.Name == "Sim101") is a lambda expression. Its assigning each object to the variable as it loops through them. Name is a property of Account. The condition is comparing the a.Name of the account to be equal to "Sim101".

    Once you have the variable, in this case myAccount, assigned the Sim101 account object you can add handlers for the PositionUpdate event, loop through positions, or look at the account connection.

    myAccount.PositionUpdate += OnAccountPositionUpdate;






    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by ezrollin View Post
      Code:
      myAccount=Account.All.FirstOrDefault(a[B][COLOR=#e74c3c]=>[/COLOR][/B]a.Name==[COLOR=#800000]"Sim101"[/COLOR]);
      Can someone help me understand every bit of this?
      It doesnt say very much in the help file.
      Is it account.connection or account.positions
      a???? wtf is a? thanks!!
      The two-character sequence '=>' is called the lamba operator.

      The presence of the lamba operator, by definition, means you are
      using a lamba expression, which is actually pretty simple,

      (input params) => expression;

      The 'input params' are just placeholders, and whatever names you
      see on the left of the lamba operator (these are usually very brief
      short 1-character names) are also the names used on the right side
      of the lamba operator. Consider that parameters defined in the
      argument list of a method are treated like temporary variables in
      the body of that method. Well, these input params are treated the
      same way in the expression part of the lamba expression -- that is,
      the 'a' is a temporary variable.

      Here's the beautiful thing,
      Lamba expressions can be used as predicates.

      What's a predicate?
      And why is this 'lamba expression' vs 'predicate' thing important?
      Ah, you have much to learn, Padi-wan.

      Yep, you're getting heavy into the world of C# by asking this question,
      and none of this has the slightest bit to do with NinjaScript. Nope, not
      a thing. Nada. Zilch. Nyet. This is all C# programming, baby.

      Predicates and delegates are fundamental building blocks used by
      LINQ, and LINQ uses predicates a lot.

      Like I said,
      The beautiful thing about lamba expressions is they are a shorthand
      way, er, I mean, an 'inline' way of creating predicates -- and this quick
      way of writing predicates is perfectly suited for LINQ.

      Ok, that's enough for now. The rest is up to you.
      Go forth, young grasshopper, and search the web.

      Start by reading this and then study this page to understand how the
      'predicate' specified in the FirstOrDefault parameter list is satisfied
      by the lamda expression. Also, see attached screenshot.

      Attached Files
      Last edited by bltdavid; 02-28-2022, 01:12 AM.

      Comment


        #4
        Here's another link to get you started.

        Comment


          #5
          Chelsea, Can I add a question to this topic? Is there a way to switch between Sim101 and the RealLiveAcct without code change and recompile.? Thanks, Ken

          Comment


            #6
            Hello kenz987,

            From an indicator an account selector can be added.
            How would one incorporate Account and Instrument Selectors in Property Grids? The intention is to allow an Account or Instrument to be selected from the relevant selector as a property of an AddOn. EDIT Update: I've found this for Instruments and it works well enough: [PropertyEditor("NinjaTrader.Gui.Tools.InstrumentPic


            Or you could use the chart trader selected account.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Thank YOU Chelsea, I meant that for a strategy, but I can do this now!!

              Comment


                #8
                see note Click image for larger version

Name:	Test-04-30.png
Views:	31
Size:	75.1 KB
ID:	1301625
                why are there two selectors for strategies

                Comment


                  #9
                  Hello kenz987,

                  The Account selector that is already part of all strategies, is the Account the strategy will run on and place orders to.
                  It is not supported to remove this, or any other intended functionality from NinjaTrader.

                  Your post was posted in the NinjaTrader Desktop > Indicator Development​ section of the forums, so my answers have been targeted to indicators which do not have an internal Account object already, the way that Strategies do.

                  A strategy already has an Account object, a selector property for this in the Strategies window, and this is what is used for selecting the account the strategy will trade to.
                  Once a strategy is enabled, the Account cannot be changed.
                  Attempting to bind the chartTrader account selector to the strategies Account will break the strategy and prevent it from being enabled.

                  If you wanted to use the chartTrader account selector for something else that is not related to the orders and positions for the strategy, like getting account values from a random account or something, you could do so, but removing the existing Account property from the Strategies window will not be supported.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Thanks Chelsea, Ok so is there a way I can at least get a read-only access to it so I can be sure both accounts are the same?
                    I know I can submit a pending order and run it thru OnOrderUpdate and get the account from that, but that is a bit messy, thought there might be a cleaner way. Thank You for all your help.
                    Last edited by kenz987; 05-01-2024, 09:37 AM.

                    Comment


                      #11
                      Hello kenz987,

                      Read-only access to what?

                      You can get the chartTrader selected account using the code suggested in post # 6.
                      You can compare that to the Account native to the strategy if you want.
                      (But you cannot change the Account native to the strategy to match the account selected in chart trader without causing issues)
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        OK Great I just want them to be the same so I get the Order markers on the chart.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by ETFVoyageur, 05-18-2024, 12:45 AM
                        5 responses
                        31 views
                        0 likes
                        Last Post ETFVoyageur  
                        Started by Kraken29, Today, 03:24 PM
                        1 response
                        10 views
                        0 likes
                        Last Post NinjaTrader_Clayton  
                        Started by Skifree, Today, 11:47 AM
                        5 responses
                        19 views
                        0 likes
                        Last Post Skifree
                        by Skifree
                         
                        Started by ETFVoyageur, Today, 10:34 AM
                        10 responses
                        25 views
                        0 likes
                        Last Post ETFVoyageur  
                        Started by traderzoso, 12-27-2020, 05:19 PM
                        6 responses
                        231 views
                        0 likes
                        Last Post lekor
                        by lekor
                         
                        Working...
                        X