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 to print current price in separate Window Form?

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

    How to print current price in separate Window Form?

    Hello Support and Others

    I need you help..

    I'm developing indicator which gives me data in a separate window form. The logic is the following.

    I add a button to a chart toolstrip. When I click the button script's method creates window form by Form form1 = new Form(); than I draw what ever I want on this form inside the method of the form creating using data from OnStartUp() and OnBarUpdate() methods.

    The problem is that the form does not display changed data from OnBarUpdate()/ It shows once I guess at the moment I click the button and the form is been created. How to make the form prints updated data, current price for example?

    I'm new in coding, please help.

    Thank you in advance.

    #2
    Hi Alex, officially a deeper area in C# which we could not really offer support for, but the form would for example need an event subscribed to basically to update it's contents - as you're not recreating it on every OnBarUpdate() call which is the event triggered then every bar. A custom working notes panel could be for example found here for ideas - http://www.ninjatrader.com/support/f...ad.php?t=43835

    I also think a custom timer be potentially useful here providing an event to listen to for your form.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Hello Bertrand --

      I found the following solution to print current price on the form. I do it OnBarUpdate() calling, but just the price only. I do not have enough knowledge to use custom timer yet (( The form is created on custom button click. The problem is that I do not know how to delete the previous price. I tried Clear() and Dispose() methods but when I use them no any price is printed. I've read all internet and I'm at a deadlock. I understand that you do not support deeper C#, but you are my the last chance.
      The code I use is the folloowing

      if (form1 != null)
      {
      Font F = new Font("Calibri",12, FontStyle.Bold);
      Brush B = new SolidBrush(Color.DarkRed);

      ts6 = form1.CreateGraphics();
      ts6.DrawString(s_cp, F, B, 10, up_cp_d-10);
      }

      form1 and ts6 are determined in Variables as Form form1 = null; and Graphics ts6 = null; other variables are calculated inside OnBarUpdate() method.

      Please, Help!!!

      Thank you in advance.

      Comment


        #4
        Hello Alex,

        When you are updating/changing the price you do not have to use the Clear, you would just want to change the "string" that drawing which it looks like is the "s_cp" variable.

        As for the Custom Timer event, there is a reference that you can view that has an example of this that you may view at the following link.


        Note that also our "BarTimer" indicator that is preloaded into NinjaTrader has a Timer event that you may view as well.

        Let us know if this helps or if you have any questions.
        JCNinjaTrader Customer Service

        Comment


          #5
          Hello JC --

          Thank you very much for your replay and the link provided.

          There are no problem with change the string, it works good. My script draws a current price on the separate window form and depend on the price value at a different location of the form. The problem is that previuos price is not deleted from the form when the new price is been drawing on the form.

          Please, Help!!!

          Thank you in advance.

          Comment


            #6
            Hello alex_bbfg,

            I would be happy to take a quick look at your code if you could provide me a sample of the script that you are using.



            If you do not feel comfortable posting it on the forums you may send it to support [at] ninjatrader [dot] com with the subject line "ATTN: JC" and in the body of the email reference this thread.
            JCNinjaTrader Customer Service

            Comment


              #7
              Originally posted by alex_bbfg View Post
              Hello JC --

              Thank you very much for your replay and the link provided.

              There are no problem with change the string, it works good. My script draws a current price on the separate window form and depend on the price value at a different location of the form. The problem is that previuos price is not deleted from the form when the new price is been drawing on the form.

              Please, Help!!!

              Thank you in advance.
              How and where exactly did you call the Dispose() method on the Graphics object?

              Comment


                #8
                Hello JC --

                The code is not a secret. The script is attached.

                Thank you in advance.
                Attached Files

                Comment


                  #9
                  Hello koganam

                  the part of the code where I used Dispose() the following

                  protected override void OnBarUpdate()
                  {
                  if (form1 != null) // Check if the form created
                  {
                  if (d_cp>d_ldcp) // check if current day price greater of previous day close.
                  {
                  ts6.Dispose(); // Here I except that the previse price will be deleted and then the new one should be drawn
                  ts6 = form1.CreateGraphics();
                  ts6.DrawString(s_cp, F, B, 10, up_cp_d-10);
                  }
                  }
                  }

                  I put the my script here


                  Thank you in advance.

                  Comment


                    #10
                    Originally posted by alex_bbfg View Post
                    Hello koganam

                    the part of the code where I used Dispose() the following

                    protected override void OnBarUpdate()
                    {
                    if (form1 != null) // Check if the form created
                    {
                    if (d_cp>d_ldcp) // check if current day price greater of previous day close.
                    {
                    ts6.Dispose(); // Here I except that the previse price will be deleted and then the new one should be drawn
                    ts6 = form1.CreateGraphics();
                    ts6.DrawString(s_cp, F, B, 10, up_cp_d-10);
                    }
                    }
                    }

                    I put the my script here


                    Thank you in advance.
                    There must be something strange, because when I imported your code, the resulting window that I get when I click on your button is shown below. It has a few colors, and there is certainly no text.
                    Attached Files

                    Comment


                      #11
                      The script gets its value to draw OnBarUpdate() method. As exchanges are closed on weekend I think the method is not called and the window is empty.

                      Comment


                        #12
                        Hello alex_bbfg,

                        While, it is not supported I believe what is happening is that the the graphics you are drawing are a part of the windows itself since it is just drawing something on the screen so when you are trying to dispose if it you are disposing of the points but it is not clearing anything inside of the Window that you are drawing in it.

                        You may want to use the Clear() method of the Graphics to clear out the window but note that it will clear out everything on the screen so you will have to redraw your other objects but this will ensure that the previous DrawStrings are not drawing on top of each other.

                        For example:

                        Code:
                        if(ts6 != null)
                        {
                                //Paint the window white to remove previous drawings.
                        	ts6.Clear(Color.White);
                        }
                        Let me know how that works for you.
                        JCNinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by alex_bbfg View Post
                          The script gets its value to draw OnBarUpdate() method. As exchanges are closed on weekend I think the method is not called and the window is empty.
                          Regardless of what works or not, in order to repaint the form, you must use the Invalidate() method. Any disposed objects will only disappear when you repaint the form.

                          Comment


                            #14
                            Hello JC, koganam and others

                            Thank you for your replies and help. I've left the idea to use CreateGraphics(); method. I am going to use Label() and Panal() methods. I knew and understand them better.

                            Thank you.

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by sidlercom80, 10-28-2023, 08:49 AM
                            166 responses
                            2,234 views
                            0 likes
                            Last Post sidlercom80  
                            Started by thread, Yesterday, 11:58 PM
                            0 responses
                            1 view
                            0 likes
                            Last Post thread
                            by thread
                             
                            Started by jclose, Yesterday, 09:37 PM
                            0 responses
                            6 views
                            0 likes
                            Last Post jclose
                            by jclose
                             
                            Started by WeyldFalcon, 08-07-2020, 06:13 AM
                            10 responses
                            1,414 views
                            0 likes
                            Last Post Traderontheroad  
                            Started by firefoxforum12, Yesterday, 08:53 PM
                            0 responses
                            11 views
                            0 likes
                            Last Post firefoxforum12  
                            Working...
                            X