Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Modifications to chart WPF elements and tab considerations

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

  • REI140205
    replied
    Hi Chelsea, your "ChartToolBarCustomMenuExample" has been a great starting point from which we can build our own personalized indicators. Any chance you can help me extend its usefulness a bit? I am stuck trying to load the same indicator on two or more tabs of the same chart window (issue: the menu icon is only visible in toolbar of first tab to which indicator is loaded). It would also be helpful to be able to load same indicator two or more times in the same tab and have a separate menu icon corresponding to each.

    Thanks.

    Leave a comment:


  • Dougtre
    replied
    Originally posted by kkc2015 View Post
    Hi Dougtre,
    Try these files.
    Thanks a lot!

    Leave a comment:


  • kkc2015
    replied
    Hi Dougtre,
    Try these files.
    Attached Files

    Leave a comment:


  • Dougtre
    replied
    Originally posted by kkc2015 View Post
    Hi Unsuitable,
    It looks like you are making good progress.
    Attached are a screen shot and a totally stripped down version of a button indicator (NT8), which can be imported and compiled.
    If you press the Help button to make it green, when you press any other buttons, you can see the text on the bottom right of the chart, showing the pressed button. After you have loaded this indicator on the chart, you will see the column of buttons on the right side of the chart.
    Good luck.
    Hi kkc2015. Thanks for sharing.
    I'm getting this when trying to download the code:
    Invalid File Specified


    Could you please re-up the file?
    Thanks a lot.

    Leave a comment:


  • Unsuitable
    replied
    Originally posted by rcrook23 View Post
    Hi Unsuitable would be interested to see your final result. The toolbar you had in NT7 is exactly what I'm looking for in NT8. I've tried to code something myself but I'm only a beginner coder.
    thanks in advance.
    There are no exact NT7 to NT8 toolbars conversions.
    NT7 Toolbar: https://ninjatraderecosystem.com/use...lbar-shortcut/

    However, people have used other libraries to reproduce the same functionality;
    https://ninjatraderecosystem.com/use...njaaddons-com/
    https://ninjatraderecosystem.com/use...-mahtoolbar-2/

    *Do note mahtoolbar calls the DrawingTool by way of hotkeys. So you may have to modify the script to match your hotkeys or use NT defaults.
    Last edited by Unsuitable; 10-01-2020, 03:21 PM.

    Leave a comment:


  • rcrook23
    replied
    Hi Unsuitable would be interested to see your final result. The tool bar you had in NT7 is exactly what I'm looking for in NT8. I've tried to code something myself but I'm only a beginner coder.
    thanks in advance.

    Leave a comment:


  • kkc2015
    replied
    All right Unsuitable, it looks like you have solved the problem.

    Leave a comment:


  • Unsuitable
    replied
    Hi kkc2015,

    I started to move the buttons so that they are alongside the main menu buttons. However, the solution to programmatically remove all the buttons does not seem to work with the main menu buttons. So chartWindow.MainMenu is where all the buttons are stored. When it comes to NT natives buttons, it has a wrapper and within that wrapper, there are the NT buttons. So the only object buttons within chartWindow.MainMenu[] are my buttons.

    Solutions tried
    1. Creating a new list and at the time of creating the buttons, store the new buttons. RESULT: the indicator crashes
    2. Tried using the UserControlCollection. RESULT: NT doesn't catch the crash so it infinite loops and I have to recover NT
    3. Using a foreach loop and specifying button filter. RESULT: indicator crashes
    4. Using a foreach loop and specifying Object filter and printing the elements: RESULT: Buttons + NinjaTrader.Gui.Tools.InstrumentSelector NinjaTrader.Gui.Tools.IntervalSelector + etc

    Code:
    ChartControl.Dispatcher.InvokeAsync((() =>
    {
      if (chartWindow != null)
      {
        //System.Windows.Controls.Button[] buttonsChartControl = {exampleButton}; //hardcoded
        //System.Windows.Controls.Button[] buttonsChartControl = chartWindow.MainMenu.OfType<System.Windows.Control s.Button>().ToArray(); //programmatically
    
        foreach (System.Windows.Controls.Button btn in chartWindow.MainMenu)
        {
          Print(btn.ToString());
        }
    
        System.Windows.Controls.Button[] buttonsChartControl = buttonList.ToArray();
    
        Print("ss");
        for (int i = 0; i < buttonsChartControl.Count(); i++)
        {
          Print("test ");
          if (buttonsChartControl[i] != null)
          {
            Print("bob ");
            chartWindow.MainMenu.Remove(buttonsChartControl[i]);
            buttonsChartControl[i].Click -= OnMyButtonClick;
            buttonsChartControl[i] = null;
            buttonList.Remove(buttonsChartControl[i]);
          }
        }
      }
    }));
    HOLD YOUR HORSES, I got it. Solution 1 does work, however one needs to initialize it. So it went from this

    Code:
    private List<System.Windows.Controls.Button> buttonList;
    to
    Code:
    private List<System.Windows.Controls.Button> buttonList;
    ...
    buttonList = new List<System.Windows.Controls.Button>();
    Last edited by Unsuitable; 09-29-2020, 08:13 PM. Reason: Clicked reply instead of preview

    Leave a comment:


  • kkc2015
    replied
    Hi Unsuitable,
    It looks like you are making good progress.
    Attached are a screen shot and a totally stripped down version of a button indicator (NT8), which can be imported and compiled.
    If you press the Help button to make it green, when you press any other buttons, you can see the text on the bottom right of the chart, showing the pressed button. After you have loaded this indicator on the chart, you will see the column of buttons on the right side of the chart.
    Good luck.
    Attached Files
    Last edited by kkc2015; 10-02-2020, 11:19 AM.

    Leave a comment:


  • Unsuitable
    replied
    //
    Originally posted by kkc2015 View Post
    Hi Unsuitable,
    Sorry for the confusion. The file contains the codes for the buttons and the grids + other unrelated variables which were used for other indicators. It is not a complete stand alone indicator and contains other variables (with declaration deleted) and thus would not compile. The main purpose is to show 1) the frame work, 2) the actual codes for the buttons and grids and 3) where they should be placed.

    You have to copy and paste only the button and grid codes, including declarations, and placed in the same sections (eg. initialize inside State.SetDefaults, State.DataLoaded, etc) of your indicator.
    Yeah no worries mate, I went with another button solution.

    So this dispatcher thing is new to me, but it's a requirement and what not for buttons. In the OG code, it went through each individual button by name. For 2 buttons this solution is fine, however for 10+ buttons, repeating the same code over and over is just bad practice. Down below I've implemented a for loop that takes care of all the buttons. Does this check out? It does compile but there can be some run time errors as well.

    Code:
    ChartControl.Dispatcher.InvokeAsync((() =>
    {
        if (myGrid != null)
        {
          System.Windows.Controls.Button[] buttons = { Button1, Button2, Button3, Button4, Button5, Button6, Button7, Button8, Button9, Button10};
    
          for (int i = 0; i < buttons.Count(); i++)
          {
             if (buttons[i] != null)
             {
                myGrid.Children.Remove(buttons[i]);
                buttons[i].Click -= OnMyButtonClick;
                buttons[i] = null;
             }
          }
    
       // if (Button1 != null)
       // {
       //    myGrid.Children.Remove(Button1);
       //    Button1.Click -= OnMyButtonClick;
       //    Button1 = null;
       // }
        }
    }));
    Thanks

    Edit: It must work cause if I remove that piece of code, it starts duplicating the buttons.
    Last edited by Unsuitable; 09-29-2020, 02:29 PM.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello kkc2015,

    To export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
    1. Click Tools -> Export -> NinjaScript...
    2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
    3. Click the 'Export' button
    4. Enter a unique name for the file in the value for 'File name:'
    5. Choose a save location -> click Save
    6. Click OK to clear the export location message
    By default your exported file will be in the following location:
    • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
    Below is a link to the help guide on Exporting NinjaScripts.
    http://ninjatrader.com/support/helpG...-us/export.htm

    Leave a comment:


  • kkc2015
    replied
    Hi Unsuitable,
    Sorry for the confusion. The file contains the codes for the buttons and the grids + other unrelated variables which were used for other indicators. It is not a complete stand alone indicator and contains other variables (with declaration deleted) and thus would not compile. The main purpose is to show 1) the frame work, 2) the actual codes for the buttons and grids and 3) where they should be placed.

    You have to copy and paste only the button and grid codes, including declarations, and placed in the same sections (eg. initialize inside State.SetDefaults, State.DataLoaded, etc) of your indicator.

    Leave a comment:


  • Mindset
    replied
    kkc2015

    Your code doesn't compile FYI.

    Leave a comment:


  • kkc2015
    replied
    Hi Unsuitable,
    Attached is a file showing the grid and button codes that I used in my application, which are also functional with tabbed charts. Note that all of the codes are from samples provided by Ninjatrader.
    Attached Files

    Leave a comment:


  • Unsuitable
    replied
    Originally posted by kkc2015 View Post
    Hi Unsuitable,
    Are you just looking for functional buttons on the edge of the chart screen? Please see attached chart screen.
    If so, I could provide you with related codes, which are all from Ninjatrader samples.

    [ATTACH]n1118752[/ATTACH]
    Yes that would be great!

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by cmoran13, 04-16-2026, 01:02 PM
0 responses
51 views
0 likes
Last Post cmoran13  
Started by PaulMohn, 04-10-2026, 11:11 AM
0 responses
31 views
0 likes
Last Post PaulMohn  
Started by CarlTrading, 03-31-2026, 09:41 PM
1 response
165 views
1 like
Last Post NinjaTrader_ChelseaB  
Started by CarlTrading, 04-01-2026, 02:41 AM
0 responses
100 views
1 like
Last Post CarlTrading  
Started by CaptainJack, 03-31-2026, 11:44 PM
0 responses
160 views
2 likes
Last Post CaptainJack  
Working...
X