Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnPositionUpdate - MarketPosition parameter - what's it good for?

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

  • sledge
    replied
    Originally posted by NinjaTrader_Dave View Post
    There is another nuance to keep in mind which has changed from the NinjaTrader 7 implementation of the IPosition interface. The Position object passed into OnPositionUpdate() does have a MarketPosition attached to it (position.MarketPosition), but this represents the state of the position before OnPositionUpdate() is called.

    OnPositionUpdate() is essentially updating the Position object passed into it, based on the MarketPosition object passed into it. So, at the moment that OnPositionUpdate() is triggered, the MarketPosition object represents the core position at that time, and the Position object has not yet been updated, so testing "position.MarketPosition" should always tell you what the position was before OnPositionUpdate() is called.
    This is in Playback - Market Replay.

    The documentation definitely needs updated as the code is referencing NT7 shtako and no longer relevant as when you are inside OnPositionUpdate () position.MarketPosition is old when a StopLoss triggers.

    p.s. I think there's an issue here.



    Code:
    protected override void OnPositionUpdate(Position position, double averagePrice, int quantity,	 MarketPosition marketPosition )
    		{
     
    			Print ( "1a marketPosition=" + marketPosition.ToString() );
    			Print ( "1b position.MarketPosition=" + position.MarketPosition.ToString() );
    Output On Long Position IN OnPositionUpdate:

    1a marketPosition=Long
    1b position.MarketPosition=Long

    Output on StopLoss triggered IN OnPositionUpdate:

    1a marketPosition=Flat
    1b position.MarketPosition=Long

    Leave a comment:


  • sledge
    replied
    Originally posted by NinjaTrader_Dave View Post
    There is another nuance to keep in mind which has changed from the NinjaTrader 7 implementation of the IPosition interface. The Position object passed into OnPositionUpdate() does have a MarketPosition attached to it (position.MarketPosition), but this represents the state of the position before OnPositionUpdate() is called.

    OnPositionUpdate() is essentially updating the Position object passed into it, based on the MarketPosition object passed into it. So, at the moment that OnPositionUpdate() is triggered, the MarketPosition object represents the core position at that time, and the Position object has not yet been updated, so testing "position.MarketPosition" should always tell you what the position was before OnPositionUpdate() is called.
    Ok thanks. That makes me feel a little better that's is not a threading issue. I'll check it out tonight again.

    Leave a comment:


  • NinjaTrader_DaveI
    replied
    There is another nuance to keep in mind which has changed from the NinjaTrader 7 implementation of the IPosition interface. The Position object passed into OnPositionUpdate() does have a MarketPosition attached to it (position.MarketPosition), but this represents the state of the position before OnPositionUpdate() is called.

    OnPositionUpdate() is essentially updating the Position object passed into it, based on the MarketPosition object passed into it. So, at the moment that OnPositionUpdate() is triggered, the MarketPosition object represents the core position at that time, and the Position object has not yet been updated, so testing "position.MarketPosition" should always tell you what the position was before OnPositionUpdate() is called.

    Leave a comment:


  • NinjaTrader_DaveI
    replied
    Hello,

    It sounds like the confusion is coming from the fact that you are making reference to the MarketPosition enum within the cbi class itself, rather than the instance passed into OnPositionUpdate. Within OnPositionUpdate, "marketPosition" will be a specific instance with relevant values, while "MarketPosition" will refer to the enum type itself.

    So, you will need to compare the enum value of the instance to one of the MarketPosition values, like so:

    Code:
    protected override void OnPositionUpdate(Position position, double averagePrice, int quantity, MarketPosition marketPosition)
            {
                base.OnPositionUpdate(position, averagePrice, quantity, marketPosition);
    
                if (marketPosition == MarketPosition.Flat)
                    Print("position flat");
            }

    Leave a comment:


  • sledge
    replied
    Had to change my code to and suffer a ToString call.

    So I don't think the old way really works fully anymore:






    Code:
    			if (marketPosition.ToString()[0] == 'F' )
    			//if (position.MarketPosition == MarketPosition.Flat)
    			{
    				...
    
    			}
    			else if (marketPosition.ToString()[0] == 'L' )
    			//else if (position.MarketPosition == MarketPosition.Long)
    			{
    				...
    			}
    			else if (marketPosition.ToString()[0] == 'S' )
    			//else if (position.MarketPosition == MarketPosition.Short)
    			{
    				...
    			}

    Leave a comment:


  • sledge
    replied
    Interesting - my stoploss HIT, but OnPositionUpdate was clueless to the fact.

    The marketPosition parameter is correct, cbi.Ninjatrader.MarketPosition is wrong. (And that might be why Unrealized/Realized were both displaying information at the same time).

    So this feels more like a bug report now.


    1 OnPositionUpdate.marketPosition=Flat
    2 OnPositionUpdate.MarketPosition=LONG

    Leave a comment:


  • sledge
    replied
    I squeezed in a test...

    Code:
    Print ( "1 OnPositionUpdate.marketPosition=" + marketPosition.ToString() );
    
    if (position.MarketPosition == MarketPosition.Long)
    {
    	Print ( "2 OnPositionUpdate.MarketPosition=" + "LONG" );
    Result:

    1 OnPositionUpdate.marketPosition=Long
    2 OnPositionUpdate.MarketPosition=LONG

    Leave a comment:


  • OnPositionUpdate - MarketPosition parameter - what's it good for?

    Just wondering...

    Is it just to have a String of the MarketPosition?

    I can't access Flat/Long/Short in it, I have to use "Ninjatrader.Cbi.MarketPosition".



    Code:
    	protected override void OnPositionUpdate(Position position, double averagePrice, int quantity,
    									 MarketPosition marketPosition )

Latest Posts

Collapse

Topics Statistics Last Post
Started by cmtjoancolmenero, Yesterday, 03:58 PM
11 responses
39 views
0 likes
Last Post cmtjoancolmenero  
Started by FrazMann, Today, 11:21 AM
0 responses
3 views
0 likes
Last Post FrazMann  
Started by geddyisodin, Yesterday, 05:20 AM
8 responses
52 views
0 likes
Last Post NinjaTrader_Gaby  
Started by DayTradingDEMON, Today, 09:28 AM
4 responses
26 views
0 likes
Last Post DayTradingDEMON  
Started by George21, Today, 10:07 AM
1 response
22 views
0 likes
Last Post NinjaTrader_ChristopherJ  
Working...
X