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 CarlTrading, 03-31-2026, 09:41 PM
        1 response
        63 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        35 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        54 views
        1 like
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        61 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        48 views
        0 likes
        Last Post CarlTrading  
        Working...
        X