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

DrawString vs DrawText

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

    DrawString vs DrawText

    I am experimenting with DrawString to get same functionality that with DrawText.

    The first thing missing is the "tag", this is very useful to uniquely identify what you have painted. So two texts on the same place with different tags overlap.

    With drawstring what I see is that erases all of the above, whether or not overlapping texts. This is so?. means you have to repaint the entire chart every time you paint text?
    So far all I've seen are examples of text in a fixed position, so doesn't matter if text is deleted , but how to paint in each of the bars? Is there to write a loop in each plot () to repaint everything each time?
    An small sample (or big) will be appreciated.

    #2
    Hi Ramon, I'm not sure what you refer to by DrawString? Our NinjaScript would not have such a method unfortunately...

    Could you please clarify?
    BertrandNinjaTrader Customer Service

    Comment


      #3
      graphics.DrawString( text , textFont, textBrush, coord.X ,.coord.Y ,stringFormat);

      I know, i Know, is outside of your scope of support I understand it
      Last edited by Ramon; 01-25-2012, 03:56 AM.

      Comment


        #4
        Thanks for clarifying, I see...this would be unfortunately not a supported method by us, as you're then working into more general C# topics - for example code using graphics.DrawString() you can check into the Pivots indicator shipped with NT.

        You're correct though only the NinjaScript supported draw methods would implement a tag to identify the objects by quicky, with graphics.DrawString() you're working outside of this framework to custom draw in C#.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Originally posted by Ramon View Post
          graphics.DrawString( text , textFont, textBrush, coord.X ,.coord.Y ,stringFormat);

          I know, i Know, is outside of your scope of support I understand it
          Create a struct with a tag as one of its properties, and the DrawString() method. The struct is then an object, and you can reference it by its "tag" property.

          Comment


            #6
            Mmmmm You're talking about structures or classes, or perhaps be indiferent ? I'll think about it, if you were so kind to give me a referral that I could see I would be very grateful.
            Koganam thanks again,I appreciate your advice that they have always been very useful.

            Comment


              #7
              Originally posted by Ramon View Post
              Mmmmm You're talking about structures or classes, or perhaps be indiferent ? I'll think about it, if you were so kind to give me a referral that I could see I would be very grateful.
              Koganam thanks again,I appreciate your advice that they have always been very useful.
              The major difference between a struct and a class is the amount of code that needs to be handled. (There are property differences, I know). Basically, if you can use a struct, you can also use a class. The issue is that for handling small data constructs, a class is usually overkill.

              From the Microsoft site: "In general, classes are used to model more complex behavior, or data that is intended to be modified after a class object is created. Structs are best suited for small data structures that contain primarily data that is not intended to be modified after the struct is created."

              ref: http://msdn.microsoft.com/en-us/library/ms173109.aspx

              Comment


                #8
                I've been busy with other matters but I will continue with this .I have little experiencie in programming so I have followed many of your recommendations as to create a "namespace" named as the indicator.
                You meant something like that? I need to know how to reference the object instance and link it to the bar that is trying.

                Code:
                ...
                using StructString;
                ...
                namespace StructString
                {
                    struct TagString
                    {
                        public int iCurBar;
                        public double dPrice;
                        public string sTag;
                        public  TagString(double price, int curbar)
                        {
                            this.dPrice=price;
                            this.iCurBar = curbar;
                            this.sTag = curbar.ToString()+ price.ToString();
                        }
                }
                ...
                        private TagString strString;
                ...
                strString = new TagString(Close[0],CurrentBar);
                ...
                    public override void Plot(Graphics graph, Rectangle bounds, double min, double max)
                        {
                    for (int idx = lastBar; idx >= firstBar; idx--)
                            {
                                string sTag = idx.ToString()+lastPrice.ToString();
                                if (sTag == strString.sTag)
                            {
                            {
                                 int x = ChartControl.GetXByBarIdx(BarsArray[0], idx);
                                 int y = ChartControl.GetYByValue(this, lastPrice);
                                 graph.DrawString(strString.sTag, ChartControl.Font, textBrush, x, y, stringFormat);
                             }
                    
                            }

                Comment


                  #9
                  Originally posted by Ramon View Post
                  I've been busy with other matters but I will continue with this .I have little experiencie in programming so I have followed many of your recommendations as to create a "namespace" named as the indicator.
                  You meant something like that? I need to know how to reference the object instance and link it to the bar that is trying.

                  Code:
                  ...
                  using StructString;
                  ...
                  namespace StructString
                  {
                      struct TagString
                      {
                          public int iCurBar;
                          public double dPrice;
                          public string sTag;
                          public  TagString(double price, int curbar)
                          {
                              this.dPrice=price;
                              this.iCurBar = curbar;
                              this.sTag = curbar.ToString()+ price.ToString();
                          }
                  }
                  ...
                          private TagString strString;
                  ...
                  strString = new TagString(Close[0],CurrentBar);
                  ...
                      public override void Plot(Graphics graph, Rectangle bounds, double min, double max)
                          {
                      for (int idx = lastBar; idx >= firstBar; idx--)
                              {
                                  string sTag = idx.ToString()+lastPrice.ToString();
                                  if (sTag == strString.sTag)
                              {
                              {
                                   int x = ChartControl.GetXByBarIdx(BarsArray[0], idx);
                                   int y = ChartControl.GetYByValue(this, lastPrice);
                                   graph.DrawString(strString.sTag, ChartControl.Font, textBrush, x, y, stringFormat);
                               }
                      
                              }
                  Unfortunately, I am not sure what you are trying to do. You asked a question, and I gave you the general paradigm on how to create an object, so that you could tag your DrawString(). However, that does mean that you will need to be creating unique objects, much as when you use DrawText() to reference different objects, you need to create unique IDrawText objects.

                  Reading over your snippet of code gives me the impression that you are trying to draw the bar numbers at each bar. If that is so, then it appears to me that you are reinventing the wheel? It is very easy to use DrawText() to perform that function without having to effectively recode it for one custom use.
                  Last edited by koganam; 04-02-2014, 04:06 PM. Reason: Corrected spelling.

                  Comment


                    #10
                    As I said in my first post

                    I am experimenting with DrawString to get same functionality that with DrawText.

                    The first thing missing is the "tag", this is very useful to uniquely identify what you have painted. So two texts on the same place with different tags overlap.
                    And your answer was

                    Create a struct with a tag as one of its properties, and the DrawString() method. The struct is then an object, and you can reference it by its "tag" property.
                    ... and this is what I'm trying but I'm not sure how to use these "tags"
                    Could you put some piece of code ?

                    Note,- I have none interest in reinventing the wheel , but iwould not mind be the owner of the patent

                    Comment


                      #11
                      The main advantage of DrawText is that the system handles all. You only have to worry about the tags are unique to the position where you want to write.
                      If you want to overwrite something, just put the same tag and the system takes care of deleting the previous one and write the new one. Different tags are new objects and if they match the coordinates overlap themselves. This is a great advantage to enter text, both in absolute and relative coordinates.
                      To achieve the same functionalitty with DrawString , the programer need take full control of the position to manage where put the text. I tried to take advantage of the Koganam's recommendation without success. He is an advanced user and his goodness thinks that others have an acceptable level. His recommendation to draw into two panels simultaneously with "DOPP = True / False" works perfectly

                      I am still using the structure and I have any problems that not have using a "class", but surely there is a bug anywhere.

                      The only way I can think of is to use collections into other collections, so it covers the entire spectrum of screen coordinates. Something like :
                      Code:
                      Dictionary<int,SortedList<int,TagString>> dictStr = new Dictionary<int,SortedList<int,TagString>>();
                      This reminds me the old arithmetic of pointers that I never mastered and many times hung my computer.
                      Attached Files
                      Last edited by Ramon; 02-08-2012, 10:36 AM.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by pechtri, 06-22-2023, 02:31 AM
                      9 responses
                      122 views
                      0 likes
                      Last Post NinjaTrader_ChelseaB  
                      Started by frankthearm, 04-18-2024, 09:08 AM
                      16 responses
                      65 views
                      0 likes
                      Last Post NinjaTrader_Clayton  
                      Started by habeebft, Today, 01:18 PM
                      1 response
                      5 views
                      0 likes
                      Last Post NinjaTrader_ChelseaB  
                      Started by benmarkal, Today, 12:52 PM
                      2 responses
                      13 views
                      0 likes
                      Last Post benmarkal  
                      Started by f.saeidi, Today, 01:38 PM
                      1 response
                      7 views
                      0 likes
                      Last Post NinjaTrader_BrandonH  
                      Working...
                      X