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 andrewtrades, Today, 04:57 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by chbruno, Today, 04:10 PM
        0 responses
        6 views
        0 likes
        Last Post chbruno
        by chbruno
         
        Started by josh18955, 03-25-2023, 11:16 AM
        6 responses
        436 views
        0 likes
        Last Post Delerium  
        Started by FAQtrader, Today, 03:35 PM
        0 responses
        7 views
        0 likes
        Last Post FAQtrader  
        Started by rocketman7, Today, 09:41 AM
        5 responses
        19 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X