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 sjsj2732, Yesterday, 04:31 AM
        0 responses
        38 views
        0 likes
        Last Post sjsj2732  
        Started by NullPointStrategies, 03-13-2026, 05:17 AM
        0 responses
        287 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        289 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        134 views
        1 like
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        95 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Working...
        X