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

stop strategy from entering NEW positions after Stop hit

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

    stop strategy from entering NEW positions after Stop hit

    If I hit a stop loss anytime during the day, I not only want to close the position but ALSO disable my strategy from entering any NEW positions. It still needs to manage the remaining open position(s) that weren't tied to the stop loss already hit.

    Could this be accomplished by changing EntriesPerDirection dynamically? Or is there a better way?

    #2
    Hello YD777,

    I have a few examples of a daily loss limit.
    Hello, I've updated the DailyLossLimit and DailyLosLimitMultiTrade examples that were posted on the forum for NinjaTrader 7 for NinjaTrader 8. These are often requested and I felt they are good examples to have for NT8. DailyLossLimitExample_NT7 - http://ninjatrader.com/support/forum...241#post451241 (http://ninjatrader


    Instead of stopping new entries after the loss limit is hit, set a variable that is changed when a stop loss or exit order fills.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks, I learned a lot from the examples.

      Can you tell how my script would know if a stop was hit for any of my orders?

      Comment


        #4
        Hello YD777,

        Yes, this is possible by detecting the signal name of the order in OnExecution() or OnOrderUpdate().

        Code:
        protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
        {
        	if (execution.Order.Name == "Profit target")
        	{
        		// the profit target has had a fill or part fill
        	}
        
        	if (execution.Order.Name == "Stop loss")
        	{
        		// the stop loss has had a fill or part fill
        	}
        
        	if (execution.Order.Name == "Trail stop")
        	{
        		// the trailing stop loss has had a fill or part fill
        	}
        }
        
        protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string comment)
        {
        	// if the order is filled or part filled
        	if (order.OrderState == OrderState.Filled || order.OrderState == OrderState.PartFilled)
        	{
        		if (order.Name == "Profit target")
        		{
        			// the profit target has had a fill or part fill
        		}
        
        		if (order.Name == "Stop loss")
        		{
        			// the stop loss has had a fill or part fill
        		}
        
        		if (order.Name == "Trail stop")
        		{
        			// the trailing stop loss has had a fill or part fill
        		}
        	}
        }
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by gentlebenthebear, Today, 01:30 AM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by Aviram Y, Today, 05:29 AM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by cls71, Today, 04:45 AM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by TradeForge, Today, 02:09 AM
        1 response
        22 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by elirion, Today, 01:36 AM
        2 responses
        14 views
        0 likes
        Last Post elirion
        by elirion
         
        Working...
        X