Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

DLL position limitations

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

    #16
    imported post

    Oli,

    It will return the correct virtual position of the strategy, not your netaccount position. These are two completely different things.

    Correct account position is returned by:

    Cbi.Position myPosition = Account.Positions.FindByInstrument(Instrument instrument);
    if (myPosition != null)
    // There is a broker position

    Ray

    RayNinjaTrader Customer Service

    Comment


      #17
      imported post

      Sorry to chime in ....
      Ray

      Does Account.Position refer to only the instrument the strategy is running against, or the account as a whole?

      Reason I'm asking, is that there are some functions, such as 'Flatten All' that refer to the whole account.

      Comment


        #18
        imported post

        No problem.

        My mistake actually. What we have in the layer under NinjaScript (which is not officially supported via documentation nor tech support) is

        Account.Positions.FindByInstrument(Instrument instrument)

        so, if you wanted to determine if an accountposition existed for the given instrument you would:

        Cbi.Position myPosition = Account.Positions.FindByInstrument(Instrument instrument);
        if (myPosition != null)
        // There is a position

        For clarification, account level propertiesare not supported in the NinjaScript layer although it is exposed for programmer who want to access it. We are just not in a position to provide the support you would expect with these lower level methods and properties.

        The above references the account as a whole.

        Ray
        RayNinjaTrader Customer Service

        Comment


          #19
          imported post

          Ray, perhaps you could give some example generic code, sort of a code temple, for writing a robust/fault tolerent automated strategy. Weneed to handle, in an unambiguous way, the following senerios:

          Senerio 1) Loose broker order connection and/or data connection.

          I'm guessing two events need to be handled:

          a) Lost connection event

          I'm guessing here the best we can do is just display a dialog box or maybe email telling us we lost the connection.

          b) Connection Reestablished event

          Here it seems like we needour code to resond to this event which will querry the broker and resync our code with what the broker says is our working positions and the orders pending in the exchanges/brokers computes.



          Senerio 2) NinjaTrader shutdown/restart.

          a) Shutdown event.

          Seems like not much we can do here. Assuming a crash or power failure.

          b) NinjaTrader restart event.

          Perhaps in the initalization code we could check the broker and do basically 1b above. I guess there are complicating factors such as if multiple stategies are running we need to parse out the brokers reply to each particular running strategy.




          Comment


            #20
            imported post

            Cbi.Position myPosition = Account.Positions.FindByInstrument(Instrument instrument);
            if (myPosition != null)
            // There is a broker position

            I am missing the syntax to make this statement work!

            NinjaTrader.Cbi is loaded with using. Cbi.Position is?

            myPosition - user defined variable, type? bool?

            Account.Positions.FindByInstrument("requires input here")

            (Instrument instrument) to me means that there is a type "Instrument"?

            I have no idea how to get this to work.

            Needs something like inst = get.Instrument.

            No idea...


            Comment


              #21
              imported post

              Oli,

              Create a strategy and insert the following code:

              Cbi.Position myPosition = Account.Positions.FindByInstrument(Instrument);
              if (myPosition != null)
              Print(myPosition.Quantity);
              else
              Print("There is no position");


              Run on a chart and view the output window.

              Ray
              RayNinjaTrader Customer Service

              Comment


                #22
                imported post

                trying to get this to work today... ignore previous post here...


                Comment


                  #23
                  imported post

                  OK - this code works, but Quantity alone is not sufficient. I need something like: Side, ie 1S or 1L. It is not enough to know that the position is open.

                  Are there extensions to Account.Positions other than Quantity?

                  Comment


                    #24
                    imported post

                    Please check out the myPosition.MarketPosition property which indicates the market side.

                    Comment


                      #25
                      imported post


                      I seem to get weird results when using MarketPosition as a property of myPosition:





                      Cbi.Position myPosition = Account.Positions.FindByInstrument(Instrument);

                      if (myPosition != null){

                      Print(myPosition.Quantity);

                      Print(myPosition.MarketPosition);

                      }

                      else{

                      Print(
                      "There is no position");

                      Print(myPosition);

                      }
                      Attached Files

                      Comment


                        #26
                        imported post

                        Please consult the docs: Print() accepts string, double, int and bool values but not type NinjaTrader.Data.MarketPosition nor NinjaTrader.Cbi.Position. You need to convert the information you want to print out to string or double or int or bool values.

                        Please try e.g.
                        Code:
                        Print ((int)myPosition.MarketPosition);
                        Print(myPosition.ToString());

                        Comment


                          #27
                          imported post

                          Thanks Dierk,

                          the solution for those in need:

                          XX = myPosition.MarketPosition.ToString();

                          Dierk, is there any way you could post here what other Properties would be available to myPosition in the current context?

                          Comment


                            #28
                            imported post

                            Real simple: Just start typing "myPosition." in NinjaScript editor and IntelliSense window pops up and shows you what's available (including documentation). This is true for any NinjaScript object.

                            Also: please make sure you are on latest NT6B10.

                            Comment


                              #29
                              imported post

                              Got it - thanks

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by junkone, Today, 11:37 AM
                              2 responses
                              15 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by frankthearm, Yesterday, 09:08 AM
                              12 responses
                              44 views
                              0 likes
                              Last Post NinjaTrader_Clayton  
                              Started by quantismo, 04-17-2024, 05:13 PM
                              5 responses
                              35 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by proptrade13, Today, 11:06 AM
                              1 response
                              7 views
                              0 likes
                              Last Post NinjaTrader_Clayton  
                              Started by love2code2trade, 04-17-2024, 01:45 PM
                              4 responses
                              36 views
                              0 likes
                              Last Post love2code2trade  
                              Working...
                              X