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

RemoveDrawObject Not Working

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

    RemoveDrawObject Not Working

    I am developing an indicator that looks for bars that have:

    Higher Highs, Higher Lows and Higher Closes or
    Lower Lows, Lower Highs and Lower Closes

    It mostly works, but on occasions it does not as highlighted in the attached image. It seems to initially mark the chart correctly but when the conditions change it should remove the indication until it becomes valid again.

    I've attached the code, but for the life of me can't figure out why its not removing the DrawObject when the conditions become invalid.

    Anyone have any ideas on how to fix this?

    tia

    taddypole...
    Attached Files

    #2
    Originally posted by Taddypole View Post
    I am developing an indicator that looks for bars that have:

    Higher Highs, Higher Lows and Higher Closes or
    Lower Lows, Lower Highs and Lower Closes

    It mostly works, but on occasions it does not as highlighted in the attached image. It seems to initially mark the chart correctly but when the conditions change it should remove the indication until it becomes valid again.

    I've attached the code, but for the life of me can't figure out why its not removing the DrawObject when the conditions become invalid.

    Anyone have any ideas on how to fix this?

    tia

    taddypole...
    Code:
    The draw object that you are removing is not the same as the draw object that you are creating. Taking you DownBar as a case in point, look at the [COLOR="Red"]red[/COLOR] text that I have highlighted.
    
    			if (Close[0] > Close[1] && Low[0] > Low[1] && High[0] > High[1])
    			{
    				DrawText([COLOR="red"]"ObviousDownBar" + CurrentBar[/COLOR], true, "M", 0, Low[0] - 1 * TickSize, 0, Color.White, ObviousBar, StringAlignment.Center, Color.Transparent, Color.Black, 0);
    			}
    			else
    			RemoveDrawObject([COLOR="red"]"ObviousDownBar"[/COLOR]);

    Comment


      #3
      taddypole, as koganam has observed, you are not removing the same draw object. You need to keep track of the bars the objects are on and then remove those draw objects from those bars. If you only want the most recent draw object shown, you can draw with "ObviousDownBar" minus the current bar and then it would be removed by your existing code.
      AustinNinjaTrader Customer Service

      Comment


        #4
        Thank you both for that. It works as expected if I put:

        RemoveDrawObject("ObviousDownBar" + CurrentBar);

        But another question.

        I was doing research on the forum and found others used this:

        RemoveDrawObject("ObviousDownBar" + CurrentBar.ToString());

        Are they both correct? and do they yield the same results?
        If not, what is the difference?

        Thanks...

        taddypole...

        Comment


          #5
          Taddypole, they are both correct. CurrentBar is automatically converted to a string in the first instance, which would make it exactly the same as the second instance.
          AustinNinjaTrader Customer Service

          Comment


            #6
            Thank you Austin,

            But now I have to ask, are there others that are automatically converted to string? If so, is this documented somewhere?

            Comment


              #7
              Hi TaddyPole,

              Unfortunately, there's no documentation on this. This is a C# feature (or nuance). Using the + operator from string to a different type does the ToString() conversion automatically.
              Last edited by NinjaTrader_RyanM1; 08-07-2011, 06:31 PM.
              Ryan M.NinjaTrader Customer Service

              Comment


                #8
                Thank you Ryan,

                That is useful information.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by cls71, Today, 04:45 AM
                0 responses
                1 view
                0 likes
                Last Post cls71
                by cls71
                 
                Started by mjairg, 07-20-2023, 11:57 PM
                3 responses
                213 views
                1 like
                Last Post PaulMohn  
                Started by TheWhiteDragon, 01-21-2019, 12:44 PM
                4 responses
                544 views
                0 likes
                Last Post PaulMohn  
                Started by GLFX005, Today, 03:23 AM
                0 responses
                3 views
                0 likes
                Last Post GLFX005
                by GLFX005
                 
                Started by XXtrader, Yesterday, 11:30 PM
                2 responses
                12 views
                0 likes
                Last Post XXtrader  
                Working...
                X