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 Barry Milan, Yesterday, 10:35 PM
          5 responses
          16 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by DanielSanMartin, Yesterday, 02:37 PM
          2 responses
          13 views
          0 likes
          Last Post DanielSanMartin  
          Started by DJ888, 04-16-2024, 06:09 PM
          4 responses
          12 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by terofs, Today, 04:18 PM
          0 responses
          11 views
          0 likes
          Last Post terofs
          by terofs
           
          Started by nandhumca, Today, 03:41 PM
          0 responses
          8 views
          0 likes
          Last Post nandhumca  
          Working...
          X