Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

On execution draw line

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

    On execution draw line

    Hi, i would like to draw a line once an order is triggered but not filled yet.
    Here below the code but for some reasons doesnt work. Any idea why?


    Code:
    protected override void OnExecution(IExecution execution)
    {
                lineLength = Math.Max(CurrentBar - barNumberOfOrder, 3);
                
                if (myLongEntry != null && myLongEntry == execution.Order
                && (execution.Order.OrderState == OrderState.Accepted))
                {
                DrawLine("EntryPending", false, lineLength, execution.Order.StopPrice, -20*lineLength, execution.Order.StopPrice, Color.White, DashStyle.Solid, 2);
                } 
    
                if (myLongEntry != null && myLongEntry == execution.Order
                && (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled 
                    || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0)))
                {
                    myLongEntry = null;        
                    RemoveDrawObject("EntryPending");
                } 
    
    }
    //called by the Onbarupdate
    private void LongEntry()
            {
                barNumberOfOrder = CurrentBar;
                myLongEntry = EnterLongStop(1,GetCurrentAsk()+ 1*TickSize, "LongEntry");
            }

    #2
    Hello badr,

    Thank you for the post.

    I believe for this, you would also need to use the OnOrderUpdate override in addition to OnExecution. OnExecution will specifically be for executions on orders, for all other state changes OnOrderUpdate should be used.



    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks, so in that case how would i access the price value of the StopPrice as shown below to draw the line?


      Code:
      protected override void OnOrderUpdate(IOrder order)
      {
                  lineLength = Math.Max(CurrentBar - barNumberOfOrder, 3);
                  
                  if (myLongEntry != null && myLongEntry == Order
                  && (Order.OrderState == OrderState.Accepted || Order.OrderState == OrderState.PendingSubmit))
                  {
                      DrawLine("EntryPending", false, lineLength, Order.StopPrice, -20*lineLength, Order.StopPrice, Color.White, DashStyle.Solid, 2);
                  } 
          
                  if (myShortEntry != null && myShortEntry == execution.Order
                  && (Order.OrderState == OrderState.Accepted || Order.OrderState == OrderState.PendingSubmit))
                  {
                      DrawLine("EntryPending", false, lineLength, Order.StopPrice, -20*lineLength, Order.StopPrice, Color.White, DashStyle.Solid, 2);
                  } 
       }

      Comment


        #4
        It's ok i got it, i had to write "order" not "Order".
        Everything is working fine now
        thanks

        Comment


          #5
          Hello badr,

          Thank you for the reply.

          It looks like you have removed the execution. and left Order in the syntax, this is basically what needs to be done but you need to make this lowercase to match the passed in order:
          Code:
          protected override void OnOrderUpdate([B]IOrder order[/B])
          Code:
          if (myLongEntry != null && myLongEntry == order
          && ([B]order[/B].OrderState == OrderState.Accepted || [B]order[/B].OrderState == OrderState.PendingSubmit))
          {
          	DrawLine("EntryPending", false, lineLength, [B]order[/B].StopPrice, -20*lineLength, order.StopPrice, Color.White, DashStyle.Solid, 2);
          } 
          	
          if (myShortEntry != null && myShortEntry == order
          && (order.OrderState == OrderState.Accepted || order.OrderState == OrderState.PendingSubmit))
          {
          	DrawLine("EntryPending", false, lineLength, order.StopPrice, -20*lineLength, order.StopPrice, Color.White, DashStyle.Solid, 2);
          }
          I look forward to being of further assistance.
          JesseNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by RookieTrader, Today, 09:37 AM
          3 responses
          14 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by kulwinder73, Today, 10:31 AM
          0 responses
          5 views
          0 likes
          Last Post kulwinder73  
          Started by terofs, Yesterday, 04:18 PM
          1 response
          23 views
          0 likes
          Last Post terofs
          by terofs
           
          Started by CommonWhale, Today, 09:55 AM
          1 response
          3 views
          0 likes
          Last Post NinjaTrader_Erick  
          Started by Gerik, Today, 09:40 AM
          2 responses
          7 views
          0 likes
          Last Post Gerik
          by Gerik
           
          Working...
          X