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

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.


    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by AveryFlynn, Today, 04:57 AM
    0 responses
    4 views
    0 likes
    Last Post AveryFlynn  
    Started by RubenCazorla, 08-30-2022, 06:36 AM
    3 responses
    79 views
    0 likes
    Last Post PaulMohn  
    Started by f.saeidi, Yesterday, 12:14 PM
    9 responses
    25 views
    0 likes
    Last Post f.saeidi  
    Started by Tim-c, Today, 03:54 AM
    0 responses
    3 views
    0 likes
    Last Post Tim-c
    by Tim-c
     
    Started by FrancisMorro, Today, 03:24 AM
    0 responses
    5 views
    0 likes
    Last Post FrancisMorro  
    Working...
    X