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

Coding Help Needed

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

    #61
    Hello Mukaddim,

    Are you accessing the drawing objects collections from your indicator? If so, there is a special requirement for compiled assemblies for Drawing Objects specifically.



    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #62
      Thanks Jesse!!
      I will give it a go, and see if I can figure it out. Will update soon.

      Mukaddim

      Comment


        #63
        Hi Jesse!

        One of the indicators in NT7 uses a Color variable, say Color myVar, which then is used in item.ForeColor in ToolStripMenuItem(). For conversion to NT8, Color type becomes Brush type, so the varible becomes Brush myVar. But I can't use it in item.ForeColor anymore since the Media.Brush to Drawing.Color conversion error pops up. Any work-around is awaited.

        Thanking
        Mukaddim

        Comment


          #64
          Hello Mukaddim,

          NT8 objects that are WPF elements should use "Brush" now instead of "Color" as we are using WPF. What specifically are you trying to convert, is it the ToolStripMenuItem? Have you used referenced and used Windows Forms controls in NT8 currently?

          The menu system in NT8 uses MenuItem or NTMenuItem now which would use Styles instead of directly setting a Brush. As a general rule, if you are seeing an object take System.Drawing.Color in NT8, you have used the incorrect object. You will run into a lot of errors if you try to use windows forms elements in WPF as they are different frameworks.

          You can find quite a few samples of toolbars and menu items here: https://ninjatrader.com/support/foru...327#post499327

          When converting UI items from NT7 to NT8, it is best to leave all the code in NT7 and just redevelop this in NT8 due to the change in frameworks. NT7 used Windows Forms and NT8 uses WPF/XAML.




          I look forward to being of further assistance.
          JesseNinjaTrader Customer Service

          Comment


            #65
            Thank you Jesse!

            Yes, the code uses ToolStripMenuItem to add a small menu into the toolbar in NT7. I would like to replicate similar in NT8. so item.ForeColor takes an Drawing.Color as you mentioned, Are you suggesting that item.ForeColor be avoided?

            Mukaddim

            Comment


              #66
              Hello Mukaddim,

              What I am suggesting is that you do not carry over any of the NT7 toolbar syntax to NT8 and only keep your idea here.

              You know of the toolbar concept in NT7 because you had used it, but because we use a new framework in NT8 that no longer has that toolbar you should only keep the idea that you want a toolbar in NT8 and get rid of the syntax you use now for NT7.

              The samples I provided in the last post would be a good place to start re-learning how to use the Toolbar concept in NT8. Because we no longer use Windows Forms the ForeColor is only one part of the overall problems you will have with using this specific syntax in nt8.

              NT8 exposes a lot of new controls in meaningful ways so you can access them easily. This was not present in NT7 so accessing items would often include a lot of looping or testing to find what you want. If you use the examples on the forum of existing concepts like adding button to the toolbar, you will see the better ways to access the UI controls in NT8 which prevent a lot of legwork.



              I look forward to being of further assistance.
              JesseNinjaTrader Customer Service

              Comment


                #67
                Hello Jesse!
                Thank you for your reply.

                I am going through the examples and hope to resolve it through learning from these examples.

                Mukaddim

                Comment


                  #68
                  Hi Jesse,
                  While working on the toolbar menu conversion, I was able to successfully convert the core of the indicator and it compiles fine, but the indicator doesn't show up in the list. So, I checked the LOG and found out that there's an error on calling the OnStateChange Method, stating that the Object Reference is not set to an instance of an Object. Have no clue what to do now. Please suggest.

                  Thanking
                  Mukaddim

                  Comment


                    #69
                    Hello Mukaddim,

                    In this case, you know both the location "OnStateChange " and the error "Object Reference is not set to an instance of an Object."

                    If you search online for the general error message for C# it will give you some details but basically, this means an object you are using is null in OnStateChange.

                    So you will need to find what object you have used that is null. I would suggest to just add some Print() statements in OnStateChange in various locations to see where they stop, or put one print in OnStateChange to print the current state. Print(State);


                    Code:
                    protected override void OnStateChange()
                    {
                        Print(State);
                    Once you know which state is failing, you can look at the objects you used. If its not apparent which is null, try making a print to check that:

                    Code:
                    if(ChartControl == null)
                    could be written as
                    Code:
                    Print("ChartControl is null? : " + (ChartControl == null));

                    I look forward to being of further assistance.
                    JesseNinjaTrader Customer Service

                    Comment


                      #70
                      Hello Jesse!
                      The Print(State) returns the same error as seen in Log.
                      ChartControl returns a 'True' followed by 'Terminated'. Please advise on further steps.

                      Thanking
                      Mukaddim

                      Comment


                        #71
                        Hello Mukaddim,

                        The Print(State); should be seen in the NinjaScript output window in addition to the error. Are you currently using the NinjaScript output window to further debug or are you watching the control center log tab?

                        You will still get the error while you add prints, the prints would simply help isolate what state the problem is in. My example of ChartControl will also not be specific to your script, I should have mentioned you need to replace "ChartControl" with whatever objects you are using.

                        If you cannot find the problem by using prints, you can also try commenting out your logic until you find the problem. Leaving just a shell of a script with all your logic commented out should allow the script to work in turn allowing you to slowly uncomment to find the problem.

                        I look forward to being of further assistance.
                        JesseNinjaTrader Customer Service

                        Comment


                          #72
                          Hi Jesse!
                          Control Center Log is not showing any error. But the Output window is.
                          Would you like to have a look at the codes?

                          Thanking
                          Mukaddim

                          Comment


                            #73
                            Hello Mukaddim,

                            Before posting any code on this, have you tried to comment out your logic to further isolate where the problem is coming from? You will very likely run into this type of error frequently if you are dealing with the GUI items so this is something that is good to know how to debug yourself.

                            To further isolate the problem I would suggest to comment out the logic you use in OnStateChange and leave the script looking similar to a new empty script, how it just has the default properties and structure. This will also entail you comment out any logic that may require the OnStateChange logic such as logic in OnBarUpdate.

                            Once you comment down the script so it does nothing but no longer produces the error, you can uncomment just the OnStateChange logic one line at a time and check when you start getting the error. This will highlight the problem which will make it more apparent on how to fix it.

                            Very likely you are using an object such as ChartControl or some UI item that is null in one of the states where it is used. If you take a look at the examples I previously posted there are extensive null checks because the objects used are frequently null in the various states. State.Terminated is one of those places because the script is terminated a few extra times when you apply it which it does not have an associated ChartControl in those cases.

                            I look forward to being of further assistance.
                            JesseNinjaTrader Customer Service

                            Comment


                              #74
                              Hello Jesse!

                              Yes, that is the idea. I'm going to try commenting technique. See if I can figure it out. On a different note, a StringSeries is a Series<string> in NT8, right?

                              Comment


                                #75
                                Hello Mukaddim,

                                Thank you for the reply.

                                Correct, you can pretty much apply that to any type to replace any custom NT7 series. Series<T> is a generic where T is the type of series you want such as string.

                                In regard to debugging, once you run through the script again if you are unable to find the problem please let me know and we could review the code together at that point. This is just one of those important processes for any GUI item you work on in NT8 so it is good practice to be able to find this error location in your code.

                                I look forward to being of further assistance.
                                JesseNinjaTrader Customer Service

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by TradeForge, 04-19-2024, 02:09 AM
                                2 responses
                                28 views
                                0 likes
                                Last Post TradeForge  
                                Started by aprilfool, 12-03-2022, 03:01 PM
                                3 responses
                                327 views
                                0 likes
                                Last Post NinjaTrader_Adrian  
                                Started by giulyko00, Today, 12:03 PM
                                1 response
                                5 views
                                0 likes
                                Last Post NinjaTrader_BrandonH  
                                Started by f.saeidi, Today, 12:14 PM
                                1 response
                                4 views
                                0 likes
                                Last Post NinjaTrader_Gaby  
                                Started by AnnBarnes, Today, 12:17 PM
                                1 response
                                2 views
                                0 likes
                                Last Post NinjaTrader_Zachary  
                                Working...
                                X