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 Can I set "IsGlobalDrawingTool" to true or false?

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

    How Can I set "IsGlobalDrawingTool" to true or false?

    Morning.

    I want to set the property "IsGlobalDrawingTool" of a Custom Drawing Tool by source code, but it's readonly and can't change if I want it draw on All Charts.


    I tried other option i saw in forum;

    Code:
    foreach (DrawingTool draw in DrawObjects.ToList())
    {
    DrawingTool.SetDrawingToolCommonValues(draw, draw.Tag, draw.IsAutoScale, this, true);
    }


    But I can't use DrawObjects.ToList() because it's static and throw an error.

    Thanks.
    Last edited by franjcy; 06-15-2024, 01:57 PM.

    #2
    Hello franjcy,

    There is not a specific way to do that from code, for an object to be drawn globally it would need to be configured that way when it is drawn either manually or in code using one of the overloads that lets you specify that it is a global object.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello franjcy,

      There is not a specific way to do that from code, for an object to be drawn globally it would need to be configured that way when it is drawn either manually or in code using one of the overloads that lets you specify that it is a global object.
      Would there be any way to "duplicate" my actual custom drawing tool setting this new to global and deleting the first one?

      I just know a few default tools like Draw.Line(...) that permits global parameter.

      Or other question, Is there any way to apply from code an .xml template to a custom drawing tool and so, setting it globlal?

      Thanks.

      Comment


        #4
        Hello franjcy,

        If the object is manually drawn then no, you could only add another object that has the same values but you would not be able to remove the manually draw object using code. If your script originally drew the object then yes, you would use RemoveDrawObject to remove it and then draw a new object using the overload that has IsGlobal.

        Templates do not contain if the object is global, that is specific to how the object was applied or drawn.

        JesseNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Jesse View Post
          Hello franjcy,

          If the object is manually drawn then no, you could only add another object that has the same values but you would not be able to remove the manually draw object using code. If your script originally drew the object then yes, you would use RemoveDrawObject to remove it and then draw a new object using the overload that has IsGlobal.

          Templates do not contain if the object is global, that is specific to how the object was applied or drawn.
          To give you more context, in case you can help me, I'm modifing the Line Drawing Tool of NinjaTrader ( public class Linea : DrawingTool ... ). I modified the original with some improvements.

          Inside, I'm reading the .xml templates directly, and putting one by one label (brushes, stroke, font, size, etc.) into drawn line. The only problem i have is putting a local chart line or global charts line.

          Your'e saying "Templates do not contain if the object is global" but I don't think so, if it were like that, how is it possible Ninja when a template is loaded manually knows if the object is local or globall? I think the label who controlls this is <GlobalLastSeenSerialize>0</GlobalLastSeenSerialize>.

          Thanks, i Hope you help me.




          Last edited by franjcy; 06-18-2024, 11:09 AM.

          Comment


            #6
            Hello franjcy,

            Reading the template files directly would not be something I could assist with, the properties in the file may change at any time, may be only used internally and are not documented or intended to be used directly like that. Templates are loaded through the user interface and applied to an object. There is the concept of a default template that is always used and a template that is loaded using the Ui to apply specific settings. The AttachedTo dropdown list is used to determine if a object is global or not when using the user interface. In NinjaScript a global object is determined by passing true or false of IsGlobal in the overloads that offer setting the object to global. There is not a way to change an object to a global object from NinjaScript after it has been drawn but you can draw the object initially as a global object either in the UI or in NinjaScript.
            Last edited by NinjaTrader_Jesse; 06-18-2024, 11:12 AM.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Jesse View Post
              Hello franjcy,

              Reading the template files directly would not be something I could assist with, the properties in the file may change at any time, may be only used internally and are not documented or intended to be used directly like that. Templates are loaded through the user interface and applied to an object. There is the concept of a default template that is always used and a template that is loaded using the Ui to apply specific settings. The AttachedTo dropdown list is used to determine if a object is global or not when using the user interface. In NinjaScript a global object is determined by passing true or false of IsGlobal in the overloads that offer setting the object to global. There is not a way to change an object to a global object from NinjaScript after it has been drawn but you can draw the object initially as a global object either in the UI or in NinjaScript.
              I understand all, but when I save a template "local chart" or "all charts" and then, I load it (template, load) it loads what I saved before, local or global.

              So with the context I mentionated before (Line custom drawing tool), don't you have any posible solution to achieve what i mean, either with not documented function, or creating this Line from code and then deleting with "RemoveDrawObject " or some other?

              Thanks.
              Last edited by franjcy; 06-18-2024, 11:53 AM.

              Comment


                #8
                Hello franjcy,

                We have already covered all the suggestions that I can recommend for this situation, the global property cannot be dynamically set in code so manipulating the drawing objects collection would not be an option to change existing objects to global or back. In contrast to a custom drawing object you would need to either use a template, default template or if the object is being used from NinjaScript one of the overloads that supports global/template can be used to draw the object as global.

                Once an object has been drawn you can only manually change its global status using the drawing objects properties window so the object would need to be drawn initially as global if you wanted it always global and you would need to manually change it if you wanted to remove it from being global later. For objects that were not drawn global you can manually change them later using the properties menu but there is no way to programmatically do that.

                I wouldn't be able to look into any unsupported use cases as that is out of the scope that our support can assist. You can certainly explore that side of the programming to see if you can find a custom solution however keep in mind if you do find something that works that may not stay that way forever. if you use undocumented properties/methods or approaches like reading the template file directly that may change with updates in the future.

                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_Jesse View Post
                  Hello franjcy,

                  We have already covered all the suggestions that I can recommend for this situation, the global property cannot be dynamically set in code so manipulating the drawing objects collection would not be an option to change existing objects to global or back. In contrast to a custom drawing object you would need to either use a template, default template or if the object is being used from NinjaScript one of the overloads that supports global/template can be used to draw the object as global.

                  Once an object has been drawn you can only manually change its global status using the drawing objects properties window so the object would need to be drawn initially as global if you wanted it always global and you would need to manually change it if you wanted to remove it from being global later. For objects that were not drawn global you can manually change them later using the properties menu but there is no way to programmatically do that.

                  I wouldn't be able to look into any unsupported use cases as that is out of the scope that our support can assist. You can certainly explore that side of the programming to see if you can find a custom solution however keep in mind if you do find something that works that may not stay that way forever. if you use undocumented properties/methods or approaches like reading the template file directly that may change with updates in the future.
                  Thank for the answer, so If I understood correctly, there is only posibilty: "a custom drawing object that supports global/template can be used to draw the object as global."

                  I tried creating inside my Drawing Tool called LineaPro the class Draw, copied from original class Line, like this:

                  Code:
                  public static partial class Draw
                  {
                  private static T DrawLineTypeCoreMod<T>(NinjaScriptBase owner, bool isAutoScale, string tag,
                  int startBarsAgo, DateTime startTime, double startY, int endBarsAgo, DateTime endTime, double endY,
                  Brush brush, DashStyleHelper dashStyle, int width, [B]bool isGlobal[/B], string templateName) where T : LineaPro
                  ....
                  And then creating new Drawing Tool inside my LineaPro Drawing Tool, like this:

                  Code:
                  Draw.LineaPro(this.DrawnBy, "tag", true, 1, 500, 0, 2000, [B]true[/B], "SMT");
                  But it seems not working, it shows a error on output:

                  Code:
                  Error al modificar la ventana del gráfico: owner
                  In english should be:
                  Code:
                  Error modifying chart window: owner


                  Comment


                    #10
                    Hello franjcy,

                    The only supported way to use drawing objects is to pass the "this" instance when drawing it, you are using this.DrawnBy which I would not be sure of what result that would have. The object will figure out in its internal code where to attach the object, in NinjaScript you would only need to specify this

                    Draw.LineaPro(this, ....
                    JesseNinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_Jesse View Post
                      Hello franjcy,

                      The only supported way to use drawing objects is to pass the "this" instance when drawing it, you are using this.DrawnBy which I would not be sure of what result that would have. The object will figure out in its internal code where to attach the object, in NinjaScript you would only need to specify this

                      Draw.LineaPro(this, ....
                      I tried just with 'this' but it shows the next error: "can't be converted the type 'Ninjatrader.NinjaScript.DrawingTools.LinePro' to ''Ninjatrader.NinjaScript.NinjaScriptBase". I don't know why this ocurrs because it inherits same that Line original.

                      I tried casting Draw.LineaPro((NinjaScriptBase)this, ... but the same results.

                      Comment


                        #12
                        Hello franjcy,

                        The syntax to draw an object is just the object this

                        Draw.LineaPro(this

                        That will work as long as you have defined the correct Draw methods in your drawing object, you can see the original Line tool to compare what you made against that to check that it is correct. In the file you would need to have 3 methods in the static draw class that replicate the DrawLineTypeCore, the private static Line Line method that uses DrawLineTypeCore and then the method with the parameter for IsGlobal if you wanted to use global lines. You will need the logic inside DrawLineTypeCore to configure the object when its drawn.

                        JesseNinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_Jesse View Post
                          Hello franjcy,

                          The syntax to draw an object is just the object this

                          Draw.LineaPro(this

                          That will work as long as you have defined the correct Draw methods in your drawing object, you can see the original Line tool to compare what you made against that to check that it is correct. In the file you would need to have 3 methods in the static draw class that replicate the DrawLineTypeCore, the private static Line Line method that uses DrawLineTypeCore and then the method with the parameter for IsGlobal if you wanted to use global lines. You will need the logic inside DrawLineTypeCore to configure the object when its drawn.

                          Morning. I think the 3 methods you are talking about are well setted in my code.

                          But the error is throwing (can't be converted the type 'Ninjatrader.NinjaScript.DrawingTools.LinePro' to ''Ninjatrader.NinjaScript.NinjaScriptBase"), it couldn't be because the call to Draw.LineaPro(this...) inside DrawingTool is well because a DrawingTool class is not inheriting from NinjaScriptBase??

                          Comment


                            #14
                            Hello franjcy,

                            The Draw methods that are inside of the drawing objects code are only for use in other types like indicators or strategies, you can't use the draw method from the drawing object its self.
                            JesseNinjaTrader Customer Service

                            Comment


                              #15
                              Ok so there’s no option to achieve my goal as I can see.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by MatthewLesko, 05-21-2021, 09:37 PM
                              4 responses
                              163 views
                              0 likes
                              Last Post Mahmad1323  
                              Started by samish18, Today, 03:02 PM
                              3 responses
                              15 views
                              0 likes
                              Last Post bltdavid  
                              Started by Jakub, Today, 11:06 AM
                              1 response
                              16 views
                              0 likes
                              Last Post NinjaTrader_LuisH  
                              Started by samish18, Today, 03:50 AM
                              10 responses
                              19 views
                              0 likes
                              Last Post samish18  
                              Started by Mestor, 06-03-2018, 10:09 AM
                              16 responses
                              2,872 views
                              0 likes
                              Last Post myaha1000  
                              Working...
                              X