Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Cannot find ChartTrader account

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

    Cannot find ChartTrader account

    When I instantiate a new chart and add an indicator with the following code, I noticed that accountSelector is null:

    Code:
    else if (State == State.DataLoaded)
    {
        Dispatcher.InvokeAsync(() =>
        {
    
            AccountSelector accountSelector = Window.GetWindow(ChartControl.Parent).FindFirst("ChartTraderControlAccountSelector") as AccountSelector;
            ...
        }
    }
    The reason, it seems, is because ChartTrader does not create the WPF elements until its visibility is first set to Visible or Hidden from the UI. Once it is visible or at least hidden, the indicator code above behaves as expected and accountSelector is never null.

    Is there a way to force ChartTrader to create the WPF elements? This would prevent this issue when the indicator is added to the chart before ChartTrader is visible/hidden.


    #2
    Hello Zombie,

    Thank you for your reply.

    Chart Trader doesn't exist in the Chart until it's made Visible or Hidden, so you wouldn't be able to access the AccountSelector until it's turned on. There wouldn't be a supported way to force it to create the WPF elements prior to that. Since the chart itself doesn't really have a concept of an Account, you'd want to add code so you don't check the AccountSelector until ChartTrader is active. You could add logic to print a message to the chart when Chart Trader isn't on to tell the user to turn it on for the indicator to function.

    I've attached an example indicator that adds some buttons when Chart Trader is active and removes them when it isn't.

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

    Comment


      #3
      Hi Kate,

      thanks, I was thinking about turning ChartTrader visibility on programmatically:I tried to do it before searching for the the account selector, but the search failed even though the ChartTrader became visible.

      Is it possible to change the ChartTrader's visibility to Visible/Hidden and only then search for the WPF elements? If so, could you please provide a code sample? Is it possible to subscribe to changes to ChartTrader's visibility?

      Thanks
      Last edited by Zombie; 01-21-2021, 03:19 PM.

      Comment


        #4
        Hello Zombie,

        Thank you for your reply.

        You'd still have to take the same approach as in the previous example - I've created a modified version that forces ChartTrader to be visible. It then checks to see that ChartControl isn't null, then creates buttons. You'd want to use the same approach - check to see that ChartControl isn't null and then look for the AccountSelector.

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

        Attached Files
        Kate W.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by demarcog, Today, 11:03 AM
        5 responses
        19 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by jo54321, Today, 04:26 AM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by pserrera, Today, 03:26 AM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by maxuscz, Today, 03:01 AM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by ntbone, Today, 02:33 AM
        2 responses
        9 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X