Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Draw Text in OnExecution()

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

    Draw Text in OnExecution()

    Hi,

    I scripted the following:

    Code:
    protected override void OnExecution(IExecution execution)
            {
                
                if (entryOrder != null && entryOrder == execution.Order)
                {
                    if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
                    {
                        
                        // Resets the entryOrder object to null after the order has been filled or partially filled
                        if (execution.Order.OrderState != OrderState.PartFilled)
                        {
                            entryOrder     = null;
                            
                        }
                    }
                    if(execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled ==0)
                    {
                        DrawText("My text" + CurrentBar, "hier", 0, High[0] + 20 * TickSize, Color.Red);
                    }
                }
        
    ...some more code
    
    }
    However, the DrawText, when an entryorder is canceled, doesn't work.
    Everything else works as it's supposed to do.
    Drawing test when submitting entryorders works. though.
    Why is that?
    Thanks in advance.

    Stephan

    #2
    Hello Stephan,

    I would check the value of "execution.Order.Filled" using the Print() method to see if it is returning the value that you expect.

    Here is a link to our support forums that goes over how to debug your code which comes in handy when writing custom code.
    http://www.ninjatrader.com/support/f...ead.php?t=3418
    JCNinjaTrader Customer Service

    Comment


      #3
      Hallo,

      thanks for your reply.
      I checked using TraceOrders=true.
      There are orders being canceled and I want to
      do something based on that event.
      The draw-command is just for testing if the approach works.
      Later on it will be replaced by some script.
      However, as stated, the drawtext command isn't executed.
      I don't know why and I need to get that going.

      Stephan

      Comment


        #4
        Hello Stephan123,
        OrderState.Cancelled generally do not gets triggered in the OnExecution event. It is an extreme rare event triggered in the OnExectution event due a race condition.

        To capture the Cancelled/Rejected events please use the OnOrderUpdate event.
        Last edited by NinjaTrader_Joydeep; 10-12-2012, 06:09 AM.
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          OK, I will try it that way.
          But, it's not such an rare event, I think,
          since it's triggered everytime a buystop or buylimit order
          is not executed because the price level wasn't hit.

          Comment


            #6
            Hello Stephan123,
            To clarify further, theoretically Cancelled or Rejected state is NOT supposed to get triggered in the OnExecution event. It is supposed to get triggered in the OnOrderUpdate event only.

            It gets triggered in the OnExecution event in a only due a rare race condition, NinjaTrader being a multi-thread application.
            JoydeepNinjaTrader Customer Service

            Comment


              #7
              Alright,
              got it. It works fine using OnOrderUpdate.
              Thanks, Stephan

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by CarlTrading, 03-31-2026, 09:41 PM
              1 response
              68 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by CarlTrading, 04-01-2026, 02:41 AM
              0 responses
              37 views
              0 likes
              Last Post CarlTrading  
              Started by CaptainJack, 03-31-2026, 11:44 PM
              0 responses
              61 views
              1 like
              Last Post CaptainJack  
              Started by CarlTrading, 03-30-2026, 11:51 AM
              0 responses
              62 views
              0 likes
              Last Post CarlTrading  
              Started by CarlTrading, 03-30-2026, 11:48 AM
              0 responses
              53 views
              0 likes
              Last Post CarlTrading  
              Working...
              X