Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Setting an Object to Global from Indicator

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

    Setting an Object to Global from Indicator

    Hello,

    Is it possible to set an object to global from an indicator? Specifically, the indicator draws an object and I would like it to be on all charts of the same instrument.

    Thanks
    Unsuitable
    NinjaTrader Ecosystem Vendor - Ocean Trading Indicators

    #2
    Hi, thanks for posting. You can use the IsGlobal parameter to make the drawing tool global when creating the draw object e.g.:

    Draw.HorizontalLine(NinjaScriptBase owner, string tag, double y, bool isGlobal, string templateName)

    It can only be set to global at this time, not after the object is created.

    Kind regards,
    -ChrisL

    Comment


      #3
      Hello ChrisL,

      That would do it. It appears that previously another overload method was used. Probably due to getting the X value via time and not bars ago. This was one of the first indicators made... pretty sure I've converted time to bars ago in future indicators. Thus, I can use the method mentioned above.

      Thanks
      Unsuitable
      NinjaTrader Ecosystem Vendor - Ocean Trading Indicators

      Comment


        #4
        Hello ChrisL,

        After trying to implement the change, it is not working. It gives this error:

        Code:
        Unhandled exception: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
        This was the code that causes it. Keep in mind I changed all the values to hard values and same result. Tried specifying a template name and leaving it blank so it goes to default, no luck.

        Code:
        text = Draw.Text(this, "testing", "gap", 101, 1980, false, "");
        text is a dynamic variable. Tried using Draw.Text directly and the same thing. Any clue what's going on?

        Thanks
        Unsuitable
        NinjaTrader Ecosystem Vendor - Ocean Trading Indicators

        Comment


          #5
          For some reason, the most I can do is ~5 bars ago. When that is set, it goes past the beginning of the chart. For now, it's set to be created at 0 bars ago and the time anchor is set after the object is created.

          The problem now is refreshing the indicator erases the global object. Beforehand I'd set the DrawnBy property to null and create a new attachedTo property. This would prevent the object from getting erased as it is now attached to the chart. Again this is unsupported. The better way would be to set the proper object owner from the beginning, but I haven't gotten any help on it as it's unsupported.

          Code:
          text.DrawnBy = null;
          text.IsLocked = false;
          
          NinjaTrader.NinjaScript.DrawingTools.DrawingToolAttachedTo newAttachedTo = new NinjaTrader.NinjaScript.DrawingTools.DrawingToolAttachedTo();
          newAttachedTo.ChartObject = ChartBars;
          newAttachedTo.Instrument = this.Instrument;
          text.AttachedTo = newAttachedTo;
          - text.IsLocked can be changed with no issues
          - text.DrawnBy causes major issues for global objects

          A DrawnBy property of null indicates it was drawn by the user. This hack works fine for text objects localized to a single instrument. When done to a global object, the indicator freaks out. After hitting refresh, the object duplicates, and the indicator crashes. The indicator only pops back up when deleting the global objects.

          Chris, do you have any insight on how to make global objects persist upon refreshing the chart?

          Thank you
          Unsuitable
          NinjaTrader Ecosystem Vendor - Ocean Trading Indicators

          Comment


            #6
            Hi, thanks for posting. If you are putting unsupported code (accessing time slots that do not yet exist on the chart) then the refresh breaking globals would be unsupported. If you are seeing the globals not re-appear after refreshing and the timestamps are already on the chart, please post an example script that reproduces the issue.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            656 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            371 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            109 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            574 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            579 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X