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

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, 12:40 PM.

        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 fx.practic, 10-15-2013, 12:53 AM
            5 responses
            5,404 views
            0 likes
            Last Post Bidder
            by Bidder
             
            Started by Shai Samuel, 07-02-2022, 02:46 PM
            4 responses
            95 views
            0 likes
            Last Post Bidder
            by Bidder
             
            Started by DJ888, Yesterday, 10:57 PM
            0 responses
            8 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by MacDad, 02-25-2024, 11:48 PM
            7 responses
            159 views
            0 likes
            Last Post loganjarosz123  
            Started by Belfortbucks, Yesterday, 09:29 PM
            0 responses
            8 views
            0 likes
            Last Post Belfortbucks  
            Working...
            X