Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

RemoveDrawObject

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

    RemoveDrawObject

    Hello,

    I'm trying to remove a Line added by the Draw.Line using RemoveDrawObject without success.

    I'm using a String object to pass the String to the Draw.Line method like this:

    DateTime dt = Time[0];

    string topLine = "ORHigh " + Bars.Instrument.MasterInstrument.Name + dt.Year + dt.Month + dt.Day;

    Draw.Line(this, topLine, false, dtStartTime, dHighestPrice, dtNewEndTime, dHighestPrice, true, "OR");


    I want the line to be remove when the next trading session begin and the OnBarUpdate calls the last bar of the previous session:

    if (Bars.IsLastBarOfSession) RemoveDrawObject(topLine);


    The Line is not removed. What I'm I doing wrong?

    #2
    Hello vavatete,

    Thank you for the post.

    From the provided details I would not be certain what may be wrong, have you tried Printing the tag at both times to make sure it is identical? I see that you are using the Time object, are you re generating the tag when you go to remove it or was the tag stored and re used?

    If you have a simple example you can attach that just draws a line and then tries to remove it how you are currently that may help also.

    You can also try a simple test such as removing it after a few bars instead of the last bar of the session to make sure the logic is working in general. For example opening a short timeframe like 5 seconds and then drawing, waiting a few bars and then removing is a good way to test draw/remove logic. This allows you to test the condition on the simulated data feed or in realtime at a quick rate so you can understand the problem.

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

    Comment


      #3
      Hello,

      Below the code. In attach a print scr from the output window.

      public class OpenRangeVava : Indicator
      {
      #region Variables

      private double dHighestPrice = 0.0;
      private double dLowestPrice = 0.0;

      private DateTime dtStartTime;
      private DateTime dtEndTime;

      private bool bShowExtendLines;

      private SessionIterator sessionIterator;

      private string linhaCima;
      private string linhaBaixo;

      #endregion

      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = @"Enter the description for your new custom Indicator here.";
      Name = "Open Range Vava";
      Calculate = Calculate.OnBarClose;
      IsOverlay = true;
      DisplayInDataBox = false;
      DrawOnPricePanel = true;
      DrawHorizontalGridLines = false;
      DrawVerticalGridLines = false;
      PaintPriceMarkers = true;
      //Disable this property if your indicator requires custom values that cumulate with each new market data event.
      //See Help Guide for additional information.
      IsSuspendedWhileInactive = true;

      StartTime = DateTime.Parse("14:31", System.Globalization.CultureInfo.InvariantCulture) ;
      EndTime = DateTime.Parse("15:30", System.Globalization.CultureInfo.InvariantCulture) ;
      ExtendLines = true;
      }
      else if (State == State.Configure)
      {
      AddDataSeries(BarsPeriodType.Minute, 1);
      }
      else if (State == State.DataLoaded)
      {
      dtStartTime = StartTime;
      dtEndTime = EndTime;
      bShowExtendLines = ExtendLines;
      }
      else if (State == State.Historical)
      {
      // sessionIterator = new SessionIterator(Bars);
      }
      }

      protected override void OnBarUpdate()
      {
      //Verificar se a serie principal é de 1 minuto para impedir correr a serie secundária
      if (BarsPeriods[0].BarsPeriodType == BarsPeriodType.Minute && BarsPeriods[0].Value == 1 && BarsInProgress == 1) return;

      DateTime dt = Time[0];
      dtStartTime = new DateTime(dt.Year, dt.Month, dt.Day, dtStartTime.Hour, dtStartTime.Minute, dtStartTime.Second);
      dtEndTime = new DateTime(dt.Year, dt.Month, dt.Day, dtEndTime.Hour, dtEndTime.Minute, dtEndTime.Second);

      //se o tempo está fora do Open Range não há mais nada a fazer
      //if (Time[0] > dtEndTime) return;

      if (BarsPeriod.BarsPeriodType == BarsPeriodType.Minute)
      {
      if (CurrentBar < 2) return;

      if (BarsPeriod.Value == 1)
      {
      if (ToTime(Time[0]) == ToTime(dtStartTime))
      {
      Print("------------------------");
      dHighestPrice = High[0];
      dLowestPrice = Low[0];
      linhaCima = "ORHigh " + Bars.Instrument.MasterInstrument.Name + dt.Year + dt.Month + dt.Day;
      linhaBaixo = "ORLow " + Bars.Instrument.MasterInstrument.Name + dt.Year + dt.Month + dt.Day;

      Print("string passed -- "+linhaCima);
      }
      else if (ToTime(Time[0]) > ToTime(dtStartTime) && ToTime(Time[0]) < ToTime(dtEndTime))
      {
      if (High[0] > dHighestPrice) dHighestPrice = High[0];
      if (Low[0] < dLowestPrice) dLowestPrice = Low[0];
      //Print("Atualização" + Time[0] + " < dtendTime " + dtEndTime);
      }
      }
      }
      if (dHighestPrice > 0 && dLowestPrice > 0)
      {
      if (bShowExtendLines)
      {
      DateTime dtNewEndTime = dtEndTime.AddDays(1);
      Draw.Line(this, linhaCima, false, dtStartTime, dHighestPrice, dtNewEndTime, dHighestPrice, true, "OR");
      Draw.Line(this, linhaBaixo, false, dtStartTime, dLowestPrice, dtNewEndTime, dLowestPrice, true, "OR");
      }
      else
      {
      Draw.Line(this, linhaCima, false, dtStartTime, dHighestPrice, dtEndTime, dHighestPrice, true, "OR");
      Draw.Line(this, linhaBaixo, false, dtStartTime, dLowestPrice, dtEndTime, dLowestPrice, true, "OR");
      }
      if (BarsInProgress==0 && Bars.IsLastBarOfSession)
      {
      RemoveDrawObject(linhaCima);
      RemoveDrawObject(linhaBaixo);
      Print("call cleaning -- " + linhaCima);

      }
      }
      }

      Comment


        #4
        Hello vavatete,

        I wanted to check, are you not seeing the objects removed at all or are you seeing a delay when removing them?

        I tried a more simple test which just draws a line and then uses the tag to remove it at the IsLastBarOfSession, I did see this worked in my test however it does require the next bar to see a tick before we would see it removed. Is that what you are also seeing or are you seeing that none of the objects are being removed ever?


        I look forward to being of further assistance.

        JesseNinjaTrader Customer Service

        Comment


          #5
          Hello vavatete,

          I see you are using global objects.

          I had a similar problem in the past.

          See if this can help you



          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by wzgy0920, Yesterday, 09:53 PM
          2 responses
          49 views
          0 likes
          Last Post wzgy0920  
          Started by Kensonprib, 04-28-2021, 10:11 AM
          5 responses
          191 views
          0 likes
          Last Post Hasadafa  
          Started by GussJ, 03-04-2020, 03:11 PM
          11 responses
          3,230 views
          0 likes
          Last Post xiinteractive  
          Started by andrewtrades, Today, 04:57 PM
          1 response
          14 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by chbruno, Today, 04:10 PM
          0 responses
          7 views
          0 likes
          Last Post chbruno
          by chbruno
           
          Working...
          X