Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

IPosition

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

    IPosition

    I would like to confirm the meaning of AvgPrice in the following scenario:
    Code:
    protected override void OnPositionUpdate(IPosition position)
    { 
        if (position.MarketPosition == MarketPosition.Flat)
        {
            double px = position.AvgPrice;
        }
    }
    Once position becomes flat and hits this code, px will be the price at which the position became flat, is that correct? For example, go long at 48.00 with a 10 tick target (via SetProfitTarget). Price goes to 48.10 and gets filled. px = 48.10.
    Please confirm.
    Thank you

    #2
    Hello,

    Thank you for the question.

    This is a good item to Test using a Print statement on your end in a blank strategy to see the output and what happens.

    I tested this on my end using EnterLong and ExitLong and a 0 is reported when you are flat because this is only reporting the Position at that time, when you change to flat it reports 0 because the order that called this was an exit which made the position flat.

    Printing without the check to see if you are flat, the Entry will call this method and report its avg fill price.

    Here is a simple test you can do on your side to test other conditions to see how this will ultimately perform:

    Code:
    protected override void OnBarUpdate()
    {
    	if(Position.MarketPosition == MarketPosition.Flat)
    	{
    		EnterLong();
    	}
    	if(Position.MarketPosition != MarketPosition.Flat && BarsSinceEntry() > 2)
    	{
    		ExitLong();
    	}
    }
    		
    protected override void OnPositionUpdate(IPosition position)
    { 
    		double px = position.AvgPrice;
    		Print(px);
    }
    Please let me know if I may be of additional assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    633 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    364 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    105 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    567 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    568 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X