Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How get the last text on a chart?

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

    How get the last text on a chart?

    Hi, i have a indicator that draw on a chart one text when meet conditions. How can get the last text, with the last N bars traded?


    thanks

    #2
    Hello Pbarrionuevo,

    Thanks for your post.

    Is the indicator that draws the text something you created or have access to its source code?

    "How can get the last text, with the last N bars traded?" I'm not sure I understand, can you provide a screenshot the illustrates what you want to accomplish?

    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Yes, i sent the image.


      thanks.


      Click image for larger version

Name:	play a sound for new textbox.jpg
Views:	31
Size:	159.8 KB
ID:	1138423

      Comment


        #4
        Hello Pbarrionuevo,

        Thanks for your reply.

        Is the indicator that draws the text something you created or have the source code for?

        Paul H.NinjaTrader Customer Service

        Comment


          #5
          No, i don't have the source code. I use this code to find it, but get an error:

          foreach (DrawingTool draw in DrawObjects)
          {
          if (draw != null) {
          if (draw.Tag.Contains("up"))
          {
          Log ("fond text: " + draw.Tag, LogLevel.Information);
          Text texto = draw as DrawingTools.Text; // when do this, i receive this error: Default Strategy 'AlertBullBear': Error on calling 'OnBarUpdate' method on bar 0: Object reference not set to an instance of an object.
          // DrawingTools.Text texto = draw as DrawingTools.Text; // and get the same error
          Log ("Bars ago: " + texto.Anchor.BarsAgo, LogLevel.Information);

          Log ("play the sound", LogLevel.Information);
          NinjaTrader.Core.Globals.PlaySound(@"C:\Program Files (x86)\NinjaTrader 8\sounds\CompiledSuccessfully.wav");

          }}

          }

          could it be a different type of object?

          Comment


            #6
            Hello Pbarrionuevo,

            Thanks for your reply.

            Yes, I think it should be DrawingTools.Text texto as in your commented example.

            Here is a similar example I have used to read text on the chart, please give this a try:

            foreach (DrawingTool draw in DrawObjects.ToList())
            {
            if (draw is DrawingTools.Text)
            {
            DrawingTools.Text myText = draw as DrawingTools.Text;
            Print("Tag name: "+myText.Tag+" Displayed text: "+myText.DisplayText);
            }
            }


            Note: Print will send the text to the New>Ninjascript output window which is the recommended place to send debugging text. Excessive use of Log() can lead to performance issues.
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              ok, but how can get the Tag/Text from the last text?


              thanks

              Comment


                #8
                Hello Pbarrionuevo,

                Thanks for your reply.

                You might try checking the DrawObjects.Count and when it changes (meaning you should save it to a variable so you can compare) then perhaps that is your trigger to read.

                When you process each (foreach loop) object you can save the anchor time to a variable and the next time through the list skip anything before that time, when the object is a later time then likely that is your candidate to check.

                DrawingTools.Text myText = draw as DrawingTools.Text;
                Print("Tag name: "+myText.Tag+" Displayed text: "+myText.DisplayText);
                Print("startPrice: " + myText.Anchor.Price);
                Print("startTime: " + myText.Anchor.Time);
                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  I will try.


                  thanks

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by varsha, Today, 06:33 PM
                  0 responses
                  9 views
                  0 likes
                  Last Post varsha
                  by varsha
                   
                  Started by NtFan, Today, 04:12 PM
                  1 response
                  8 views
                  0 likes
                  Last Post NtFan
                  by NtFan
                   
                  Started by futurenow, Today, 01:44 PM
                  2 responses
                  38 views
                  0 likes
                  Last Post voltation  
                  Started by Gerik, Today, 12:44 PM
                  1 response
                  14 views
                  0 likes
                  Last Post NinjaTrader_Jim  
                  Started by autogenix, Today, 01:01 PM
                  3 responses
                  20 views
                  0 likes
                  Last Post NinjaTrader_Emily  
                  Working...
                  X