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 Russ Moreland, Today, 12:54 PM
        0 responses
        1 view
        0 likes
        Last Post Russ Moreland  
        Started by f.saeidi, Today, 12:14 PM
        2 responses
        5 views
        0 likes
        Last Post f.saeidi  
        Started by TradeForge, 04-19-2024, 02:09 AM
        2 responses
        28 views
        0 likes
        Last Post TradeForge  
        Started by aprilfool, 12-03-2022, 03:01 PM
        3 responses
        327 views
        0 likes
        Last Post NinjaTrader_Adrian  
        Started by giulyko00, Today, 12:03 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Working...
        X