Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Why do IExecution and IPosition show opposite positions?

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

    Why do IExecution and IPosition show opposite positions?

    So, I've been heavily into watching and studying what is printed
    to my NT7 log file, and I've noticed something that strikes me as
    a bit odd, perhaps even a bug.

    Why does the IExecution.MarketPosition property sometimes differ
    from the IPosition.MarketPosition?

    Basically, as shown in this annotated screenshot of my NT7
    log file (populated with results from running a strategy called
    XXX_20 on Sim101), lines 36 and 44 (stamped with red 1 and
    2, respectively) are printed into NT7 log by NinjaTrader itself.

    But I recognize these 2 lines with red dots as the string from
    IExecution.ToString(), see here,


    IPosition also supports ToString(), see here


    As you can see from the help guide, both IExecution and IPosition
    contain a MarketPosition property. It looks to me like IExecution's
    MarketPosition gets out of sync, as witnessed by attached log file.

    Explanation of log file:
    The strategy XXX_20 was trading a long position, entered 2 orders
    long, and then submitted a stop and target for each order when they
    were filled in OnExecution.

    In the attached screenshot, you can see at line 31 the stop was moved
    for the 2nd order.

    But my comment is about when the stop orders are filled, which occurs
    at lines 36 & 44. I added red dots to those lines.

    Look at the "position=" reported at red dot #1 and red dot #2 ...

    They should say "long", not "short".

    Notice how all the other positions being reported by IPosition.ToString()
    and IExecution.ToString() correctly report position is "long".

    So why does IExecution.MarketPosition report "short" at the red dots?

    Looks like a bug to me.
    Attached Files

    #2
    Hello bltdavid,

    Thank you for your post.

    The Execution shows what side of the market the order was for. For example a Sell Limit to close a certain quantity would be filled as short for market position of the execution. This is not the market position of the instrument or account.

    Comment


      #3
      Yeah, that's what I thought you'd say ..

      Ok, so let me tell you how I really feel.

      I love NinjaTrader, so don't take any of this the wrong way.

      But ...

      This has gotta be the dumbest stupidest answer on so many levels.
      From a support perspective, sure, that's your answer. But from
      an engineering perspective, this is an asinine idiotic response.

      Let me count the ways:

      1. The documentation for IExecution does not provide any detail
      what MarketPosition means. An oversight, and borderline dumb.

      2. The documentation for IPosition does not provide any details
      what MarketPosition means. An oversight, and borderline dumb.

      3. Why would the same property names in these 2 classes have
      totally different meanings? Monumentally stupid design choice
      on part of engineering.

      4. Everywhere else MarketPosition is used it reflects, well, the current
      market direction of the position you have in the market. Why the heck
      does it get reused in IExecution in a way that creates a disconnect from
      the normal and expected use of all other cases? Sorry, rehashing #3.

      5. Oh yeah, we have a global object called "Position" which contains a
      property called "MarketPosition" ... and it is actually documented in
      the help guide to mean ... drum-roll ... the current market position!
      Sorry, I'm still channeling my explanation in #4 ...

      6. But engineers aren't always stupid (heck, I'm an engineer, and some
      of the smartest people I've met are also engineers) ... so I suspect that
      #3 is not by choice, and the resulting disconnect of what MarketPosition
      means in IExecution is actually a low-grade bug, probably unintentional.

      Or, perhaps its acceptance has been exacerbated over time by legacy
      and neglect -- or maybe the engineer code review process at the time
      failed to detect this misuse and no one has ever complained -- or maybe
      it was detected by the code review but was deemed acceptable due to
      the internal nature of NT7 log file's purpose. Well, it is not *that* internal,
      this *is* customer facing, visible in the log file and documented (albeit
      incompletely) in the help guide. Thus, by that definition, this is more of
      a bug. Sure, low priority and no real impact, but still: it causes confusion
      for strategy programmers. And that confusion is not corrected by the
      documentation.

      So, in retrospect, this reuse of MarketPosition in IExecution to mean the
      direction, (aka buy or sell) is deeply idiotic, and serves to create and
      even promote a confusing situation. Why? Because of the common
      assumption that is easily made due to reuse of an already well established
      property name (MarketPosition) that has an easily guessed meaning is
      completed redefined and reused wrongly in IExecution.

      Instead of re-using MarketPosition, you should have re-used OrderAction,
      and the possible values would have been Buy or Sell. This would have
      been clearer, and would not cause any confusion whatsoever.

      Or create a new enum, call it MarketAction,

      Code:
      public enum MarketAction
      {
           Buy,
           Sell,
      }
      then let IExecution show "action=Sell" or "action=Buy" .. again much
      clearer because there would be absolutely no confusion.

      Anyways, still love NinjaTrader, just ranting on the poor choice made by
      the original designers (Sorry Ray, if that was you ... I'm sure IExecution
      has a long history and has been around from the beginning, my bad).

      Patrick, I hear ya, I know what you're saying. But I still consider this
      more a bug. Its behavior may be consistent in how you describe its
      use in IExecution (or it really would be a bug), but this reuse of the
      name "MarketPosition" still smells kinds fishy and certainly stinks of
      a poor choice made somewhere in the past.

      Phew, ok then, show's over. Wow, twas a good rant, I feel better.

      Quick, let me duck to avoid the boos and bottles being thrown, I gotta
      get back to coding my NinjaScript strategy anyways.
      Last edited by bltdavid; 10-16-2015, 04:51 PM.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by yertle, Today, 08:38 AM
      5 responses
      14 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by frankthearm, Today, 09:08 AM
      2 responses
      4 views
      0 likes
      Last Post frankthearm  
      Started by adeelshahzad, Today, 03:54 AM
      3 responses
      16 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by bill2023, Yesterday, 08:51 AM
      6 responses
      27 views
      0 likes
      Last Post NinjaTrader_Erick  
      Started by NinjaTrader_ChelseaB, 01-08-2017, 06:59 PM
      80 responses
      19,667 views
      5 likes
      Last Post NinjaTrader_ChelseaB  
      Working...
      X