Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OrderMethod/Onexecution

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

    OrderMethod/Onexecution

    Hey guys, when you meet a profit target in a trade using the statement, SetProfitTarget("Long 1a", CalculationMode.Ticks, profitVar);

    Lets say I want to change certain variables in the Onexecution method when the "Long 1a" trade meets its profit target and is sold, how do I know which position was sold in OnExecution?

    #region OrderMethod
    protected override void OnExecution(IExecution execution)

    #2
    You can call SetProfitTarget() throughout OnBarUpdate() to change the values used without needing OnExecution.

    When using OnExecution to track orders you would likely want to use IOrders to manage your position as opposed to calling the SetProfitTarget() method.

    That being said this is possible to call SetProfitTarget() from OnExecution()

    For an example of determining which order called OnExecution please see: http://www.ninjatrader.com/support/f...ead.php?t=7499
    LanceNinjaTrader Customer Service

    Comment


      #3
      Hi, thanks for the info, but when I use SetProfitTarget like

      SetProfitTarget("Long 1a", CalculationMode.Ticks, profit1);

      entryOrder1 = EnterLong(0, DefaultQuantity, "Long 1a");

      protected override void OnExecution(IExecution execution)
      {
      if(entryOrder1 != null)

      entryOrder1 comes up as NULL here for some reason, not sure why?

      Comment


        #4
        Do you have a sample script that replicates the error.

        It is possible OnExecution would get called when the entry order is null but this would depend on your logic. In otherwords you could be setting it to null somewhere else or a different order could be calling OnExecution
        LanceNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        561 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        325 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        547 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        547 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X