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

Removing Draw Objects

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

    Removing Draw Objects

    Hi guys, I'm having some problem removing draw objects despite following the exact example posted by Ryan in a previous thread/post. I have posted a chart where you can see how the objects remain behind from around 20.43 pm. The only reason the ones prior to this time have been removed is because I press F5 which refreshes the chart. I am using COBC = false and need to use this. Relevant snippet of the code based on the attached chart the code I'm using is below. I'd appreciate if you could throw any light on it. Thanks. DJ


    else if (((Close[0]-EMA(18)[0])/Close[0])*100>=0.23 && ((Close[0]-EMA(18)[0])/Close[0])*100<0.28)
    {
    DrawSquare("CLArrow60"+ CurrentBar, true, 0, High[0] +20 * TickSize, Color.White);
    DrawTextFixed("CL60" + CurrentBar, " 60", blPosition, Color.White, textFontMed, Color.Black, Color.Green, 10);

    }



    else if (((Close[0]-EMA(18)[0])/Close[0])*100>=0.28 && ((Close[0]-EMA(18)[0])/Close[0])*100<0.34)
    {
    DrawSquare("CLArrow70"+ CurrentBar, true, 0, High[0] +20 * TickSize, Color.Yellow);
    DrawTextFixed("CL70" + CurrentBar, " 70", blPosition, Color.White, textFontMed, Color.Black, Color.Green, 10);


    }

    else if (((Close[0]-EMA(18)[0])/Close[0])*100>=0.34 && ((Close[0]-EMA(18)[0])/Close[0])*100<0.42)
    {
    DrawSquare("CLArrow80"+ CurrentBar, true, 0, High[0] +20 * TickSize, Color.Lime);
    DrawTextFixed("CL80" + CurrentBar, " 80", blPosition, Color.White, textFontMed, Color.Black, Color.Green, 10);

    }

    else

    {

    RemoveDrawObject("CL60"+ CurrentBar);
    RemoveDrawObject("CLArrow60" + CurrentBar);
    RemoveDrawObject("CL70" + CurrentBar);
    RemoveDrawObject("CLArrow70" + CurrentBar);
    RemoveDrawObject("CL80" + CurrentBar);
    RemoveDrawObject("CLArrow80" + CurrentBar);

    }
    Attached Files

    #2
    The squares that you are removing are not always the squares that you are drawing, as the removal and drawings are in an if ... else statement, meaning that only one is ever executed on any execution of the function. As CurrentBar is changing on each bar, and is part of the tag for the squares, if the conditions that warrant removal of the square occur on any bar other than the bar that caused the square to be drawn, then the square will not be removed. In other words, between the last tick of the last bar and the first tick of the new bar, the tag of the square changed, so any deletion would be directed at the wrong object.

    You probably need to rewrite the code to track the correct tag for the last square drawn, so that you can remove that.
    Last edited by koganam; 03-15-2011, 02:12 AM.

    Comment


      #3
      Remove draw objects

      Thanks Koganam, I am not sure how to write it, in fact I got this from another thread where Ninja Ryan posted this as the code to be used so was surprised it doesn't work as intended. Do you know of any reference where this was used before? Thanks. DJ

      Comment


        #4
        Thanks, koganam, for the explanation here.

        djkiwi - Without seeing the thread you refer, was likely designed to remove drawings for bars currently forming in real time.

        If you are looking for professional coding assistance, I suggest contacting one of our NinjaScript consultants. The snippets provided by NinjaTrader support are designed to help guide in the right direction, but in no way do we guarantee functionality or otherwise offer custom coding services.



        For a sample on removing drawing objects, please see here:
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Thanks Ryan, this is the thread I was referring.



          Your post 7 which makes perfect sense to me. Fernando said it worked and was using COBC close so could not figure out why mine didn't work. Cheers. DJ

          Comment


            #6
            Originally posted by djkiwi View Post
            Thanks Koganam, I am not sure how to write it, in fact I got this from another thread where Ninja Ryan posted this as the code to be used so was surprised it doesn't work as intended. Do you know of any reference where this was used before? Thanks. DJ
            Untested code to illustrate the idea.

            On first tick of new bar, evaluate the past bar and delete objects if necessary, by correctly referencing them with the tag. You may have to convert CurrentBar and (CurrentBar - 1) to "string" in both cases, but I have seen instances where the cast was implicit.

            Code:
            if (!CalculateOnBarClose && FirstTickOfBar)
            {
             if (!(((Close[1]-EMA(18)[1])/Close[1])*100>=0.28 && ((Close[1]-EMA(18)[1])/Close[1])*100<0.34))
            	{
            	RemoveDrawObject("CL60"+ CurrentBar - 1);
            	RemoveDrawObject("CLArrow60" + CurrentBar - 1);
            	}
            
            // repeat and adjust references for the other "if" clauses
            }

            Comment


              #7
              Code Fix

              Thanks for taking the time to post the code. In the interim I messed around with it and fixed by making sure I had the same name, so it just overwrote the same one each time. Corrected code attached for others having the same issue. Cheers. DJ

              else if (((Close[0]-EMA(18)[0])/Close[0])*100<=-0.26 && ((Close[0]-EMA(18)[0])/Close[0])*100>-0.32)
              {

              DrawSquare("-NQsquare" + CurrentBar, false, 0, Low[0] -10 * TickSize, Color.White);

              }

              else if (((Close[0]-EMA(18)[0])/Close[0])*100<=-0.32 && ((Close[0]-EMA(18)[0])/Close[0])*100>-0.40)
              {
              DrawSquare("-NQsquare" + CurrentBar, false, 0, Low[0] -10 * TickSize, Color.Yellow);

              }

              else

              {

              RemoveDrawObject("-NQsquare"+ CurrentBar);

              }

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by JoMoon2024, Today, 06:56 AM
              0 responses
              6 views
              0 likes
              Last Post JoMoon2024  
              Started by Haiasi, 04-25-2024, 06:53 PM
              2 responses
              17 views
              0 likes
              Last Post Massinisa  
              Started by Creamers, Today, 05:32 AM
              0 responses
              5 views
              0 likes
              Last Post Creamers  
              Started by Segwin, 05-07-2018, 02:15 PM
              12 responses
              1,786 views
              0 likes
              Last Post Leafcutter  
              Started by poplagelu, Today, 05:00 AM
              0 responses
              3 views
              0 likes
              Last Post poplagelu  
              Working...
              X