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

XAML References to Current Skin, NT8

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

    XAML References to Current Skin, NT8

    Hi Everyone.



    Taking my first dive into developing an AddOn for NT8. I started with the AddOn Example available for download from your website. I've got no problem adding a new menu entry and I'm able to click on it and it shows me the example window. When i look at the xaml file in visual studio, in the designer window it tells me cannot create an instance of "Order Grid" and the xaml file it call on <AccountData:OrderGrid BorderBrush="{StaticResource .... it says it's unable to locate the license assembly. I don't think I commented out a reference or anything; how is the best way to get around this?



    Also, I started my own AddOn project based on the example and I'm trying to get a feel for how this is going to work. I created a new xaml/c# file and I've got that working no problem. As I start to put new controls out there, how can I reference properties of the current skin being used? For example, I've put up a textbox but it doesn't show a border. How can I set the border color (and thickness, weight, etc) to match whatever the current skin is? Is there a different namespace I have to reference? When trying to use StaticResource, I get similar errors as in the first question.



    Thanks for your help



    Brennan

    #2
    Hello BrennanSalibrici,

    Thank you for the post.

    What you are seeing in the designer is correct, the NinjaTrader controls require a context that Visual Studio cannot provide so they are not designer compatible.You can instead manually code the controls using xaml code without the designer.

    Generally if you need the designer to generate some code an alternate option is to use a separate WPF project in visual studio so you can generate xaml using the designer for any standard controls. You can then copy/paste that into your NinjaTrader xaml to use it.

    Keep in mind that loading the xaml works differently in NinjaTrader, you are not using the C# code behind so bindings or other xaml related features won't work out of the box. You can see the LoadXaml method in the addon for a preview of how the xaml is actually parsed and loaded.


    how can I reference properties of the current skin being used?
    This is a difficult question, there is not really a resource that provides details on the skin properties. Most items you would just use the control as is and it will be styled automatically based on its type. If you wanted to do custom styling or if styling does not work where it was used you can search for static resources in the standard C# way to apply them. The keys for the styles would be in the skin blueprint.xaml file. https://ninjatrader.com/support/help...lightsub=skins
    You can see this post, the print is not very useful but the attached sample shows how to find a resource which is a style. https://ninjatrader.com/support/foru...-controlcenter

    I look forward to being of further assistance.



    JesseNinjaTrader Customer Service

    Comment


      #3
      Thank you Jesse.

      The XAML/C# code behind is new for me. The last GUI project I worked on was all WinForms so this is a pretty major change and since then I've really only been working on backend processing so I need to spend some time figuring out how this world works. Just to be clear, are you saying that the code behind file is not used at all or is it just the loading/instantiation that it's bypassed? I think you're saying anything along these lines needs to be put in the xaml file for it to work.

      I'm pretty new to the NT platform and the more I was poking around I started noticing there are quite a few NT specific controls and what you're saying (totally makes sense) to use these as opposed to generics. Do you guys have a list of some kind of what controls are available which are specifically optimized for NT?

      Along these lines, I'm trying to put a chart in the new window I'm creating. From all the forum posts I read (they are not very recent so perhaps something has changed?) it looks like it's very difficult to add a new chart to a window programmatically. Is this still the case? Actually, it's not even the entire chart that I'm looking for, what I really want is to put a few individual chart panels on display. In a similar way that you can put price bars in panel 1 and then price bars for a different instrument in panel 2, they appear to be stacked on top of each other. My goal is to have 4 chart panels on display in a similar way and then have a toolbar on the top of the screen and a handful of other various controls. Perhaps the easiest way is to open a workspace with the charts I need, then I could minimize those chart windows and reference or point to them with a chartpanel control in my xaml file. Would this be a reliable path to start down? It'd be pretty easy to reference the existing charts/chart panels in C# but are there some xaml properties of NTchart controls I should or should NOT use to go after this?

      Thanks for your help Jesse, I very much appreciate your help in getting acclimated to this new world!!

      Brennan

      Comment


        #4
        Hello BrennanSalibrici,

        The XAML/C# code behind is new for me. The last GUI project I worked on was all WinForms so this is a pretty major change and since then I've really only been working on backend processing so I need to spend some time figuring out how this world works.
        That is a good idea, WPF is very different from windows forms so creating a GUI application in visual studio first is very helpful toward learning how xaml/wpf work.


        Just to be clear, are you saying that the code behind file is not used at all or is it just the loading/instantiation that it's bypassed? I think you're saying anything along these lines needs to be put in the xaml file for it to work.
        Correct, there is no code behind file for the xaml that you use in NinjaScript. The code behind would be how you load the xaml and parse it. You then look for controls and store them to variables to use them later or subscribe to events. Everything is done manually instead of having a compiled CS file that matches the Xaml file. This means Bindings and other compiled xaml specific items won't work as you would have them work in a normal WPF application. The sample addon shows this, the LoadXaml method is where that happens.



        I'm pretty new to the NT platform and the more I was poking around I started noticing there are quite a few NT specific controls and what you're saying (totally makes sense) to use these as opposed to generics. Do you guys have a list of some kind of what controls are available which are specifically optimized for NT?
        The only list of controls would be the Addon controls, those are truly intended to be re used.


        You can however use any WPF/ internal Control that is found in the platform or that you add code for. The internal controls are not all intended to be used from NinjaScript so that is more of a situation where you can pick a control and then do a forum search for its type. That may produce some existing users trying to use that control and may have a sample as well.


        Along these lines, I'm trying to put a chart in the new window I'm creating. From all the forum posts I read (they are not very recent so perhaps something has changed?) it looks like it's very difficult to add a new chart to a window programmatically. Is this still the case?
        Yes there is a lot that goes into the chart and it is not exposed in any meaningful way for re use. You could try to add third party graphing library or use WPF rendering if you specifically needed a chart however I could instead suggest to try and use an Indicator for that purpose and apply it to an existing chart.



        Actually, it's not even the entire chart that I'm looking for, what I really want is to put a few individual chart panels on display. In a similar way that you can put price bars in panel 1 and then price bars for a different instrument in panel 2, they appear to be stacked on top of each other. My goal is to have 4 chart panels on display in a similar way and then have a toolbar on the top of the screen and a handful of other various controls. Perhaps the easiest way is to open a workspace with the charts I need, then I could minimize those chart windows and reference or point to them with a chartpanel control in my xaml file. Would this be a reliable path to start down? It'd be pretty easy to reference the existing charts/chart panels in C# but are there some xaml properties of NTchart controls I should or should NOT use to go after this?

        Controlling the actual chart windows by their window instance would be a better approach than trying to make custom chart windows. If they windows need to be separate that would likely be one way to approach the goal, if they can reside in the same window you may want to look at just using a Strategy. A strategy can host multiple child indicators to create multiple panels in one chart. The strategy wouldnt need to place trades just do the hosting, you can also add toolbars or do other GUI tasks from a strategy/indicator.



        I look forward to being of further assistance.







        JesseNinjaTrader Customer Service

        Comment


          #5
          Hey Jesse.
          This looks very promising! I've been reading up on pretty much everything I can find strategy related. I've been able to create strategies, I think I understand how to manipulate them a bit, but the one thing I can't seem to figure out is how to show it visually. For example, I saw a tutorial about setting trailing stops and I took a snapshot of his screen where he's got a chart, chart trader, dom and a slider shown. I think this is the kind of thing you're talking about, but how do you get there? How do I get from creating a strategy to showing the components on the screen like this? It's probably something simple I'm missing but I can't seem to figure it out. Do you start with a chart first?

          Thanks for your help.

          Comment


            #6
            Hello BrennanSalibrici,

            What is shown in the image appears to be the chart trader and superdom along with the simulated data feed. If the strategy was applied to the sample instrument/account both the dom and chart trade would show its orders. This applies in both 7 and 8.

            You can apply the strategy directly to a chart or also in the control center, it would only be visual if you apply it to the chart in regard to any indicators it uses or drawings it does. The chart would otherwise show the executions if chart trader is open.

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

            Comment


              #7
              In the majority of Addon examples I've found, it seems like most UI elements get referenced by an 'Automation ID'. Is this an enumeration of some kind? Either way, is there a list of the various automation ids that I can reference? What is the best way to reference a specific object - like if there's 3 open charts and I want to move "Chart #2"? In the immediate near term, I want to be able to reference a specific chart and/or chart control. Right now, I just want to adjust their placement on the screen. Also, this seems like a reasonable way to go about it if the chart/object is open and on the screen, however, if it's not open but is already defined as in a saved chart or a chart(s) that's saved as a part of a workspace, is there a way to serialize it an open it via XamlWriter/Reader so I don't have to open it first in order to reference it?

              brennan

              Comment


                #8
                Hello BrennanSalibrici,
                In the majority of Addon examples I've found, it seems like most UI elements get referenced by an 'Automation ID'. Is this an enumeration of some kind? Either way, is there a list of the various automation ids that I can reference?
                There is not a list of items but you can locate them by using microsofts Inspect tool. https://docs.microsoft.com/en-us/win...ectedfrom=MSDN

                What is the best way to reference a specific object - like if there's 3 open charts and I want to move "Chart #2"? In the immediate near term,
                If you have just the active window collection that won't really be specific as you would just have Window objects. You would have to get the actual Chart object from each window or one of the sub objects like one of the charts BarsArray to find out more about it. The charts Title may work to identify it or you can otherwise access the other properties the chart has to isolate which chart you are looking at.
                Also, this seems like a reasonable way to go about it if the chart/object is open and on the screen, however, if it's not open but is already defined as in a saved chart or a chart(s) that's saved as a part of a workspace, is there a way to serialize it an open it via XamlWriter/Reader so I don't have to open it first in order to reference it?
                I am not certain I understand what you are asking here, can you clarify this question?

                It may help to provide a short description of your overall goal in as few words as possible. There may be existing samples on the forum for what you are trying to accomplish.


                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Nice! Didn't know about the Inspect tool. Thanks

                  As far as the 'Active Windows' question, I'm a bit confused now. Here's what I'm hoping to do: I want to just take 4 charts and essentially tile them across the screen into 4 quadrants. Originally, I thought the best way to do it would be to take the chartcontrol from each of the 4 charts I wanted to use and put a copy of it on a grid or canvas that I would define in Xaml in my AddOn. I may have misunderstood what you were saying before; I thought you suggested to just arrange the screen placement of the those charts as an NTWindow instead of copying each one and putting it into Xaml. But now, I think you're saying that in order to reference each chart, there's no real defining features at the NTWindow level and I need to get further down to the actual chart object itself, so if that's the case why wouldn't we just create a copy of the chart and put it on a Xaml canvas then? I don't really need it to do much as far as orders, indicators or drawing is concerned, it's mainly just for a quick reference.

                  I was thinking of something like putting a List<Object> in the Addon File and in the override of OnWindowCreate() just add to the list if(window.type = chart) so to speak.

                  As for my 2nd question, what I'm getting is this: after you saved a chart to a workspace it automatically comes up when you open the workspace, so somewhere, NT knows what that chart is, what the settings are, what indicators it has, what timeframe etc. So in the Workspace.Open() command, there's a reference to Chart_1.Open(), Chart_2.Open(), etc. Can I access those 'Open Chart' commands? As for the xaml part, I think I've learned that in Xaml, you don't really 'copy' or 'paste' a UIElement, per sea, but you copy/paste the Xaml text files behind the UIElement and thats what I'm wondering about.

                  Comment


                    #10

                    Hello BrennanSalibrici,

                    As far as the 'Active Windows' question, I'm a bit confused now. Here's what I'm hoping to do: I want to just take 4 charts and essentially tile them across the screen into 4 quadrants. Originally, I thought the best way to do it would be to take the chartcontrol from each of the 4 charts I wanted to use and put a copy of it on a grid or canvas that I would define in Xaml in my AddOn.
                    If you are trying to tile the charts you could control the whole window in that case. Trying to extract a control out of the window into your own control is not something I could suggest to try. A wpf window has a Top and Left property which you can use to position it in the screen and has a Width and Height for sizing.

                    I may have misunderstood what you were saying before; I thought you suggested to just arrange the screen placement of the those charts as an NTWindow instead of copying each one and putting it into Xaml. But now, I think you're saying that in order to reference each chart, there's no real defining features at the NTWindow level and I need to get further down to the actual chart object itself,
                    My previous answer had no specifics on the arrangement part, I was only speaking about how to interact with the objects you are using. You are correct in understanding what I had said, to find out about the chart you would need to drill down from the top level window to a child object and find out about it.

                    so if that's the case why wouldn't we just create a copy of the chart and put it on a Xaml canvas then? I don't really need it to do much as far as orders, indicators or drawing is concerned, it's mainly just for a quick reference.
                    It would be much more simple to just control the window size and position. As I stated earlier it would not be something I can suggest trying or to try and extract a part of the chart, you should just control the existing one. Right now there is no system to create new charts from code so really at most you could control open charts if you are trying to make some kind of quick reference or management tool.


                    I was thinking of something like putting a List<Object> in the Addon File and in the override of OnWindowCreate() just add to the list if(window.type = chart) so to speak.
                    Yes that would be the correct approach if you need to hold on to some windows. For any new windows that are opened they would be appended. A more simple approach is to use the NinjaTrader.Core.Globals.AllWindows collection in place of your list here and just iterate all windows each time one is added. You can do that from OnWindowCreated or also State.Active when the addon is ready.

                    As for my 2nd question, what I'm getting is this: after you saved a chart to a workspace it automatically comes up when you open the workspace, so somewhere, NT knows what that chart is, what the settings are, what indicators it has, what timeframe etc. So in the Workspace.Open() command, there's a reference to Chart_1.Open(), Chart_2.Open(), etc. Can I access those 'Open Chart' commands? As for the xaml part, I think I've learned that in Xaml, you don't really 'copy' or 'paste' a UIElement, per sea, but you copy/paste the Xaml text files behind the UIElement and thats what I'm wondering about.
                    The chart is stored to the workspace file along with all the other settings in the workspace. This is just xml serialization however there is not really a system exposed to create charts or load parts of the workspace. You may see different methods in the intelleprompt related to opening workspaces but there is really no documentation or support surrounding that at this point.
                    JesseNinjaTrader Customer Service

                    Comment


                      #11
                      Ok. Thanks for the clarification, Jesse!

                      Comment


                        #12
                        So, I can arrange charts around the screen how I want to now, but I’m wondering if you can help me with this. I’ve got a combobox and with each selected item in the combobox, I’d like to change the instrument that the chart is showing. So for example, I’d like to have something like combobox_OnSelectionChange {if(comboxbox.selecteditem == 1) then chart.instrument = EURUSD || if(combobox.selecteditem == 2) then chart.instrument = AUDUSD}. (Most likely a switch statement).
                        I’ve been trying to wrap my head around the ‘chart’ object structure, but I thought it might be easier to just ask you - what’s the right way to programmatically change the instrument on a chart in this manner? I would want everything else to stay the same (timeframe, indicators, etc) just update the instrument and then update the chart with the new bars.

                        Thanks

                        Comment


                          #13
                          Hello BrennanSalibrici,

                          There is currently no means to change the chart settings for the data series in code, the charts logic is needed to update the chart. You could invoke keyboard commands in the chart to do the insturment change by keyboard. There is a sample of that in the rollover indications indicator on the public user app share: https://ninjatraderecosystem.com/use...indications-2/


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

                          Comment


                            #14
                            Hi Jesse,
                            So I've spent a fair bit of time getting acquainted with the various parts and pieces of this NT environment. I'd like to first, confirm that I'm understanding the way this is all set up correctly. It seems to me that creating a custom indicator/strategy is useful for manipulating charts and a custom addon's purpose is for building custom windows, other general (or background tasks), and/or creating new gui objects to display on any of the various NT windows, but it doesn't seem like they are interchangeable. For example, with an custom indicator, I can use AddData(), but while working on a custom Addon, this function is not available (or gives me errors) when I try to use it even if I #include the same namespaces. Can you use both (or a strategy as well) in the same Visual studio project/solution or do they have to stay independent for some reason? In my Addon project, I tried adding functionality to an indicator by including a section of my Addon project defining the indicator namespace and the class definitions but it wasn't happening for me. I suspect that it was just a referencing issue, but is it even intended to be used like that? Perhaps there's other things happening behind the scenes that would prevent an indicator and Addon being used in the same project. Could that cause multi-threading dead-locks?

                            Here's a couple things I'm trying to do, and I'm hoping you can tell me which tool I should use and if i can keep them all in the same project/solution or if they have to be seperate:
                            I want to have a couple toolbar buttons that will toggle between a couple different views of charts. View 1 would displays 4 charts symmetrically across the screen. This is sort of the 'default' way the workspace opens. View 2 would minimize 3 of the charts and maximize the fourth one. For general, 'window related' things like this, or changing the 'Always On Top' setting programmatically, is a custom Addon the right place for this?

                            Then, I'd like to have 3 other toolbar buttons that toggle indicator settings, for example the SMA. I want 1 button to turn the SMA visible setting to off, the 2nd button to show the 20 period SMA, and the 3rd button to show the 50 period SMA. Is this best done from a custom indicator VS file. If these had to be separate files, how can I put buttons (triggering functions from a addon and others from a strategy or indicator) on the same toolbar, specifically with respect to referencing and multi-threading?

                            Thanks,
                            Brennan

                            Comment


                              #15
                              Hello BrennanSalibrici,


                              For example, with an custom indicator, I can use AddData(), but while working on a custom Addon, this function is not available (or gives me errors) when I try to use it even if I #include the same namespaces. Can you use both (or a strategy as well) in the same Visual studio project/solution or do they have to stay independent for some reason? In my Addon project, I tried adding functionality to an indicator by including a section of my Addon project defining the indicator namespace and the class definitions but it wasn't happening for me. I suspect that it was just a referencing issue, but is it even intended to be used like that? Perhaps there's other things happening behind the scenes that would prevent an indicator and Addon being used in the same project. Could that cause multi-threading dead-locks?
                              The difference you are seeing here is that an addon by nature does not have a data series or something which you apply it to so it needs to use a BarsRequest. Internally something similar happens for the chart which gives you the bars series. When you apply an indicator to that chart it inherits the existing series and then has its special events like OnBarUpdate called. The addon has none of that so if it needs data the BarsRequest is the mechanism for that because nothing else is calling it.


                              Here's a couple things I'm trying to do, and I'm hoping you can tell me which tool I should use and if i can keep them all in the same project/solution or if they have to be seperate:
                              I want to have a couple toolbar buttons that will toggle between a couple different views of charts. View 1 would displays 4 charts symmetrically across the screen. This is sort of the 'default' way the workspace opens. View 2 would minimize 3 of the charts and maximize the fourth one. For general, 'window related' things like this, or changing the 'Always On Top' setting programmatically, is a custom Addon the right place for this?
                              Yes if you need to work with windows the addon is generally the best location for that because it has the window overrides. https://ninjatrader.com/support/help...dowcreated.htm
                              You can reference all windows by using the NinjaTrader.Core.Globals.AllWindows collection.

                              Then, I'd like to have 3 other toolbar buttons that toggle indicator settings, for example the SMA. I want 1 button to turn the SMA visible setting to off, the 2nd button to show the 20 period SMA, and the 3rd button to show the 50 period SMA. Is this best done from a custom indicator VS file. If these had to be separate files, how can I put buttons (triggering functions from a addon and others from a strategy or indicator) on the same toolbar, specifically with respect to referencing and multi-threading?
                              You can likely toggle the visibility for the indicators in this way however that would be a more complex task from an addon. This type of logic would be easier from an indicator directly to avoid any multithreading/finding controls in the window. From an addon you would have to find the active chart control in the window and then access its Indicators collect to toggle the indicator visibility. This is not something I have a specific sample for. From the Indicator you could instead set the plot to transparent to hide or show it.

                              I look forward to being of further assistance.




                              JesseNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by bortz, 11-06-2023, 08:04 AM
                              47 responses
                              1,602 views
                              0 likes
                              Last Post aligator  
                              Started by jaybedreamin, Today, 05:56 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post jaybedreamin  
                              Started by DJ888, 04-16-2024, 06:09 PM
                              6 responses
                              18 views
                              0 likes
                              Last Post DJ888
                              by DJ888
                               
                              Started by Jon17, Today, 04:33 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post Jon17
                              by Jon17
                               
                              Started by Javierw.ok, Today, 04:12 PM
                              0 responses
                              12 views
                              0 likes
                              Last Post Javierw.ok  
                              Working...
                              X