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 rhyminkevin, Today, 04:58 PM
    4 responses
    52 views
    0 likes
    Last Post dp8282
    by dp8282
     
    Started by iceman2018, Today, 05:07 PM
    0 responses
    5 views
    0 likes
    Last Post iceman2018  
    Started by lightsun47, Today, 03:51 PM
    0 responses
    7 views
    0 likes
    Last Post lightsun47  
    Started by 00nevest, Today, 02:27 PM
    1 response
    14 views
    0 likes
    Last Post 00nevest  
    Started by futtrader, 04-21-2024, 01:50 AM
    4 responses
    50 views
    0 likes
    Last Post futtrader  
    Working...
    X