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

How many open positions now

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

    How many open positions now

    Hello. How to check "how many open positions now"?

    #2
    Originally posted by alexstox View Post
    Hello. How to check "how many open positions now"?
    In any one instrument, you have only one position, long, short or flat. The Position object holds the relevant data.

    If you have multiple instruments in the same strategy, you can query their individual positions with the Positions array.

    ref:

    Comment


      #3
      Hello Alex,

      Thank you for your post.

      Koganam provides the correct information here. You can check the number of positions with Position.Quantity.

      Comment


        #4
        Position.Quantity is described as "Gets the current position size.".

        Well, I need to know is entry order in market now or persist as order now. For example, I entered long via order and named it "enter 1". So, I need to check whether it in market as position OR whether it persist as order. I want to enter other long "enter 2". So, I think I should set condition "if strategy hold 1 enter" Or "if order still live or position still live". It's simple to check via "position.long" but this can contains more that 1 entry. So, how can I check whether the "enter 1" is live as order or live as position?
        Last edited by alexstox; 11-04-2013, 02:52 PM.

        Comment


          #5
          Originally posted by alexstox View Post
          Position.Quantity is described as "Gets the current position size.".

          Well, I need to know is entry order in market now or persist as order now. For example, I entered long via order and named it "enter 1". So, I need to check whether it in market as position OR whether it persist as order. I want to enter other long "enter 2". So, I think I should set condition "if strategy hold 1 enter" Or "if order still live or position still live". It's simple to check via "position.long" but this can contains more that 1 entry. So, how can I check whether the "enter 1" is live as order or live as position?
          You use OnExecution() to tell you if the order executed, and you set a state variable from the answer.

          Comment


            #6
            Hello Alex,

            Thank you for your response.

            You can use IOrder objects to track the orders in OnOrderUpdate() and check the order state to see if it is filled or not. For information on IOrder objects please visit the following link: http://www.ninjatrader.com/support/h...nt7/iorder.htm

            Please let me know if I may be of further assistance.

            Comment


              #7
              Thank you. I did so before.
              There is only one private double that is used for enter - entryOrder. Let imagine, script entered and named this enter as "Long". Sometimes conditions for further enter comes true when "Long" still present as opened position. So, in that case I'd like to enter via entryOrder as "Long1". But before do this I need to check if "Long" still present. How to check entryOrder.Name for presenting as opened position?

              Comment


                #8
                Hello Alex,

                Thank you for your response.

                As there would only be the preceding one long then Position.MarketPosition == MarketPosition.Long will check if the current position is long.

                For information on Position please visit the following link: http://www.ninjatrader.com/support/h...7/position.htm

                Please let me know if I may be of further assistance.

                Comment


                  #9
                  Well. Thanks. But it's not solution! I think it could be few decisions.
                  First, by using Position.Quantity. Especially when use DefaultQuantity in entry orders. For example, if by default I enter with 1 contract, then quantity of contracts = number of entries (positions).

                  Second,
                  Code:
                  .....
                  private int PositionsQuantity = 0; //to calculate # of opened positions 
                  .....
                  protected override void OnExecution(IExecution execution)
                          {
                  	if (entryOrder != null && entryOrder == execution.Order)
                  		{
                  		if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0)) 
                  				{
                  				PositionsQuantity = PositionsQuantity + 1;
                  ......................
                  //than in OnExecution() check for exit order filling. and if filled, 
                  if (trailOrder != null && trailOrder == execution.Order)
                  		{
                  		if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled)
                  			{
                  			PositionsQuantity = PositionsQuantity - 1;
                  			}

                  Comment


                    #10
                    Please comment is this correct?

                    Add later: this is bad idea! Because first or other entries could exits different way.

                    Add later: the QUESTION is

                    1. how to identify the position?! For example, if I entered with entryOrder.Name == "Long", so I have 1 long position that I can't identify. After entryOrder = null,position still present. But I enter second time entryOrder.Name == "Long1". And as earlier after order was filled, it reset to null. There are 2 positions. How to identify each of them?
                    Last edited by alexstox; 11-07-2013, 06:40 AM.

                    Comment


                      #11
                      Hello Alex,

                      Thank you for your response.

                      There is no identifier for the individual position, the positions are added or subtracted when the order is filled. The overall count for the Position can be viewed as Position.Quantity, checking this value will let you know if it has increased or decreased.

                      Please let me know if I may be of further assistance.

                      Comment


                        #12
                        So, how can I handle trail orders in that case?

                        Comment


                          #13
                          Hello Alex,

                          Thank you for your response.

                          You can use SetTrailStop() to trail the market: http://www.ninjatrader.com/support/h...ttrailstop.htm

                          Please let me know if I may be of further assistance.

                          Comment


                            #14
                            Originally posted by NinjaTrader_PatrickH View Post
                            Hello Alex,

                            Thank you for your response.

                            You can use SetTrailStop() to trail the market: http://www.ninjatrader.com/support/h...ttrailstop.htm

                            Please let me know if I may be of further assistance.
                            NO! I can't. Because of many reasons. One of the most important reasons liveUntilCancel opportunity. That's why I use IOrders. What you can advise else?

                            Comment


                              #15
                              Hello Alex,

                              Thank you for your response.

                              Use an Exit() method and your own calculations and conditions to adjust the order. Use the same IOrder for each adjustment of the "trailing stop".

                              Please let me know if I may be of further assistance.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by tkaboris, Today, 05:13 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post tkaboris  
                              Started by GussJ, 03-04-2020, 03:11 PM
                              16 responses
                              3,281 views
                              0 likes
                              Last Post Leafcutter  
                              Started by WHICKED, Today, 12:45 PM
                              2 responses
                              19 views
                              0 likes
                              Last Post WHICKED
                              by WHICKED
                               
                              Started by Tim-c, Today, 02:10 PM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by Taddypole, Today, 02:47 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post Taddypole  
                              Working...
                              X