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 charlesugo_1, 05-26-2026, 05:03 PM
        0 responses
        56 views
        0 likes
        Last Post charlesugo_1  
        Started by DannyP96, 05-18-2026, 02:38 PM
        1 response
        143 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        160 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        96 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        276 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Working...
        X