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 funk10101, Today, 09:43 PM
        0 responses
        6 views
        0 likes
        Last Post funk10101  
        Started by pkefal, 04-11-2024, 07:39 AM
        11 responses
        37 views
        0 likes
        Last Post jeronymite  
        Started by bill2023, Yesterday, 08:51 AM
        8 responses
        44 views
        0 likes
        Last Post bill2023  
        Started by yertle, Today, 08:38 AM
        6 responses
        26 views
        0 likes
        Last Post ryjoga
        by ryjoga
         
        Started by algospoke, Yesterday, 06:40 PM
        2 responses
        24 views
        0 likes
        Last Post algospoke  
        Working...
        X