Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Need help with removing rays

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

    Need help with removing rays

    Hi,

    My indicator is, by design, to draw rays when condition is true but I have too many lines and am trying to reduce the clutter by removing old lines. I thought the easiest way would be by using a list to remove the older ones. While everything seems to be compiling without errors, something else may be wrong with the list. I tried capping it to 10 rays but I'm still getting more than 50 rays! Can you please have a look to see what is wrong or how I should go about resolving this issue? The code is below:-

    Code:
    if (CurrentBar < (level*2 + 10)) return;
    
    if( DemandLineCount == DemandLineMaxCount )
    {
    DemandLines.RemoveAt(DemandLines.Count-1);
    }
    
    // Identify the first pivot low
    if((Math.Min(Low[1],Close[2]) < Math.Min(Low[0],Close[1])) && (Math.Min(Low[1],Close[2]) < Math.Min(Low[2], Close[3])))
    {
    DemandPoint0 = Math.Min(Low[1],Close[2]);
    DemandPoint0Y = CurrentBar-level;
    // Draw.Dot(this, "DPDot"+CurrentBar, true, 1, DemandPoint0, Brushes.Red, true);
    // Print(Time[0].ToString());
    // Print("CurrentBara = " + CurrentBar.ToString());
    }
    // Hunting for a lower pivot low that has already occurred which meets the same pivot low condition and to draw a ray connecting the 2 points
    for( int x = 1; x <= Math.Min(CurrentBar-4, 50); x++)
    {
    if ((Math.Min(Low[x], Close[x+1]) < Math.Min(Low[x-1], Close[x])) && (Math.Min(Low[x], Close[x+1]) < Math.Min(Low[x+1], Close[x+2])))
    {
    if (Math.Min(Low[x], Close[x+1]) < DemandPoint0)
    {
    DemandPoint1 = Math.Min(Low[x], Close[x+1]);
    DemandPoint1Y = x;
    string drawTag = "DPL" + CurrentBar;
    Draw.Ray(this, drawTag, true, DemandPoint1Y, DemandPoint1, CurrentBar - DemandPoint0Y , DemandPoint0, Brushes.Pink, DashStyleHelper.Solid, 1);
    DemandLineCount++;
    DemandLines.Add(drawTag);
    Print(Time[0].ToString());
    Print("drawtag = " + drawTag);
    // Print("x =" + x.ToString());
    // Print("low[x] = " + Low[x].ToString());
    // Print("low[1] = " + Low[1].ToString());
    // Print("CurrentBar = " + CurrentBar.ToString());
    // Print("DemandPoint0 = " + DemandPoint0.ToString());
    // Print("DemandPoint0Y = " + DemandPoint0Y.ToString());
    break;
    }
    }
    }

    #2
    Hello kaywai,

    You either need to use X number of unique Tags so that they eventually start to be reused, if a tag is reused the old object is updated which would limit the number of objects to the number of tags.
    If that is not an option you need to use RemoveDrawObject to remove objects, adding them to the list is only for your convenience and does nothing for removing the objects.


    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    72 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    39 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    63 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    63 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    53 views
    0 likes
    Last Post CarlTrading  
    Working...
    X