• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ExitShortStopMarket after limit order, Position.MarketPosition incorrect

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

    ExitShortStopMarket after limit order, Position.MarketPosition incorrect

    I have a problem in which I would like to wait until the limit entry order is filled before placing a stop exit order (since the NT8 documentation says the stop exit order will be ignored if no position exists). Assuming this documentation is accurate, it really complicates entering the stop exit order. The reason is because even though the EnterShortLimit has executed, and filled, somehow Position.MarketPosition == MarketPosition.Short still reads out as false, and my ExitShortStopMarket "if" statement never executes.

    So I see three possibilities:
    1) I execute the ExitShortStopMarket immediately after the entry. However, the entry may not have filled, so in this case it will be ignored, and this "if" Entry statement will never be entered again as shown below, because I don't want it to.
    2) I execute the ExitShortStopMarket in the "if" statement as shown in my code below, but this fails to enter because MarketPosition.Short is never turning true (even though my account reflects a successful entry).
    3) I execute the ExitShortStopMarket on every bar update after entry. I don't want to try this, because I don't know if it will repeat these stop orders throughout the rest of the bar. Is there some description of what the behavior would be if I am short 100 shares, then this executes repeatedly (multiple hundreds of times) to Exit those 100 shares in a stop order?

    Please advise how to get around this problem and get my Stop Exit orders to work! Thanks

    Code:
    protected override void OnBarUpdate()
    {
    
    if (BarsInProgress != 0) 
    	return;
    
    if (CurrentBars[0] < 1)
    	return;
    			
    			
    if (State == State.Realtime) 
    {
    	if (IsFirstTickOfBar)
    	{
    		TradeCounter = 0;	
    	}
            if (TradeCounter < 1 && Position.MarketPosition == MarketPosition.Flat) 
    	{
    		TriggerPrice = Close[0];
    		NumShares = Convert.ToInt32(PosSize/TriggerPrice);
    		TradeCounter++;
    		EnterShortLimit(NumShares, TriggerPrice);
            }
            if (TradeCounter == 1 && Position.MarketPosition == MarketPosition.Short)
    	{
    		TradeCounter++;
    		ExitShortStopMarket(NumShares, TriggerPrice*1.2);
    	}
    }
    }

    #2
    Hello dcschultz,

    You are correct. When calling an entry order the order has not been submitted, accepted, become working, filled, and then the position updated. This does take time and it is not instant.

    I would recommend placing the exit orders after the entry has filled in OnExecutionUpdate() or in OnPositionUpdate

    Below is a link to an example.
    https://ninjatrader.com/support/foru...345#post521345

    As well as publicly available links to the help guide.
    https://ninjatrader.com/support/help...tionupdate.htm
    https://ninjatrader.com/support/help...tionupdate.htm
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by chazyang, Today, 08:11 AM
    1 response
    2 views
    0 likes
    Last Post NinjaTrader_PatrickG  
    Started by Erwin Beckers, 11-04-2018, 02:39 AM
    6 responses
    77 views
    2 likes
    Last Post koganam
    by koganam
     
    Started by sergey_z, Today, 02:34 AM
    3 responses
    14 views
    0 likes
    Last Post NinjaTrader_PaulH  
    Started by frankduc, Today, 05:24 AM
    4 responses
    16 views
    0 likes
    Last Post frankduc  
    Started by shmarola, Today, 01:01 AM
    0 responses
    4 views
    0 likes
    Last Post shmarola  
    Working...
    X