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

Get Price of pending Limit Order and use it for further calculations

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

    Get Price of pending Limit Order and use it for further calculations

    Hello,

    I want to develop an Indicator which detects the Price Level of a current Limit Order. The Price Level will be used for further calculations.

    The Limit Order will be set manually in the Chart Trader.
    I tried to use the IOrder based on the examples in the NT Help Files, but could not solve the issue.

    What would be the right syntax to get the price?

    Thank You!
    Helmut

    #2
    Hello Tradix10,

    Thank you for writing in.

    Here is some sample undocumented code on how you can obtain the limit price of all of your working orders placed on the Sim101 account:

    Code:
    protected override void OnBarUpdate()
    {
         foreach (Account acct in Cbi.Globals.Accounts)
         {
              if (acct.Name == "Sim101")
              {
                   OrderCollection orders = acct.Orders;
                   foreach (Order order in orders)
                   {
                        if (order.OrderState == OrderState.Working)
                             Print(order.LimitPrice);
                   }
              }
         }
    }
    Please, let us know if we may be of further assistance.
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      Thanks Zachary,

      this is what I was looking for. Code works.
      Further question: Is it possible to get the Information whether the order is a Short or a Long order?

      Hint for Other Programers: In Indicator Settings turn "Calculate on bar update" to "false" to get immediate feedback from the indicator. Otherwise You need to wait until current candle is finished.

      Best Regards
      Helmut

      Comment


        #4
        Hello Helmut,

        You can check to see if the order is a buy or sell order by:

        Code:
        Print(order.OrderAction.ToString());
        If you wish to print out all information about the order, you can do:
        Code:
        Print(order.ToString());
        Last edited by NinjaTrader_ZacharyG; 03-04-2016, 12:56 PM.
        Zachary G.NinjaTrader Customer Service

        Comment


          #5
          Hello Zachary,

          Print(OrderState.ToState.ToString()); shows just whether the order is Working

          the output is e.g.:

          9834
          Working


          Print(order.ToString()) shows all information, including buy or sell, which is too much.

          I just want get get feedback like "buy" oder "Sell".

          Thanks
          Helmut

          Comment


            #6
            Hello Helmut,

            I apologize about that; I will edit my previous post.

            What I meant was OrderAction rather than OrderState:
            Code:
            Print(order.OrderAction.ToString());
            Last edited by NinjaTrader_ZacharyG; 03-04-2016, 12:56 PM.
            Zachary G.NinjaTrader Customer Service

            Comment


              #7
              Hello Zachary,

              now it works - Thanks for Your great support!

              Best Regards
              Helmut

              Comment


                #8
                Get price of pending oders - and deactivate it, as soon as an position was opened

                Hello,

                the code in the thread below works. Now I got a new issue:

                As soon as a position is opened, I put a Profit Target and a Stopp Loss order in the system (the ATM does).

                The new issue is:
                - There is an open position and two new pending orders in the system.
                - My indicator recognizes the orders and does what he did without position.
                >> I want to stop the Indicator doing this as long as a position is open, because it is just relevant in case there is No open position.

                In other words: I would like to tell the indicator: Hey, there is an open position - stop doing what You do without an open Position. Do something different.

                I tried to do it with bool Variables (works on strategies) - but it does not work here.
                Do You habe any proposal how to solve the issue?

                Thanks,
                Helmut

                Comment


                  #9
                  Hello Helmut,

                  Thanks for your post.

                  Please see this post which has a sample account access code which would then allow you to also know/check for position: http://ninjatrader.com/support/forum...63&postcount=2
                  Paul H.NinjaTrader Customer Service

                  Comment


                    #10
                    Thanks Paul for your response.

                    I'll check the Script, my first impression looks promising.

                    Best Regards
                    Helmut

                    Comment


                      #11
                      Originally posted by Tradix10 View Post
                      Hello,

                      the code in the thread below works. Now I got a new issue:

                      As soon as a position is opened, I put a Profit Target and a Stopp Loss order in the system (the ATM does).

                      The new issue is:
                      - There is an open position and two new pending orders in the system.
                      - My indicator recognizes the orders and does what he did without position.
                      >> I want to stop the Indicator doing this as long as a position is open, because it is just relevant in case there is No open position.

                      In other words: I would like to tell the indicator: Hey, there is an open position - stop doing what You do without an open Position. Do something different.

                      I tried to do it with bool Variables (works on strategies) - but it does not work here.
                      Do You habe any proposal how to solve the issue?

                      Thanks,
                      Helmut
                      If you look at the SampleAtmStrategy that ships with NinjaTrader, you will see this snippet. It clearly shows how to determine if you are already in a position.
                      Code:
                      if (atmStrategyId.Length > 0)
                      			{
                      				// You can change the stop price
                      				if (GetAtmStrategyMarketPosition(atmStrategyId) != MarketPosition.Flat)
                      					AtmStrategyChangeStopTarget(0, Low[0] - 3 * TickSize, "STOP1", atmStrategyId);
                      
                      				// Print some information about the strategy to the output window
                      				Print("The current ATM Strategy market position is: " + GetAtmStrategyMarketPosition(atmStrategyId));
                      				Print("The current ATM Strategy position quantity is: " + GetAtmStrategyPositionQuantity(atmStrategyId));
                      				Print("The current ATM Strategy average price is: " + GetAtmStrategyPositionAveragePrice(atmStrategyId));
                      				Print("The current ATM Strategy Unrealized PnL is: " + GetAtmStrategyUnrealizedProfitLoss(atmStrategyId));
                      			}

                      Comment


                        #12
                        Thanks Koganam,
                        for the code. In this case I want the indicator itself to process the information whether there is an open position. I use the ATM just to put the profit taker and stopp loss in the system.

                        I want the indicator to change its behaviour as soon as the position is opened. It should do one thing with open Order and another thing with filled order.

                        In case it would be a strategy I would do it with a simple bool variable and if loop. This code does not work within indicators.

                        Best Regards,
                        Helmut

                        Comment


                          #13
                          Originally posted by Tradix10 View Post
                          Thanks Koganam,
                          for the code. In this case I want the indicator itself to process the information whether there is an open position. I use the ATM just to put the profit taker and stopp loss in the system.

                          I want the indicator to change its behaviour as soon as the position is opened. It should do one thing with open Order and another thing with filled order.

                          In case it would be a strategy I would do it with a simple bool variable and if loop. This code does not work within indicators.

                          Best Regards,
                          Helmut
                          For some reason, I did not realize that you wanted it to happen from an indicator. When I see any talk about positions, I think in terms of strategies. In this case, that thinking was evidently wrong. You maybe want to follow the link to the code that attaches handlers to your strategy from an indicator. (Which you say you have already done. I just wrote that in here to make it a complete response for anybody/somebody else who might not read the whole thread).

                          Comment


                            #14
                            Thanks Koganam, Your code is very helpful as I never thought about doing a more complex ATM Strategy. Maybe my idea could also be realized with an ATM Strategy. I will study it in parallel. I always tried to do things with indicators, which in this case is just a workaround.
                            Best regards
                            Helmut

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by FrancisMorro, Today, 03:24 AM
                            0 responses
                            1 view
                            0 likes
                            Last Post FrancisMorro  
                            Started by Segwin, 05-07-2018, 02:15 PM
                            10 responses
                            1,770 views
                            0 likes
                            Last Post Leafcutter  
                            Started by Rapine Heihei, 04-23-2024, 07:51 PM
                            2 responses
                            31 views
                            0 likes
                            Last Post Max238
                            by Max238
                             
                            Started by Shansen, 08-30-2019, 10:18 PM
                            24 responses
                            944 views
                            0 likes
                            Last Post spwizard  
                            Started by Max238, Today, 01:28 AM
                            0 responses
                            11 views
                            0 likes
                            Last Post Max238
                            by Max238
                             
                            Working...
                            X