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 Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        648 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        369 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        108 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        572 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        574 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X