Announcement

Collapse
No announcement yet.

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:	155
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


                          #13
                          ​Hi Chelsea,
                          the ChartButtonSample code has the following : account = Account.All.FirstOrDefault(a => a.Name == "Sim101");
                          Do I need modify "Sim101" to my "DEMO54854" or live account number in order to test the sample code ?
                          Attached Files

                          Comment


                            #14
                            One more question from the same sample code is as follows. I can't locate where "Instrument" is defined. Can I just replace it with "ES 12-24" ?


                            region Use case 1, immediately submitting a market order

                            if (button == longMarketButton)
                            {
                            Order mar****rder = account.CreateOrder(Instrument, OrderAction.Buy, OrderType.Market, OrderEntry.Manual, TimeInForce.Day, 1, 0, 0, string.Empty, string.Empty, new DateTime(), null);
                            account.Submit(new Order[] { mar****rder} );
                            }
                            #endregion​
                            Click image for larger version

Name:	image.png
Views:	44
Size:	22.6 KB
ID:	1326412
                            Attached Files
                            Last edited by judysamnt7; 12-02-2024, 08:41 PM.

                            Comment


                              #15
                              Hello judysamnt7,

                              The local Sim101 account is available with Multi-provider mode is enabled.


                              You can change to the account name of a demo account or live account if you wanted.

                              The Instrument is the instrument of the primary data series, of the chart the indicator or strategy (or host script) is applied to.
                              If the indicator is on an ES 12-24 chart the Instrument property available to the indicator class will be ES 12-24.
                              Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.


                              If you want to hard code a different instrument to place the orders to you can get an Instrument object and assign this to a custom variable using Instrument.GetInstrument().
                              Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by meatskin, Today, 03:07 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post meatskin  
                              Started by Pa_Baz, 12-14-2024, 09:40 PM
                              26 responses
                              372 views
                              1 like
                              Last Post MarioM94  
                              Started by crystalet, 12-06-2022, 06:59 AM
                              2 responses
                              50 views
                              1 like
                              Last Post mrmark123  
                              Started by ClauTrade, Today, 02:26 PM
                              2 responses
                              8 views
                              0 likes
                              Last Post ClauTrade  
                              Started by jpapa, Today, 01:44 PM
                              6 responses
                              21 views
                              0 likes
                              Last Post jpapa
                              by jpapa
                               
                              Working...
                              X