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

Accessing ChartWindow & ChartTrader in an add on

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

    Accessing ChartWindow & ChartTrader in an add on

    Hello world, my first post here. trying to create an Add on which is going to be used for disabling ChartTrader when account exceeds certain drawdown. I referred one of the WPFmodication example which ChelseaB has out for others to follow. it works great (its made as an indicator). I tired to use the same chartWindow snippet in my Add on but getting a compile error as
    AddOnFramework.cs The name 'ChartControl' does not exist in the current context CS0103 543 52

    here is my snippet where i am getting main chart & chartTrader.

    Code:
    private void performAccountGuardCheck(Account activeAccount) {
    
    // get the main chart window
    // the main chart window
    chartWindow = System.Windows.Window.GetWindow(ChartControl.Paren t) as Chart;
    // if not added to a chart, do nothing
    if (chartWindow == null)
    return;
    // this is the grid in the chart window
    chartGrid = chartWindow.MainTabControl.Parent as Grid;
    // this is the entire chart trader area grid
    chartTraderGrid = (chartWindow.FindFirst("ChartWindowChartTraderCont rol") as ChartTrader).Content as Grid;
    //chartTraderGrid.IsEnabled = false; =
    
    }
    Not sure where i am going wrong.. all i need is access to Main ChartWindow and then get hold of ChartTrader object, please note that i am using an Add-on. thank you in advance.

    #2
    Hello manishj,

    Thank you for your post.

    Since you're doing this from an addon instead of from an indicator which already knows which window you're referring to, you'd either need to loop through the active windows to find windows that have a chart or make a check in OnWindowCreated whether the newly created window is a chart and then get the ChartTrader from the Automation ID.

    Here's an example of looping through chart windows:

    Code:
    foreach (var window in NinjaTrader.Core.Globals.AllWindows)
    {
    // check if the found window is a Chart window, if not continue looking
    if (!(window is NinjaTrader.Gui.Chart.Chart)) continue;
    
    window.Dispatcher.InvokeAsync(new Action(() =>
    {
    // try to cast as a Chart, if it fails it will be null
    var foundChart = window as NinjaTrader.Gui.Chart.Chart;
    
    // make sure we found a chart
    if (foundChart == null) return;
    
    // make sure the found chart is the owner window
    if (foundChart != this.Owner as NinjaTrader.Gui.Chart.Chart) return;
    }));
    }
    There's another example of getting all charts from an addon in this older forum thread here:



    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Let me try this one Kate! Please know that i appreciate this super quick response!

      Comment


        #4
        Your snippet was really helpful Kate. Got me what i wanted to a great extend. if there a way to get hold of followings now from Add-on.
        1. Context Menu :
        2. SuperDOM. any help here would be appreciated. i guess for superdoom i just need to follow superdomControl<wpeId>. as automation id ?

        For context menu attaching a pic of what control i am trying to get hold of.

        again thank you so much for prompt & helpful response.
        Click image for larger version  Name:	contextMenu.png Views:	0 Size:	194.6 KB ID:	1140125
        Attached Files
        Last edited by manishj; 02-05-2021, 12:41 AM.

        Comment


          #5
          Hello manishj,

          Thank you for your reply.

          Here's an example of getting a SuperDOM window and adding buttons to it that may be helpful that is publicly available on our User App Share:



          And an example of getting the context menu and adding items can be found here:



          Please let us know if we may be of further assistance to you.

          The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.
          Kate W.NinjaTrader Customer Service

          Comment


            #6
            thank you , will take a look!

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by trilliantrader, 04-18-2024, 08:16 AM
            4 responses
            18 views
            0 likes
            Last Post trilliantrader  
            Started by mgco4you, Today, 09:46 PM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by wzgy0920, Today, 09:53 PM
            0 responses
            9 views
            0 likes
            Last Post wzgy0920  
            Started by Rapine Heihei, Today, 08:19 PM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by Rapine Heihei, Today, 08:25 PM
            0 responses
            10 views
            0 likes
            Last Post Rapine Heihei  
            Working...
            X