Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Question about OnExecution()

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

    Question about OnExecution()

    if I'm handeling multiple orders, do I have to assign each one its individual OnExecution()?

    ie

    longentryOrderA

    Code:
    protected override void OnExecution(IExecution execution)
           
                // LONG ORDER A STOP AND TARGET
                if (longentryOrderA != null && longentryOrderA.Token == execution.Order.Token)
    and then for longentryOrderB
    Code:
                if (longentryOrderB != null && longentryOrderB.Token == execution.Order.Token)
    or must they be under their own individual OnExecution?

    #2
    You can do them as separate if-statements. You do not need a separate OnExecution.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      hrmm ok...

      the reason I'm asking is that I'm seeing issues where I have an order placed, but the stops and targets are not getting placed all the time (sometimes they do, sometimes they don't)

      this is the code... any ideas?

      Code:
              protected override void OnBarUpdate()
              {
                  // BUY MODE HIGHER LOWS
                  if (longentryOrderA == null 
                      && Low[1] > Low[2])
                  {
                      longentryOrderA = EnterLongLimit(0, true, DefaultQuantity, GetCurrentBid() + -1 * TickSize, "LongA");
                  }
      
              protected override void OnExecution(IExecution execution)
              {
                  // LONG ORDER A STOP AND TARGET
                  if (longentryOrderA != null && longentryOrderA.Token == execution.Order.Token)
                  {
                      if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
                      {
                          // Stop-Loss order 4 ticks below our entry price
                          longstopOrderA     = ExitLongStop(0, true, execution.Order.Filled, execution.Order.AvgFillPrice - 4 * TickSize, "LongStopA", "LongA");
                          
                          // Target order 8 ticks above our entry price
                          longtargetOrderA = ExitLongLimit(0, true, execution.Order.Filled, execution.Order.AvgFillPrice + 6 * TickSize, "LongTargetA", "LongA");
                          
                          // Resets the entryOrder object to null after the order has been filled or partially filled
                          if (execution.Order.OrderState != OrderState.PartFilled)
                          {
                              longentryOrderA     = null;
                          }
                      }
                  }
      
                  // RESET LONGA STOP AND TARGET
                  if ((longstopOrderA != null && longstopOrderA.Token == execution.Order.Token) || (longtargetOrderA != null && longtargetOrderA.Token == execution.Order.Token))
                  {
                      if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled)
                      {
                          longstopOrderA = null;
                          longtargetOrderA = null;
                      }
                  }

      Comment


        #4
        BigDog008,

        I suggest you add yourself the OnOrderUpdate() method and print every event from there to see what is happening with your stops and targets.
        Josh P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by cmoran13, Yesterday, 01:02 PM
        0 responses
        29 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        21 views
        0 likes
        Last Post PaulMohn  
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        160 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        95 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        148 views
        2 likes
        Last Post CaptainJack  
        Working...
        X