Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

working with lists

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

    working with lists

    Hello,

    I could modify an indicator to write elements (i) to a list with conditions I need.

    But I do not understand from this basic indicator how to remove elements with a condition. The lines in the indicator are

    for (int i = myList.Count -1; i >= 0; i--)
    {Print ("Event # "+ i + " Occured on bar: " + myList[i]);
    if (i < myList.Count - 10)
    {RemoveDrawObject("mydot" + myList[i].ToString()); myList.Remove(myList[i]);}

    When I modify with the condition I need this doesnt work and the line is not removed.
    for (int i = myList.Count -1; i >= 0; i--)
    {Print ("Event # "+ i + " Occured on bar: " + myList[i]);
    if (i > Closes[1][0])
    {RemoveDrawObject("mydot" + myList[i].ToString()); myList.Remove(myList[i]);}


    Can anyone help me with this code to remove elements from the list eg with "if CrossAbove (SMA(8), SMA(20), 1))" then RemoveDrawObject.

    Thank you!
    Tony
    Last edited by tonynt; 10-09-2020, 02:19 PM. Reason: add info

    #2
    Hello tonynt,

    Thanks for your post.

    We had given an example that triggers the RemoveDrawObject call when if (State == State.Realtime). When RemoveDrawObject is called, the CurrentBar index associated with your drawing object that is saved in the List is removed.

    If you want to change when this gets triggered so it is done on a crossover, you can check if CrossAbove (SMA(8), SMA(20), 1)) instead of if (State == State.Realtime).

    You could also consider adding the full drawing object tag to the List instead of just the CurrentBar index, and if you need to find specific drawing objects, you can check the item in your List while looping through the List and see if it contains the part of the drawing tag string that you are looking for.

    For the thread's context I have attached the example we gave you over email.

    We look forward to assisting.
    Attached Files

    Comment


      #3
      Hello,

      so now its clear whats going on in this sample. I have modified this to what I need but I have a problem now:

      when there is a certain condition true I want to plot a line and I want to save the high of the bar, I do this with both to a list, line to "mylistline" and high to "mylisthigh". I do this instead adding the currentbar in the sample. OK.

      The problem : I want to remove the drawing when price is crossing the high few bars later. How can one remove the drawing from the "mylistline" when price crosses the double in "mylisthigh"? The problem is not the condition nor the few bars later, the problem is how to remove the plot when the high is crossed?
      I can remove the high from the mylisthigh but how to remove the plot that has been created at this high?

      OR

      How can I assign the drawing/plot to a High or Low instead of CurrentBar so that with cross of that high or low the drawingobject is removed? In the helpguide (https://ninjatrader.com/support/help...?draw_line.htm) I cant find from the syntax how to do. When using the full drawing object tag how could this work when I need to match the current High/Low with the High/Low of the bar where the drawing object starts plotting, I would need the High/Low in the tag, no?

      Thank you!
      Tony
      Last edited by tonynt; 10-10-2020, 01:46 PM. Reason: inaccurate translation

      Comment


        #4
        Hello tonynt,

        Let's keep this simple. In order to remove a drawing object, we would use RemoveDrawObject() and give it the tag of a drawing object we would like to remove. You can save the name of a tag in a list and use RemoveDrawObject to remove the drawing object with that tag by referencing the element from your list in your RemoveDrawObject call.

        In the TestList example, the list is referenced in a loop where i is the index that is being iterated. That index is used in the brackets to reference that element in the list.

        Something else that you could consider would be to avoid appending CurrentBar to your tag, and using specific tag names for the drawing object. You could then just call RemoveDrawObject("MyTag"); and your expected drawing object would be removed because it is not holding a CurrentBar index with the tag.

        We look forward to assisting.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        650 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        370 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        109 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        574 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        577 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X