Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Moving a stop

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

    Moving a stop

    In a strategy I set an initial stop with the line of code below:

    stopLongEntryPP = ExitLongStop(0, true, execution.Order.Filled, pp - stop * TickSize, "Stop of Long PP", "Long Entry PP");

    If I want to change that on certain price conditions I take it I do this in OnBarUpdate? But when I try and use the execution.Order.Filled in OnBarUpdate I get an error. Am I only able to use execution.Order.Filled in OnExecution? If so what is the best way to reference the current position size?

    Thanks

    #2
    Hi,

    The parameter you're accessing is read-only from the OnExecution method.

    If you'd like to get the current position size you can call Position.Quantity in OnBarUpdate:

    Code:
    Print("Position.Quantity: " + Position.Quantity);]
    You could also just pass the execution.Order.Filled price from the Execution

    Code:
            protected override void OnBarUpdate()
            {
    			// pulled from OnExecution
    			Print("executionQty: " + executionQty);
    
             }
    			
             protected override void OnExecution(IExecution execution)
            {
    			executionQty = execution.Order.Filled;
    	}
    MatthewNinjaTrader Product Management

    Comment


      #3
      That's great thanks. Is there a way of checking which iorder is the current execution if it has been reset to null?

      Comment


        #4
        Sure, there are a lot of properties you can read from the objects

        Code:
        		protected override void OnExecution(IExecution execution)
        		{
        			if(execution.Name == "myOrder")
        			{
        				Print("myOrder was executed!");
        				executionPrice = execution.Order.Filled;
        			}
        			
        		}
        Examples of checking for null can be found from the following link:

        MatthewNinjaTrader Product Management

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by charlesugo_1, 05-26-2026, 05:03 PM
        0 responses
        59 views
        0 likes
        Last Post charlesugo_1  
        Started by DannyP96, 05-18-2026, 02:38 PM
        1 response
        143 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        161 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        97 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        283 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Working...
        X