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 BarzTrading, Today, 07:25 AM
          2 responses
          13 views
          1 like
          Last Post BarzTrading  
          Started by devatechnologies, 04-14-2024, 02:58 PM
          3 responses
          19 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by tkaboris, Today, 08:01 AM
          0 responses
          3 views
          0 likes
          Last Post tkaboris  
          Started by EB Worx, 04-04-2023, 02:34 AM
          7 responses
          162 views
          0 likes
          Last Post VFI26
          by VFI26
           
          Started by Mizzouman1, Today, 07:35 AM
          1 response
          9 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Working...
          X