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

How to check if a drawobject exists?

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

    How to check if a drawobject exists?

    Try to get rid of some repeating drawobjects. Is there a ninjascript or c# function like this:
    boolean ExistsDrawObject(TagID).

    Thanks in advance.

    #2
    I don't know if such does exist but I'd be surprised if it doesn't exist.

    That said, I've written a couple of "target" drawing indicators where I want to know....say the mid point of the last swing or the 100% extension of the prior upswing after a retracement.

    In those cases I also want to know a couple or a few of the prior "targets" but I also do not want to have targets painted all the way back to the beginning of the chart.

    So, the solution I use is a simple toggle.

    int toggle = 0;

    toggle++; // on each instance of wanting to draw something

    DrawDot("Tag" + (toggle % 3), 0, CCI(14)[0], Color.Red);

    toggle % 3 means divide toggle by 3 and give me the remainder ( modulus math function ). So the numeric value being appended to "Tag" is always going to be 0,1 or 2 and as those cycle so to does the dot on the screen since C# will just remove the last instance of Tag0 and draw a new Tag0 at the new location.

    It's an approach that reduces management but isn't right for all situations. Where I've used it I've set the divisor ( 3 in the example ) as a parameter I can adjust because at smaller time frames I may not want any targets but at larger ones I may want 4 or 5.

    No idea if it is right for what you are doing, just tossing it out as an idea.

    Comment


      #3
      Newshues, thanks for sharing your idea. I'll use a variable to store the Currentbar of the Drawobject. A new Drawobject will be drawn only if my rules are passed && (new Currentbar - stored Currentbar) > 2. This will get rid of the 3 consecutive drawobjects in a row situation.

      Comment


        #4
        Thanks for the ideas guys, there is no collection of draw object tag Id's.
        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by elirion, Today, 01:36 AM
        2 responses
        12 views
        0 likes
        Last Post elirion
        by elirion
         
        Started by DJ888, 04-16-2024, 06:09 PM
        5 responses
        14 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by samish18, Yesterday, 08:31 AM
        4 responses
        14 views
        0 likes
        Last Post elirion
        by elirion
         
        Started by funk10101, Yesterday, 09:43 PM
        1 response
        14 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by TheWhiteDragon, 01-21-2019, 12:44 PM
        5 responses
        551 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X