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

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.
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by ageeholdings, Today, 07:43 AM
    0 responses
    2 views
    0 likes
    Last Post ageeholdings  
    Started by pibrew, Today, 06:37 AM
    0 responses
    4 views
    0 likes
    Last Post pibrew
    by pibrew
     
    Started by rbeckmann05, Yesterday, 06:48 PM
    1 response
    14 views
    0 likes
    Last Post bltdavid  
    Started by llanqui, Today, 03:53 AM
    0 responses
    6 views
    0 likes
    Last Post llanqui
    by llanqui
     
    Started by burtoninlondon, Today, 12:38 AM
    0 responses
    12 views
    0 likes
    Last Post burtoninlondon  
    Working...
    X