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

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
    Chris L.NinjaTrader Customer Service

    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.

            Chris L.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by carnitron, Today, 08:42 PM
            0 responses
            5 views
            0 likes
            Last Post carnitron  
            Started by strategist007, Today, 07:51 PM
            0 responses
            6 views
            0 likes
            Last Post strategist007  
            Started by StockTrader88, 03-06-2021, 08:58 AM
            44 responses
            3,974 views
            3 likes
            Last Post jhudas88  
            Started by rbeckmann05, Today, 06:48 PM
            0 responses
            8 views
            0 likes
            Last Post rbeckmann05  
            Started by rhyminkevin, Today, 04:58 PM
            4 responses
            58 views
            0 likes
            Last Post dp8282
            by dp8282
             
            Working...
            X