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

Remove DrawObjects on OrderFill

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

    Remove DrawObjects on OrderFill

    Hi, I have a strategy using bracket orders after my entry was filled.
    I have my strategy draw lines at the target and stop prices on the chart.
    I have the lines drawn in the on order update method.
    My question is how do I remove the lines from the chart, when either one of the bracket orders is filled. Meaning if the orders are filled or cancelled the lines on the chart should be removed too.
    Should work like if you are using the charttrader, if there is an existing order, display line at price, if order is filled, canceled or updated, remove or update the lines.

    Regards

    #2
    Hello,

    Thank you for the question.

    If these lines are only drawn when you are in a position and need to be removed when you are out of the position you can try to call RemoveDrawObjects(); this removes any script added objects.


    otherwise if this does not work as expected you could define a variable that you will set as an ILine object, this will allow you to modify or update the line and also remove it.

    Code:
    private ILine line1 = null;
    protected override void OnBarUpdate()
    {
         //set the variable to a line that we create
         line1 = DrawLine("tag", true, 0, Close[0], 10, Close[0], Color.Red, DashStyle.Solid, 1);
        
         //If you want to then update the line
         line1.StartY = Close[0];
         line1.EndY = Close[0];
    
         //when you want to remove the object
         RemoveDrawObject(line1);
         line1 = null;
    }
    Please let me know if I may be of additional assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks,

      Marketposition.Flat works in the Order Update method.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by TAJTrades, Today, 11:03 AM
      0 responses
      2 views
      0 likes
      Last Post TAJTrades  
      Started by wuannetraam, Today, 02:40 AM
      3 responses
      25 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by jjs12, Today, 10:29 AM
      2 responses
      8 views
      0 likes
      Last Post jjs12
      by jjs12
       
      Started by Ludwik, Today, 03:52 AM
      7 responses
      32 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by sdauteuil, 09-23-2021, 10:16 AM
      5 responses
      1,221 views
      0 likes
      Last Post NinjaTrader_RyanS  
      Working...
      X