Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

removing previous draw object

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

    removing previous draw object

    Hi I am drawing lines ok but I want to onlly keep last drawn line. in this screnshot I have several redlines. I want to have only last one. I tried to remove them but its not working, i am doing something wrong.


    string flagBearLabel = "BearFlag"+CurrentBar;
    string flagBullLabel = "BullFlag"+CurrentBar;
    RemoveDrawObject(flagBearLabel);
    RemoveDrawObject(flagBullLabel);
    if(BullBearFlag)
    {

    isLowSequence = true;
    for (int i = 0; i < lookbackPeriod-1; i++)
    {
    if (Low[i] <= Low[i + 1])
    {
    isLowSequence = false;
    break;
    }
    }

    if (isLowSequence && trendDirection == -1 && Low[0] < Close[0])
    double slope = (Low[0] - Low[lookbackPeriod -1] ) / lookbackPeriod;
    trendlineValueUp = Low[0] - (slope * 0);
    Draw.Line(this, flagBearLabel, true, lookbackPeriod, Low[lookbackPeriod -1], 0, Low[0], Brushes.Aqua, DashStyleHelper.Solid, 2);
    Alert("Alert", Priority.High, "Up trend line broken", NinjaTrader.Core.Globals.InstallDir+@"\sounds\Reve rsing.wav", 10, Brushes.Transparent, Brushes.Transparent);
    bearFlag = true;

    }

    ​​Click image for larger version

Name:	image.png
Views:	55
Size:	35.8 KB
ID:	1318037

    #2
    I would want to keep currentbar to make those lilnes unique so lines stay on the chart historiacally.

    Comment


      #3
      like on this short video, if i remove currentbar then it removes lines from the chart and only keeps the last one occured. I want lines to stay on the chart but only last ones from the signal

      Comment


        #4
        Hello tkaboris,

        It is not clear from your description what you want. The following two statements contradict each other.

        but I want to onlly keep last drawn line. in this screnshot I have several redlines. I want to have only last one.
        I would want to keep currentbar to make those lilnes unique so lines stay on the chart historiacally.

        If you only keep the last drawn line you will never have any historical lines. You will only have a single line on the chart at the position where it was last drawn. That object can be updated to new bars but there will only ever be a single line on the chart.

        If you want to keep using CurrentBar for the tag so its unique and on the chart historically then you won't have the option to only keep the last drawn line. You will have historical lines unless you later remove them.

        Comment


          #5
          Use a counter instead of CurrentBar. Use Draw.Line(this, "BearFlag" + BearCtr, ... and then increment the counter: BearCtr++.
          If you want to remove the previous line use this: RemoveDrawObject("BearFlag" +(BearCtr-1));
          If you don't want to remove it skip the removal process and proceed to the next line and counter incrementing.
          You can just remove this stuff:
          string flagBearLabel = "BearFlag"+CurrentBar;
          eDanny
          NinjaTrader Ecosystem Vendor - Integrity Traders

          Comment


            #6
            How I reposition a line that was created with Draw.Line.without removing it and recreating it which I imagine is slow.?
            I mean, I created one with myline = Draw.Line(NinjaScriptBase owner, string tag, int startBarsAgo, double startY, int endBarsAgo, double endY, Brush brush).
            Then I would like to reposition it with an imaginary command like: myline.AlterPosition(startBarsAgo, startY, endBarsAgo, endY). I don't see a command similar to this anywhere in the documentation or forum.
            What is correct and simple way to do it (if it is worth the computing effeciency)
            Or Else which one the simple suggested way to obtain the same result? Or should I remove the object and recreate it ? (Which I guess it's slow)
            Best
            Gio

            Comment


              #7
              Hello giogio1,

              To reposition a line you just have to call the draw method again with new values and the same tag to update the existing object.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by abelsheila, 05-14-2025, 07:38 PM
              3 responses
              58 views
              0 likes
              Last Post Vintoro5  
              Started by futurenow, 12-06-2021, 05:49 PM
              18 responses
              871 views
              0 likes
              Last Post dj0ntz
              by dj0ntz
               
              Started by TurkeyAngola, Yesterday, 04:44 AM
              0 responses
              20 views
              0 likes
              Last Post TurkeyAngola  
              Started by nailz420, 05-14-2025, 09:14 AM
              1 response
              109 views
              0 likes
              Last Post NinjaTrader_ChristopherJ  
              Started by NinjaTrader_Brett, 05-12-2025, 03:19 PM
              0 responses
              508 views
              1 like
              Last Post NinjaTrader_Brett  
              Working...
              X