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

Account.PositionUpdate event parameter problem

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

    Account.PositionUpdate event parameter problem

    For Account.PositionUpdate Event, it's PositionEventArgs.MarketPosition has different value between Sim account and Live account.

    someAccount.PositionUpdate += OnPositionUpdate;

    private void OnPositionUpdate(object sender, PositionEventArgs e)
    {
    Print(string.Format("e.Operation={0}, e.MarketPosition={1}", e.Operation, e.MarketPosition);
    }
    Take 6B future for example:

    Buy 1 then sell 1 via Sim101 account:
    e.Operation=Add, e.MarketPosition=Long
    e.Operation=Remove, e.MarketPosition=Flat
    Buy 1 then sell 1 via Live account:
    e.Operation=Add, e.MarketPosition=Long
    e.Operation=Remove, e.MarketPosition=Short
    same close position operation but the e.MarketPosition is different, why?
    My live account provider is Continuum.
    Last edited by jjhou; 02-16-2017, 07:57 AM.

    #2
    Hello jjhou,

    Thank you for your note.

    Please see the following link under Multi-threaded consideration for an explanation of why this can happen.



    Using position.MarketPosition would yield the most current position.

    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Well, I added more detailed output to print, see the following:

      Buy 1 then sell 1 via Sim101 account:
      buy event: e.Operation=Add, e.MarketPosition=Long, e.Position.MarketPosition=Long, e.Quantity=1, e.Position.Quantity=1

      sell event: e.Operation=Remove, e.MarketPosition=Flat, e.Position.MarketPosition=Long, e.Quantity=0, e.Position.Quantity=1
      Buy 1 then sell 1 via Live account:
      buy event: e.Operation=Add, e.MarketPosition=Long, e.Position.MarketPosition=Long, e.Quantity=1, e.Position.Quantity=1

      sell event: e.Operation=Remove, e.MarketPosition=Short, e.Position.MarketPosition=Long, e.Quantity=0, e.Position.Quantity=1
      See? for the live account, e.Position.MarketPosition is not Flat neither.
      I don't think it's the multi-threaded caused, because I only have 1 long positon, it's impossible to have multiple partial position changes; and for this statement in the help document:
      Of course, the OnPositionUpdate() method parameters will eventually receive the event for "Flat" in the sequence the events were received.
      I received only one event when I close position, as you see above (the 2nd line printed) , no more events received, I didn't see any Flat value for live account.
      So I think it's a bug.

      By the way, my code is in an indicator, not a strategy.
      Last edited by jjhou; 02-19-2017, 10:02 PM.

      Comment


        #4
        Hello jjhou,

        In the helpguide link I provided, it mentions “events back from the broker API on thread "B". Given the SIM101 account does not have any information coming back from a broker API, you could expect this multithreading issue not to occur with the SIM101 account however may occur with the live account. Sim vs live does present a different thread.

        Please let us know if you need further assistance.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          OK. But for this one:
          Of course, the OnPositionUpdate() method parameters will eventually receive the event for "Flat" in the sequence the events were received.
          I consider it as I will receive a event with some parameter='Flat' eventually no matter what multi-thread context is, Have I understood correctly? I have never received one like that, never.

          Comment


            #6
            Hello jjhou,

            We are currently investigating and I will follow up when we have more information.

            Thank you for your patience.
            Alan P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by RubenCazorla, Today, 09:07 AM
            1 response
            5 views
            0 likes
            Last Post RubenCazorla  
            Started by Irukandji, Today, 09:34 AM
            0 responses
            3 views
            0 likes
            Last Post Irukandji  
            Started by TraderBCL, Today, 04:38 AM
            3 responses
            25 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by WeyldFalcon, 08-07-2020, 06:13 AM
            11 responses
            1,423 views
            0 likes
            Last Post jculp
            by jculp
             
            Started by BarzTrading, Today, 07:25 AM
            2 responses
            29 views
            1 like
            Last Post BarzTrading  
            Working...
            X