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