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

PositionEventArgs and nested Position property differ

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

    PositionEventArgs and nested Position property differ

    The entry was long, then I hit the Closse button, or a Sell Mkt button matching the same quantity, and this code gives me conflicting values:
    Code:
    void OnPositionUpdate(object sender, PositionEventArgs e){
    	try{
    		_Dispatcher.InvokeAsync(() => {
    			Print(string.Format("e.MarketPosition: {0}", e.MarketPosition));
    			Print(string.Format("e.Position.MarketPosition: {0}", e.Position.MarketPosition));
    		});
    	}catch (Exception error){ _Dispatcher.InvokeAsync(() => Print(error.ToString())); }
    }
    Shouldn't these two values be the same? Output:
    e.MarketPosition: Flat
    e.Position.MarketPosition: Long
    Why are the properties of the nested Position member of the PositionEventArgs instance different.

    #2
    Hello xcondor,

    Thanks for your inquiry.

    Considering the help guide documentation for Account.PositionUpdate suggests to use PositionEventArgs.MarketPosition and the result is what we would expect, I would suggest moving forward with e.MarketPosition.

    Nonetheless, since there is not any clear documentation on PositionEventArgs and expected usage, I am consulting with Product Management on the matter.

    I'll update this post as more information becomes available.
    JimNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Jim View Post
      Nonetheless, since there is not any clear documentation on PositionEventArgs and expected usage, I am consulting with Product Management on the matter.
      It appears that e.Position is the position from BEFORE the update event fired.

      Comment


        #4
        Hello xcondor,

        Position.MarketPosition is the position that gets added or removed. If we add a print for e.ToString(), we can see the Add and Remove operations.

        instrument='ES 06-18' account='Sim101' avgPrice=2671.75 quantity=1 marketPosition=Long operation=Add
        e.MarketPosition: Long
        e.Position.MarketPosition: Long

        instrument='ES 06-18' account='Sim101' avgPrice=0 quantity=0 marketPosition=Flat operation=Remove
        e.MarketPosition: Flat
        e.Position.MarketPosition: Long
        Upon entering with a Buy Market, we see the current MarketPosition read as long, and an operation of adding a long Position.MarketPosition is seen.

        Upon exiting with a Sell Market, we see the current MarketPosition read as flat, and an operation of removing a long Position.MarketPosition is seen.

        If you have any additional questions, please don't hesitate to ask.
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by mjairg, 07-20-2023, 11:57 PM
        3 responses
        213 views
        1 like
        Last Post PaulMohn  
        Started by TheWhiteDragon, 01-21-2019, 12:44 PM
        4 responses
        544 views
        0 likes
        Last Post PaulMohn  
        Started by GLFX005, Today, 03:23 AM
        0 responses
        3 views
        0 likes
        Last Post GLFX005
        by GLFX005
         
        Started by XXtrader, Yesterday, 11:30 PM
        2 responses
        12 views
        0 likes
        Last Post XXtrader  
        Started by Waxavi, Today, 02:10 AM
        0 responses
        7 views
        0 likes
        Last Post Waxavi
        by Waxavi
         
        Working...
        X