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 red text that I have highlighted.
    
    			if (Close[0] > Close[1] && Low[0] > Low[1] && High[0] > High[1])
    			{
    				DrawText("ObviousDownBar" + CurrentBar, true, "M", 0, Low[0] - 1 * TickSize, 0, Color.White, ObviousBar, StringAlignment.Center, Color.Transparent, Color.Black, 0);
    			}
    			else
    			RemoveDrawObject("ObviousDownBar");

    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 JTizz, Today, 03:32 PM
                1 response
                33 views
                0 likes
                Last Post NinjaTrader_ChrisL  
                Started by ebaydan777, Today, 02:41 PM
                1 response
                27 views
                0 likes
                Last Post NinjaTrader_ChrisL  
                Started by aligator, Today, 02:28 PM
                1 response
                27 views
                0 likes
                Last Post NinjaTrader_ChristopherJ  
                Started by daniel_weber8, Today, 01:21 PM
                1 response
                43 views
                0 likes
                Last Post NinjaTrader_ChristopherS  
                Started by jungsoohuh, Today, 12:07 PM
                1 response
                35 views
                0 likes
                Last Post NinjaTrader_PaulH  
                Working...
                X