Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop Loss Order Questions

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

    Stop Loss Order Questions

    Hi, Thanks in advance for shedding some light on my questions. The following code is called in OnBarUpdate() and CalculateOnBarClose = true;

    Code:
    if(Position.MarketPosition == MarketPosition.Long){	
    	 stopOrder = ExitLongStop(stopLoss,"Stop Losss Long",My_LONG);
    				   
    }
    So this would get called over and over again as long as I have a long position. What does Ninjatrader do here? does it get ignored if there is already a stop order in place? It looks almost like that if my observations are correct.

    I said "almost" because it works fine in the same trading session. However, Ninjatrader cancels the stop order, place another exactly same one if the trade spans multiple sessions even if the TIF is GTC.

    Another strange behavior is that if code is like the following, the stop order is in place for the next bar only and then gets cancelled and never generated again,




    Code:
     private IOrder stopOrder = null;
    
     protected override void OnBarUpdate(){
    	if(my condtions met){
    		EnterLong();
    		stopOrder = null;
    	}
    
    	if(Position.MarketPosition == MarketPosition.Long){	
    		if( stopOrder == null;)
    		   stopOrder = ExitLongStop(stopLoss,"Stop Losss Long",My_LONG);
    					   
    	}
    
    }

    #2
    Hello sys_trader,

    Thanks for your post.

    Yes this is correct. When the liveUntilCancelled bool is not used, the order will cancel at the end of the bar.

    To have an order not be cancelled at the end of the bar use liveUntilCancelled as true.
    For example:
    ExitLongStop(0, true, 1, stopLoss, "Stop Losss Long", My_LONG);
    ExitLongStop(int barsInProgressIndex, bool liveUntilCancelled, int quantity, double stopPrice, string signalName, string fromEntrySignal)
    http://www.ninjatrader.com/support/h...itlongstop.htm

    Also, when starting a strategy that has been disabled, NinjaTrader will first cancel any live working orders that were made by the strategy previously. (This is so no problems occur from the strategy when it trys to recalculate and resubmit profit targets, stop losses etc. from the previous run). If the Immediately submit live working historical orders is selected in Tools -> Options... -> Strategies -> NinjaScript, then any orders that should be live historically will be resubmitted.
    http://www.ninjatrader.com/support/h..._positions.htm
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by alifarahani, 04-19-2024, 09:40 AM
    14 responses
    117 views
    0 likes
    Last Post alifarahani  
    Started by aguison, 06-19-2024, 02:32 PM
    4 responses
    23 views
    0 likes
    Last Post MiCe1999  
    Started by phenqreviews, Today, 12:11 AM
    0 responses
    5 views
    0 likes
    Last Post phenqreviews  
    Started by WHICKED, Yesterday, 08:47 PM
    1 response
    6 views
    0 likes
    Last Post MiCe1999  
    Started by phenqreviews, Today, 12:04 AM
    0 responses
    4 views
    0 likes
    Last Post phenqreviews  
    Working...
    X