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

Tracking position and orders stats

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

    Tracking position and orders stats

    Hi!

    I need from my script (indicator or a strategy), to keep track of the open position of my manual orders or via ATM, such as knowing the average price all the time.

    I understand the "Position" object of my script is not able to know from the entries that I make manually or ATM, so what I am doing is evaluating all the filled orders and doing my own calculations.

    My current problem is that I have orders with the value of quantity/filled/remaining at zero, being orders that were executed and filled, which makes it difficult for me to calculate, for example, the average price...

    First question, why is this happening? Second question, is there another simpler alternative to track my position other than evaluating all the orders in the account?​

    thanks in advance!

    Attached Files

    #2
    Hello PabloDea,

    Correct, a strategy position and order method overrides are only affected by orders submitted by that instance of the strategy. Manual orders and orders through Atm Strategy methods, or from other instances of strategies are not seen by the strategy instance.

    You can add handler methods to the account position update event, and account order update events to trigger actions for all orders that affect the account.





    I would not expect these orders with a quantity of 0 to be allowed for manual orders, and I was not able to reproduce this on my end using 8.1.1.1.
    Testing, I am finding Chart Trader, the SuperDOM, and Basic Entry window will revert to a minimum quantity of 1 when manually typing in a 0 for the quantity.

    May I confirm you are on the latest release, 8.1.1.1?

    Are you able to reproduce these orders with a quantity of 0 with manual orders?

    Are these orders from a NinjaScript?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      thanks Chelsea,

      I confirm I am on latest release 8.1.1.1

      The orders are manual orders and ATM orders. I usually enter through an ATM strategy and then I put some extra orders manually.
      After that, into the current position opened, I want to check avg prices, margin risk etc etc from my script (indicator) .. for that I am looping through account orders using "foreach (Order order in myAccount.Orders)..."

      I am going to check the events you recommend.
      For example the first one, OnPositionUpdate can access to position when I put my orders manually or via ATM?
      That´s the point, I need to do manual or atm orders .

      thanks again!
      Pablo

      Comment


        #4
        Hello Pablo,

        Yes, manual orders and atm orders affect the account.

        This will update the Account.PositionUpdate event as advised in post # 2.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thanks Chelsea,

          another related question about OnOrderUpdate we talk in previous posts. The event fires many times even with old prints I use to debug. I sense that events are queued and are not being removed correctly. I'm using State.Terminated to dettach the event.


          My script

          Code:
          protected override void OnStateChange()
                  {
                      if (State == State.SetDefaults)
                      {
                         ......
                         lock (Account.All)
                             myAccount = Account.All.FirstOrDefault(a => a.Name == "Playback101");
          
                          if (myAccount != null)
                          {
                              myAccount.OrderUpdate += OnOrderUpdate;
                          }
                        ....
                    }
                    else if (State == State.Terminated)
                    {
                        myAccount.OrderUpdate -= OnOrderUpdate;
                    ​​}
               }
          
          private void OnPositionUpdate(object sender, PositionEventArgs e)
          {
           ....
          Print("here show old texts too");​
          }
          Is it ok to remove the event like this?
          How can I prevent it from firing many times?​

          thanks again!
          Pablo

          Comment


            #6
            Hello Pablo,

            Yes, any event handler method must be removed from the event handler in State.Terminated.

            In the code sample in the help guide, this is in the Cleanup() method as the code sample is for an Addon window.

            Cleanup() in an Addon window would be the equivalent of State.Terminated in an indicator or strategy.
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Waxavi, 04-19-2024, 02:10 AM
            2 responses
            36 views
            0 likes
            Last Post poeds
            by poeds
             
            Started by chbruno, Yesterday, 04:10 PM
            1 response
            43 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by Max238, Today, 01:28 AM
            1 response
            23 views
            0 likes
            Last Post CactusMan  
            Started by giulyko00, Yesterday, 12:03 PM
            2 responses
            10 views
            0 likes
            Last Post giulyko00  
            Started by r68cervera, Today, 05:29 AM
            0 responses
            4 views
            0 likes
            Last Post r68cervera  
            Working...
            X