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

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.

    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.

        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.

              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 maybeimnotrader, Yesterday, 05:46 PM
                        2 responses
                        21 views
                        0 likes
                        Last Post maybeimnotrader  
                        Started by adeelshahzad, Today, 03:54 AM
                        5 responses
                        32 views
                        0 likes
                        Last Post NinjaTrader_BrandonH  
                        Started by stafe, 04-15-2024, 08:34 PM
                        7 responses
                        32 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Started by merzo, 06-25-2023, 02:19 AM
                        10 responses
                        823 views
                        1 like
                        Last Post NinjaTrader_ChristopherJ  
                        Started by frankthearm, Today, 09:08 AM
                        5 responses
                        22 views
                        0 likes
                        Last Post NinjaTrader_Clayton  
                        Working...
                        X