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

hiding text by button

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

    hiding text by button

    Hi,
    is it possible to hide any text element in the chart via button? I need it to toggle between the pure chart without my comments and with it. I think it's possible to change the color but this isn't professional and hide any other elements...

    Thanks
    Mario
    Last edited by md236; 06-27-2017, 09:11 AM.

    #2
    Hello Mario,

    Thanks for opening the thread.

    NinjaScripts can only modify a chart's drawing objects that have been made from that NinjaScript. So this would be possible to do if you have the indicator that writes your notes create a button that would change the text brush of your Text DrawingTool objects. There is not a simple method to call that would hide and show text, changing the color would be the most direct way of doing this.

    Code:
    myText.TextBrush = Brushes.Transparent;
    Here is a link to some samples written by our colleague Chelsea that demonstrate how to create your own buttons on a chart: http://ninjatrader.com/support/forum...327#post499327

    Please let me know if I may be of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      Hi Jim,

      thanks for the information but the link you provided is for NT8 only.
      My code, so far, react to an button and I can isolate the Text objects, but sometimes it works and then not, don't know why. The text object seems to be a copy of the original because if I use a different color as transparent, then it results in two text objects.
      I tried to implement a try-catch but I got the error that "a local variable e can't declared here". What's wrong here?


      Code:
      	
      		private void ButtonClick(object s, EventArgs e) {
      			int i =0;
      			try{
      				if(isVisible){
      					foreach (IDrawObject draw in ChartControl.ChartObjects)
      					{
      						if(draw.DrawType == DrawType.Text){
      							i++;						
      							IText txt = (IText)draw;  
      							Print("Tag: " +draw.Tag+" Text: "+ txt.Text); 
      							DrawText(draw.Tag,txt.Text,txt.BarsAgo,txt.Y,Color.Transparent);
                                                              // change Color of the button
      							flagGraphics.FillRectangle(Brushes.LightBlue, 0, 0, 30, 30);
      						}
      					}				
      				}else{
      					foreach (IDrawObject draw in ChartControl.ChartObjects)
      					{
      						if(draw.DrawType == DrawType.Text){
      							IText txt = (IText)draw;  
      							DrawText(draw.Tag,txt.Text,txt.BarsAgo,txt.Y,Color.White);
      							flagGraphics.FillRectangle(Brushes.Red, 0, 0, 30, 30);
      						}
      					}				
      				}
      			}
      			catch(Exception e){
      				Print("error: " +e.ToString());
      			}
      			finally{
      				Print("text objects found: " + i);
      				isVisible= !isVisible;
      				ChartControl.Refresh();
      			}
      		}
      Mario
      Last edited by md236; 06-28-2017, 06:03 AM.

      Comment


        #4
        Hello Mario,

        Thanks for pointing that out. It looks like I misread the forum name. Oops!

        The text object seems to be a copy of the original because if I use a different color as transparent, then it results in two text objects.
        I see that you are looping through each drawing object in the chart. Each of these drawing objects will have to be made by the NinjaScript where you have the button to change the text color if you would like that NinjaScript to change them. NinjaScripts cannot modify drawing objects that they do not own.

        I would recommend to use IText objects to organize each of your DrawText()'s in this indicator and to change the IText.TextColor instead of looping through all of the chart's draw objects and recalling DrawText(). This way the expected behavior would be clear and observable, and you wouldn't risk creating a new draw object for one created outside this NinjaScript.

        I tried to implement a try-catch but I got the error that "a local variable e can't declared here". What's wrong here?
        It looks like you are already using the variable 'e' for the ButtonClick() method. You would need to use a different variable for the try/catch Exception.

        Here are some NinjaTrader 7 relevant resources for the thread's reference.

        IText - https://ninjatrader.com/support/help.../nt7/itext.htm

        DrawText() - https://ninjatrader.com/support/help...m?drawtext.htm

        NinjaTrader 7 button sample - http://ninjatrader.com/support/forum...php?linkid=490

        Please let me know if I may be of further assistance.
        JimNinjaTrader Customer Service

        Comment


          #5
          Hi Jim,

          good observation with the double "e" variable
          I just removed the DrawText... and used the way you showed via IText to change Color and it works now

          Thank you
          Mario
          Last edited by md236; 06-29-2017, 04:45 AM.

          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
          2 responses
          12 views
          0 likes
          Last Post junkone
          by junkone
           
          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