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

DrawText start bars ago < 0

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

    DrawText start bars ago < 0

    Originally posted by NinjaTrader_Ray View Post
    What was reported on EliteTrader are custom indicators disappearing off the chart. This is what will happen if there is erroneous user generated code in the indicator script. Basically, if there is a bug in a custom script, NT terminates the script (instead of crashing the application), writes out some information to the Log tab and removes it from the chart since it can on longer run.
    Ray, thanks you for the info. In my case, the intermittent disappearing indicator was VolumePRV, and I checked the log today. There were only three identical messages related to the indcator. A snapshot of the message is attached below.

    I use DrawText method twice, once for when the session is inactive
    DrawText("PRVnum", "PRV off", -3, PRVol, Color.Black);

    and once during every BarUpdate (every tick) to recalculate Volume.
    DrawText("PRVnum", "PRV = " + PRVol.ToString(), -4, PRVol+200, Color.Black);

    This works and does exactly what is needed - prints the message to the right of the bar. Please see attached picture. Note that barsago is ALWAYS negative and rarely is there a log error (3 out of how many tick updates?). I now realize that this is probably an unexpected usage for ya'll; however it works. The intermittent log message seems to be a bug, and hopefully that can be fixed.

    It is important to have the text to the right of the bar to avoid interference (readability) and I have always appreciated the fact that the Ninjatrader code is executed without error on most days.

    BTW, if DrawTextFixed printed to the indicator pane I might have used it instead originally, but now I rather like that the Text floats with the Volume bar.
    Attached Files

    #2
    Thanks for clarifying. For sure using negative values is not promoted usage. If it works sometimes then that is just a positive side effect. We do not guarantee that it works all the time, hence the error messages in the log.
    RayNinjaTrader Customer Service

    Comment


      #3
      Hi Ray!
      The fact that it is intermittent does indicate that there is another problem underneath somewhere and I hope y'all can get it fixed.

      I wonder if it has to do with the white space on the right eventually being used up -- if I step away from the computer and the white space is filled with bars then that may be when the problem occurs. I'll keep an eye out, as I do not wish to change the # to 0 (given the picture, I am sure you understand why) If I could guarantee a minimum # of empty bars on the right of that chart, that might fix it...

      Comment


        #4
        Yes, for sure there is an issue but its outside of the methods intended use. We do not support negative index values. I have sent this to development to either trap negative index value usage or see if we can provide official support for it.
        RayNinjaTrader Customer Service

        Comment


          #5
          I decided to change the DrawText command so that barsago can be 0, and I padded the string with blanks. My blanks were removed.

          The only way I could get the blanks space was to put a non-blank chaacter in the first position.
          DrawText("PRVnum", ". PRV off", 0, PRVol, Color.Black);

          Do you do that deliberately? if so, please mention that in your help...
          How can I put leading blanks in without the leading period?
          Is there a character to force a blank, or multiple (n) blanks?
          \t for tab also did not work.

          Thanks!!

          Comment


            #6
            Maybe you could try something like this:
            Code:
            char t = '\u0020';
            string text = "text1".PadLeft(100, t);
            DrawText("tag", text, 1, Close[0], Color.Black);
            Note: This may not be the best way of doing it.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Hi Lost Trader !

              The default alignment of strings in DrawText is 'Center'. You might consider using a different signature of DrawText(...):

              DrawText("1", false, "Test", 10, Low[10] - 0.1, Color.Green, null, StringAlignment.Near, Color.Empty, Color.Empty, 0);
              DrawText("2", false, " Test", 10, Low[10] - 0.2, Color.Red, null, StringAlignment.Near, Color.Empty, Color.Empty, 0);

              Kind regards,
              Christian
              ChristianSenior Software Developer

              Comment


                #8
                Guys, y'all are great.

                I actually tried both. Went with the padleft for now only because the string alignment.near had the text starting immediately at the colored bar edge with no white space at all. One blank would have helped... It is a readability thing to me, my eyes are bad enough.

                I may play with it some more, but I really appreciate the solutions -- thank you!

                P.S. please add to the help text the fact that the barsago # is the center of the written text for the first DrawText version. Thanks!!

                Comment


                  #9
                  Thanks for the suggestion.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    NinjaTrader_Josh , that code doesn't work and goofed up my existing code.

                    Comment


                      #11
                      piptek, if Josh's code messes up your code, I would recommend removing his code. His post is from 2008; a lot has changed in NinjaTrader since then. What are you trying to do here?
                      AustinNinjaTrader Customer Service

                      Comment


                        #12
                        Asking for an example

                        I am trying to display "Text1" for right now at the left corner top of to chart window... it may be Hgih or Low. but once I know the syntax I can display anything I like to... and I am surprised also none of the support gave a plain vanilla example of DrawTextFixed just like this with DrawText...

                        int LeftSideOfScreen = ChartControl.FirstBarPainted;
                        DrawText("Test", false, "Text to show at left side of screen",
                        (CurrentBar - LeftSideOfScreen), Close[0], 0, Color.Yellow, new Font("Arial" , 12),
                        StringAlignment.Near, Color.Transparent, Color.Transparent, 2);
                        thanks for what you do.....

                        Comment


                          #13
                          Originally posted by piptek View Post
                          I am trying to display "Text1" for right now at the left corner top of to chart window... it may be Hgih or Low. but once I know the syntax I can display anything I like to... and I am surprised also none of the support gave a plain vanilla example of DrawTextFixed just like this with DrawText...

                          int LeftSideOfScreen = ChartControl.FirstBarPainted;
                          DrawText("Test", false, "Text to show at left side of screen",
                          (CurrentBar - LeftSideOfScreen), Close[0], 0, Color.Yellow, new Font("Arial" , 12),
                          StringAlignment.Near, Color.Transparent, Color.Transparent, 2);
                          thanks for what you do.....
                          Take a look at this thread, where I responded to another user. Does it pass muster?

                          Comment


                            #14
                            piptek, unfortunately all of the ChartControl properties/methods are unsupported, so we can't help you out here. Please try koganam's suggestion, he is usually right on the money.
                            AustinNinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by CortexZenUSA, Today, 12:53 AM
                            0 responses
                            1 view
                            0 likes
                            Last Post CortexZenUSA  
                            Started by CortexZenUSA, Today, 12:46 AM
                            0 responses
                            1 view
                            0 likes
                            Last Post CortexZenUSA  
                            Started by usazencortex, Today, 12:43 AM
                            0 responses
                            5 views
                            0 likes
                            Last Post usazencortex  
                            Started by sidlercom80, 10-28-2023, 08:49 AM
                            168 responses
                            2,265 views
                            0 likes
                            Last Post sidlercom80  
                            Started by Barry Milan, Yesterday, 10:35 PM
                            3 responses
                            11 views
                            0 likes
                            Last Post NinjaTrader_Manfred  
                            Working...
                            X