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 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:	220
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 frankthearm, Yesterday, 09:08 AM
                  12 responses
                  43 views
                  0 likes
                  Last Post NinjaTrader_Clayton  
                  Started by junkone, Today, 11:37 AM
                  1 response
                  12 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by quantismo, 04-17-2024, 05:13 PM
                  5 responses
                  35 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Started by proptrade13, Today, 11:06 AM
                  1 response
                  6 views
                  0 likes
                  Last Post NinjaTrader_Clayton  
                  Started by love2code2trade, 04-17-2024, 01:45 PM
                  4 responses
                  35 views
                  0 likes
                  Last Post love2code2trade  
                  Working...
                  X