• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

retaining drawing objects on refresh

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

    retaining drawing objects on refresh

    Hi all,

    I have an indicator that draws on the chart. Whenever I refresh the chart by clicking F5 or by adding another indicator, the drawings get removed.

    I keep state with private vars which I use to draw - these also get set to the default values in the above cases. In short, I lose my drawings and the info I need to redraw them.

    Any thoughts on how to keep this from happening?

    Onn

    #2
    Hello Onn,

    Thank you for your post.

    When this occurs are there errors on the Log tab of the Control Center? If so, what do these errors report?

    Can you provide a snippet of code for a drawing object that does not re-draw when reloading NinjaScript?

    I look forward to your response.
    Patrick H.NinjaTrader Customer Service

    Comment


      #3
      hi, I should have been more clear. It is not an error.
      Say I have a pair of coodinates that I use to draw a line with. I store those coordinates as variables in my indicator. Those coordinates are not calculated - they are provided by the user by clicking the mouse.

      Now when the you either add a study or refresh the chart, the drawings I previously had on the chart are removed and the the class variables are initialized so I loose my coordinates.

      Hope this makes more sense.
      Onn

      Comment


        #4
        Hello Onn,

        Thank you for your response.

        Hello Onn,

        Thank you for your post.

        When this occurs go to the Log tab, do you see an error listed?

        Can you provide a snippet of code for a drawing object that does not re-draw when reloading NinjaScript?

        I look forward to your response.
        Patrick H.NinjaTrader Customer Service

        Comment


          #5
          hi again, no errors in the log.

          See this simplified code below. To reproduce do the following:

          1. Add the indicator to the chart.
          2. Click the mouse button anywhere on the chart. As a result, you should see "Hello!!" in the center of the chart
          3. Hit F5 or add another indicator to the chart. You should see that the text disappears.

          I think I am getting there though. If I can keep a private variable to hold state, I can draw the drawings again within the plot method. The problem is that private variables also get initialized on F5 so I made them a property. So now they are keeping state between F5's and I am guessing that is because they are serialized and that kind of works. Problem is that I don't want them to appear in the indicators property dialog.

          So two questions really:
          1. Is there a different approach that you can recommend
          2. Is there a way to define properties and not have them appear in the properties dialog

          Code:
          		
          protected override void OnStartUp()
          {
              this.ChartControl.ChartPanel.MouseDown += new MouseEventHandler(this.OnClick);
          }
          		
          		
          private void OnClick(object sender, MouseEventArgs e)
          {
              if (ChartControl == null)
              {
                  return;
              }
          			
              DrawTextFixed("text", "Hello!!", TextPosition.Center);
              ChartControl.ChartPanel.Invalidate();
          }
          		
          protected override void OnTermination()
          {
              if (ChartControl != null)
              {
                  ChartControl.ChartPanel.MouseDown -= OnClick;
              }
          }
          Onn

          Comment


            #6
            Originally posted by onnb1 View Post
            hi again, no errors in the log.

            See this simplified code below. To reproduce do the following:

            1. Add the indicator to the chart.
            2. Click the mouse button anywhere on the chart. As a result, you should see "Hello!!" in the center of the chart
            3. Hit F5 or add another indicator to the chart. You should see that the text disappears.

            I think I am getting there though. If I can keep a private variable to hold state, I can draw the drawings again within the plot method. The problem is that private variables also get initialized on F5 so I made them a property. So now they are keeping state between F5's and I am guessing that is because they are serialized and that kind of works. Problem is that I don't want them to appear in the indicators property dialog.

            So two questions really:
            1. Is there a different approach that you can recommend
            2. Is there a way to define properties and not have them appear in the properties dialog

            Code:
                    
            protected override void OnStartUp()
            {
                this.ChartControl.ChartPanel.MouseDown += new MouseEventHandler(this.OnClick);
            }
                    
                    
            private void OnClick(object sender, MouseEventArgs e)
            {
                if (ChartControl == null)
                {
                    return;
                }
                        
                DrawTextFixed("text", "Hello!!", TextPosition.Center);
                ChartControl.ChartPanel.Invalidate();
            }
                    
            protected override void OnTermination()
            {
                if (ChartControl != null)
                {
                    ChartControl.ChartPanel.MouseDown -= OnClick;
                }
            }
            Onn
            Set the correct attribute on the property.
            Code:
            [Browsable(false)]

            Comment


              #7
              Hello Onn,

              Thank you for your response.

              What Koganam suggested should work for the properties.

              The mouse events and chart panel are items that are not supported in NinjaScript, they are general C# programming.

              Please let us know if Koganam's suggestion resolves this matter.
              Patrick H.NinjaTrader Customer Service

              Comment


                #8
                koganam!! sure does. 10x

                Comment


                  #9
                  jumped the gun before, sorry.
                  Could it be that if I set a property Browsable(false) it no longer gets serialized? What works with browsable true doesn't work with false. Do I need to add some annotation?

                  Onn

                  Comment


                    #10
                    Originally posted by onnb1 View Post
                    jumped the gun before, sorry.
                    Could it be that if I set a property Browsable(false) it no longer gets serialized? What works with browsable true doesn't work with false. Do I need to add some annotation?

                    Onn
                    The Browsable attribute is independent of the XmlIgnore attribute. What entity are you trying to serialize?

                    Comment


                      #11
                      Code:
                      [Serializable()]    
                          public struct chartCoord
                          {
                              public DateTime X;
                              public double Y;
                              public bool Valid;
                          }

                      Comment


                        #12
                        Originally posted by onnb1 View Post
                        Code:
                        [Serializable()]    
                            public struct chartCoord
                            {
                                public DateTime X;
                                public double Y;
                                public bool Valid;
                            }
                        You will most likely have to write your own serialize routines to serialize a struct. Alternatively, serialize the individual members, and construct the struct inside your code.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by sergey_z, Today, 02:56 PM
                        1 response
                        9 views
                        0 likes
                        Last Post NinjaTrader_Jesse  
                        Started by samir, Today, 02:46 PM
                        1 response
                        13 views
                        0 likes
                        Last Post NinjaTrader_Kate  
                        Started by neoikon, Today, 02:24 PM
                        1 response
                        7 views
                        0 likes
                        Last Post NinjaTrader_ChristopherJ  
                        Started by XimoTrader, Today, 12:57 PM
                        1 response
                        12 views
                        0 likes
                        Last Post NinjaTrader_PatrickG  
                        Started by FxInception, Today, 12:27 PM
                        2 responses
                        14 views
                        0 likes
                        Last Post FxInception  
                        Working...
                        X