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 objets

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

    Remove objets


    Hello. I am drawing a horizontal line when set 1 is met. what I want is to erase a line when the price hits it but keeping the others until the price touches them. can you help me? thanks!

    HTML Code:
     // Set 1
    if (NBarsUp1[0] == 1)
    {
    Draw.HorizontalLine(this, @"MyCustomStrategy2 Horizontal Line_1 " + Convert.ToString(CurrentBars[0]), false, Low[3], Brushes.CornflowerBlue, DashStyleHelper.Solid, 2);
    }

    #2
    If I understand your wish correctly, you may have multiple lines stacked above the current price... and when price hits the lowest one, remove that and leave the others until price hits/touches the next higher one... right?

    Three comments..
    1. To remove the desired line, you will need to be able to identify it, and it seems that will need to include the price at which it is drawn. You could achieve this by including a fixed format of the price in the object's tag...eg by using the master instrument's FormatPrice method. So for example your tag might end up looking like "MyStrategy2 ES 4237.75"
    2. Then, you can test if a drawing object with a given tag exists, and if so, delete it. So... lets assume you have such a tag on a horizontal line... maybe the tag is a string in a variable HL_tag... then this code would do it.
      Code:
      if (DrawObjects[HL_tag] as DrawingTools.HorizontalLine != null) // remove existing existing horizontal line at the specified price level
      	RemoveDrawObject(HL_tag);
    3. Next... how/when to perform this test? Well, if you are running a strategy/chart on each tick... a test in OnBarUpdate should work...testing each and every price level, but if you are running on say a 5 minute bar on bar close or whatever, you would need to test for crossovers intrabar. And then, the question becomes "What price do you check?" I think you would probably need to loop through all possible prices by ticksize increment from the bar's open through to the bars high. Or perhaps keep a list of prices where you believe lines are drawn... and check if one of those is within the bar's price range. This would be more efficient... but if your list gets out of synch with your chart, then things could go wrong... so it's less robust.
    Maybe someone else has a better idea...
    Hope it helps...
    T.
    Last edited by tgn55; 06-29-2021, 08:06 PM.

    Comment


      #3
      Hello manueldecastro,

      Thanks for opening the thread.

      As another tip to add, you can consider using Calculate.OnPriceChange for the detection of price levels matching your drawing object's price, and for any Calculate.OnBarClose behavior, you can use IsFirstTickOfBar to have OnBarClose actions while OnBarUpdate is updating OnPriceChange.

      The Help Guide documentation below provides an example for how you can program OnBarClose style logic using IsFirstTickOfBar in a script that uses Calculate.OnPriceChange or OnEachTick.



      Let us know if you have any additional questions.
      JimNinjaTrader Customer Service

      Comment


        #4
        if my objet is created as Draw.Rectangle(this, "R1"+CurrentBar,.....

        How can i remove a specific rectangle of all those that are drawn

        Comment


          #5
          Hello manueldecastro,

          RemoveDrawObject looks for a drawing tool tag to remove a drawing object. Simply put, you would need to keep track of "R1"+CurrenBar so you can call it with RemoveDrawObject to remove the drawing object at a later time.

          tgn55's suggestion was to use a tag that uses price instead of CurrentBar, so you have unique tags to place multiple drawing objects, but since the price is used instead of the CurrentBar index, you can check if the drawing object exists by price (see post #2) without needing to track the CurrentBar index.
          JimNinjaTrader Customer Service

          Comment


            #6

            First of all thanks for the help. I have tried with the horizontal line and the code works. I am trying something similar with areas drawn with rectangles but I have 2 problems: 1.- The rectangle ends at 15 candles, but I would like it to continue drawing candle by candle until the price crosses it. 2.- once the price crosses it, it is no longer valid, so it should be deleted. I don't know how to implement the code for horizontal line in the rectangle.


            Sample code for rectangles.
            In this case, the rectangle should grow candle by candle until the price is higher than the high [0] that defined the rectangle. Once it is higher than High, delete the rectangle

            if (High[0] < Low[2]){
            Draw.Rectangle(this, "Bajista"+High[0], false,2, Low[2], -15, High[0], Brushes.Transparent, Brushes.Crimson, 20);}
            Last edited by manueldecastro; 07-07-2021, 12:01 AM.

            Comment


              #7
              Hello manueldecastro,

              Let's think of this in terms of what parameters the Draw.Rectangle method needs to draw a rectangle, and how you can model your logic to call the method with new parameters.

              For example, use class level variables and when your condition becomes true:
              1. Assign the tag to a variable
              2. Store the starting BarsAgo value (you can increment this as new bars develop)
              3. Store the ending BarsAgo value (this can stay the same as new bars develop)
              4. Store the price levels of the rectangle (you can update these variables with another condition if you want to price levels to change)
              5. Assign a boolean variable indicating that you should draw the rectangle
              Then, you can check when the boolean variable is true, and then you can call Draw.Rectangle with the parameters you stored in variables. Using the same drawing tag will update the rectangle, so updating the variables and calling Draw.Rectangle again would be appropriate to row the rectangle.

              You can then consider resetting these variables to initial values and setting the bool to false when you come across a condition which would call RemoveDrawObject to remove the rectangle.

              We look forward to assisting.
              JimNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Tim-c, Today, 02:10 PM
              1 response
              7 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by Taddypole, Today, 02:47 PM
              0 responses
              2 views
              0 likes
              Last Post Taddypole  
              Started by chbruno, 04-24-2024, 04:10 PM
              4 responses
              50 views
              0 likes
              Last Post chbruno
              by chbruno
               
              Started by TraderG23, 12-08-2023, 07:56 AM
              10 responses
              400 views
              1 like
              Last Post beobast
              by beobast
               
              Started by lorem, Yesterday, 09:18 AM
              5 responses
              25 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Working...
              X