• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

keep highest line

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

    keep highest line

    hi !!

    what is the best method to keep
    - for example the highest line (in row of lines) and
    - the lowest line in row (of lines)
    and delete the lines, when a higher high or lower low appears?

    lines are drawn with DrawLine (...)
    the points where the lines are drawn are defined by indicator.

    using
    ILine myLine = DrawLine(...);
    if (null != prevLine && prevLine.StartY < myLine.StartY)
    {RemoveDrawObject(prevLine); }
    prevLine = myLine;

    is working fine for one line.
    turning it round for the other line, the indicator is compiling, but not drawing correctly.
    any suggestions how this can be solved ?
    any suggestions for another method to use ?
    thx !

    #2
    Hello,

    Thank you for the question.

    One way would be to keep a collection of the existing lines so that you can loop through them to find any lines that should no longer be kept.

    You can do this pretty easily using a List https://msdn.microsoft.com/en-us/lib...(v=vs.90).aspx

    A simple example would be:

    Add the using statement to allow List in the Script.
    Code:
    using System.Collections.Generic;
    Create the List:
    Code:
    private List<ILine> ObjectsList = new List<ILine>();
    Usage, add the object to the list and later you can get the objects information to do things:
    Code:
    ObjectsList.Add(DrawLine("MyLine", 10, Close[10], 0, Close[0], Color.Blue));
    			
    for(int i = 0; i < ObjectsList.Count; i++)
    {
            ILine line = ObjectsList[i];
    	if(Close[0] > line.StartY)
    	{	
    		RemoveDrawObject(line.Tag);
    		ObjectsList.Remove(line);
    	}
    }
    This would allow you to loop through the collection and remove items based on a tag or other criteria such as its Y value. Also if you will be removing objects, the for statement would be needed opposed to using a foreach statement, this is because the index will change when you remove the object and cause an error when using foreach specifically.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      hi jesse,
      thank you very much!!

      i don't know if a newbee will be able to do that - but i'll try....

      Comment


        #4
        used the code.
        indicator is compiling.
        lines are drawn, but not deleted.

        Code:
        ObjectsList.Add(DrawLine ("HH1" + (CurrentBar - barsback),false,barsback, High[barsback],-10, High[barsback], Color.Blue,DashStyle.Solid, 3));
        				for(int i=0; i<ObjectsList.Count; i++)
        				{
                		ILine line = ObjectsList[i];
        				if("HH1" [0] > line.StartY)
        				{	
        				RemoveDrawObject(line.Tag);
        				ObjectsList.Remove(line);
        				}
        due to the indicator, the lines don't appear on position [0], but later.
        perhaps this causes that the line at the high ( called "HH1") isn't deleted.
        what else can i do ?
        Last edited by Tradexxx; 05-04-2015, 11:40 AM.

        Comment


          #5
          Hello,

          I am unsure but it looks like possibly this statement, I don't have all the variables here so this was the only item that really caught my attention:

          if("HH1" [0] >

          The "HH1", is this meant to be a data series?

          If so it would need to have the quotes removed or just HH1[0] to get the value.


          A easy way to figure out if this is the cause would be to just use the Close price in place of this variable to see if the Close is greater than the lines value, depending on the variables you are using this may or may not come true you may need to adjust the test to work correctly.

          I have added a simple script that shows this working, in the case that you are unable to get this working please attach the script with variables and I could run it to see the cause.

          I look forward to being of further assistance.
          Attached Files
          JesseNinjaTrader Customer Service

          Comment


            #6
            Pls See PM

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by lavalampmj, Today, 05:25 PM
            0 responses
            3 views
            0 likes
            Last Post lavalampmj  
            Started by Antares66, Today, 05:19 PM
            0 responses
            2 views
            0 likes
            Last Post Antares66  
            Started by jmneto, Today, 05:18 PM
            0 responses
            4 views
            0 likes
            Last Post jmneto
            by jmneto
             
            Started by Bobbyj78, Today, 02:21 PM
            2 responses
            14 views
            0 likes
            Last Post bltdavid  
            Started by EnveousColnago, Today, 02:10 PM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_Ariana  
            Working...
            X