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 bortz, 11-06-2023, 08:04 AM
        47 responses
        1,608 views
        0 likes
        Last Post aligator  
        Started by jaybedreamin, Today, 05:56 PM
        0 responses
        9 views
        0 likes
        Last Post jaybedreamin  
        Started by DJ888, 04-16-2024, 06:09 PM
        6 responses
        19 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by Jon17, Today, 04:33 PM
        0 responses
        6 views
        0 likes
        Last Post Jon17
        by Jon17
         
        Started by Javierw.ok, Today, 04:12 PM
        0 responses
        16 views
        0 likes
        Last Post Javierw.ok  
        Working...
        X