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

ATM Stragegy Synchronization between SuperDom and Chart Trader

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

    ATM Stragegy Synchronization between SuperDom and Chart Trader

    When using SuperDom with the Chart Trader Hidden, the selected ATM strategy can be different between the SuperDom and the Chart Trader.
    I use HotKeys for order entry and navigate betwen SuperDom and Chart while trading. This is a big issue for me because I can easily see the ATM strategy in the Superdom but not the hidden Chart Trader. Therefore if I press an order entry hotkey while positioned in the chart it will use the hidden Chart Trader ATM setting which by default is NONE and not the one that I see in the SuperDom.

    To me this makes using HotKeys for order entry dangerous as I can esily enter trades inadvertantly with no stops set by an ATM strategy.

    Possible solutions are:
    1. Never use the Chart Trader either as active or hidden.
    2. Never use the SuperDom and only use visible Chart trader.

    I really would rather have the ATM strategy automatically synchronized between SuprDom and Chart Trader whenever I change it:
    1. I can't figure out a way to do this with just HotKeys.
    2. I might be able to do this with AutoHotkeys but that gets a bit complicated and perhaps not very robust.

    I think perhaps this just leaves NinjaScript as a good solution so I wonder if it is posssible to use Ninjascript to:
    1. Recognize a change in the ATM strategy and synchronize it in both places. <or>
    2. Create a button in the SuperDom that always syncs the Chart Trader ATM to the SuperDom ATM <or>
    3. Maybe something I have not tought of ...

    In summary can a script be triggered by an event on an object such as ATM Stategy Changed Event?

    Thanks
    Carl

    #2
    Hello seagraph,

    Thank you for the post.

    In this situation I believe it would be best for me to put in a feature request for an option for this, similar to the existing window linking.

    You may be able to manage this with an addon, however it would not be a simple task. That would require observing all windows yourself and the individual ATM selector controls in those windows for changes. After accessing the selectors you could use the events from those controls: https://ninjatrader.com/support/help...gyselector.htm

    You can find an example of accessing an ATM selector in the following page, the code used in an addon would be similar however would need to be executed for many windows.



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

    Comment


      #3
      Thanks Jesse,
      I browsed the addon capability and this "seems" quite doable especially if I assume only one SuperDom and one Chart is active (for now):
      Please let me know if this is a good approach:

      Pseudo Code:
      // Add listener when SuperDom is added to workspace
      OnWindowCreate()
      if window type is SuperDom
      attach event listener for ATM selector StratChange()

      // Listener event handler
      StratChange()
      for each window in Globals.AllWindows
      if window type is Chart
      <get handle to ChartTrader>
      <get handle to Strategy Selector>
      Selector.Strategy = curStrat

      I did see this bit of code in your links but I am not sure if this eleminates the need to loop using Globals.AllWindows on not:
      chartTrader = Window.GetWindow(ChartControl.Parent).FindFirst("C hartWindowChartTraderControl") as ChartTrader;

      I am not clear on the concept of linked windows - perhaps if a SuperDom and Chart were linked this could be simplified

      Best,
      Carl

      Comment


        #4
        Hello seagraph,

        Yes this looks like you are on the right track. The OnWindowCreated will help with any new windows, and I see you have also used Globals.AllWindows to access all of the windows, so in theory this could work on more than just one superdom/chart active depending on how you code it.

        I did see this bit of code in your links but I am not sure if this eleminates the need to loop using Globals.AllWindows on not:
        chartTrader = Window.GetWindow(ChartControl.Parent).FindFirst("C hartWindowChartTraderControl") as ChartTrader;
        No this would be for a specific window. So in the context of the Globals.AllWindows, lets assume you have a loop and your loop is:
        Code:
        foreach(Window myWindow in Globals.AllWindows)
           chartTrader = myWindow.FindFirst("C hartWindowChartTraderControl") as ChartTrader
        In this psudocode the window in the loop is used to find the control, you will also need to use dispatchers to access the correct objects when doing this type of logic. It sounds like you may have worked with this type of concept before so I will leave that out for now to simplify this sample, if you need more details on this or are not sure what I am referring to here just let me know.

        You will likely need to make a method out of what you make here and call it from both OnWindowCreated (new windows) and also in State.Active (exiting windows) depending on how you want this to work. An addon is loaded after a compile, so you will very likely run into both cases while testing. You would probably be best off just using the Globals.AllWindows loop for all cases to make sure everything is setup across the workspace when new windows are made/destroyed/NS is compiled.


        I am not clear on the concept of linked windows - perhaps if a SuperDom and Chart were linked this could be simplified
        You can read about this here: https://ninjatrader.com/support/help...hlightsub=link

        I put in a feature request for this to include order entry window settings such as ATM strategies and other settings that are shared in the tools. You can already link timeframes and instruments in a chart/superdom so this feature is already there it just does not sync ATMS.

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

        Comment


          #5
          Greetings,

          Well thanks to Jesse I think I have the code that is finding the ATM selector object in the ChartTrader window but I can't figure out how to get or set the current strategy in the selector. I'm a bit overwhelmed by all the methods and properties so I am reaching out for help. Here is some prototype script where I get to the point of trying to print the name of the current strategy in the selector (I am assuming that I correctly have a handle to the selector)

          Code:
          namespace NinjaTrader.NinjaScript.AddOns
          {
              public class MyCustomAddOn : NinjaTrader.NinjaScript.AddOnBase
              {
          
                  protected override void OnWindowCreated(Window window)
                  {
                      if (window.ToString() == "NinjaTrader.Gui.SuperDom.SuperDom")
                          Print("super");
          
                      foreach(Window myWindow in NinjaTrader.Core.Globals.AllWindows)
                      {
                          Print("***" + myWindow.ToString());
                          if (myWindow.ToString() == "NinjaTrader.Gui.Chart.Chart")
                          {
                              Gui.Chart.ChartTrader chartTrader;
                              chartTrader = myWindow.FindFirst("ChartWindowChartTraderControl") as ChartTrader;
                              Print("###" + chartTrader.ToString());
                              NinjaTrader.Gui.NinjaScript.AtmStrategy.AtmStrategySelector selector = chartTrader.FindFirst("ChartTraderControlATMStrategySelector") as NinjaTrader.Gui.NinjaScript.AtmStrategy.AtmStrategySelector;
                              Print("^^^" + selector.ToString()); // this prints [B]AtmStrategySelector Items.Count:8[/B]
                              Print(selector.Items.CurrentPosition.ToString()); // this prints [B]-1[/B]
                              Print(selector.SelectedAtmStrategy.Name); // this prints [B]AtmStrategy[/B]
                              ///// I simply want to get or set value or index of ATM Strategy droppdown selector  ////
                          }
                      }
                  }
          
              }
          }
          Last edited by seagraph; 08-21-2019, 10:00 PM. Reason: To ask for aditional guidance

          Comment


            #6
            Hello seagraph,

            That looks like a good step forward, however you cannot set the SelectedAtmStraetgy directly because it is read only. You can change the SelectedItem if you know what specific item in the items list you want to change to. You could use an index for that purpose:

            Code:
            selector.SelectedItem = selector.Items[4];
            Here is a quick test just setting all selectors to the same value:

            Code:
            foreach (Window myWindow in Core.Globals.AllWindows)
            {
                if (!(myWindow is Chart)) continue;
                ChartTrader chartTrader = myWindow.FindFirst("ChartWindowChartTraderControl") as ChartTrader;
                if (myWindow.Dispatcher != null)
                {
                    myWindow.Dispatcher.InvokeAsync(() =>
                    {
                        AtmStrategySelector selector = chartTrader.FindFirst("ChartTraderControlATMStrategySelector") as AtmStrategySelector;
                        if (selector != null) { selector.SelectedItem = selector.Items[4]; }
                    });
                }
            }
            To get the name of a template, you can use the Template property instead:

            Code:
            selector.SelectedAtmStrategy.Template
            Likely you could do some logic to store the selected index, or find the selected item in the items collection to locate its index. I have not explored that far myself to advise there but using the SelectedItem seems to be one way which can set the selected item.


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

            Comment


              #7
              Thanks again for the great feedback.

              I see from your example that it is best if not absolutely manditory to use dispacher because the various GUI componets are multi-threaded and therefor messaging has to be done via a worker queue - my C# is a bit rusty.

              Yes I can add listeners (as windows are created) to the selection changed event and get the index in the event handler and then update all active ATM strategy selectors on all windows to this recently selected index.

              Currently it am having a bit of trouble understaning when the addon is triggered. I think this is because I have the editor open and compiling seems to retrigger stuff. I hope that once I am done tweaking the code and do a final compile then every time I restart NT ANY new window that is created will cause the listeners to be created on the windows types I specify and all should be good. Not sure about restoring workspaces but I will worry about that if and when needed.

              It is great that you are willing and responsive to my requests but I really should get to be more self sufficent. I don't know if the underlying libraries have more embedded documentaion or there are other resources to help understand the classes and data structures or if this is just a matter of learning by studying other examples. I think my C# and dotnet and coding are sufficiient but need to gain more knowledge of NT scripting. I can and probably should switch to using Visual Studio instead for the editor so I have a debbugging and other helpfull tools. So hopefully you can suggest a learning path for me.

              Best,
              Carl

              Comment


                #8
                Hello seagraph,

                I see from your example that it is best if not absolutely manditory to use dispacher because the various GUI componets are multi-threaded and therefor messaging has to be done via a worker queue - my C# is a bit rusty.
                Correct, in this case because NT is multi threaded you can hit a lot of threading errors when working with GUI elements. In most cases you will need a dispatcher, this really depends on the states used and what is being done. The easiest way to know is you will hit an error if you need to use one.

                Currently it am having a bit of trouble understanding when the addon is triggered. I think this is because I have the editor open and compiling seems to retrigger stuff. I hope that once I am done tweaking the code and do a final compile then every time I restart NT ANY new window that is created will cause the listeners to be created on the windows types I specify and all should be good. Not sure about restoring workspaces but I will worry about that if and when needed.
                I believe the best way to understand an addons life-cycle is to use a print. There are few cases where an addon reloads, and a print will show those. You could so something like the following to see whats happening:

                Code:
                protected override void OnStateChange()
                {
                     Print("OnStateChange " + State);
                }
                
                protected override void OnWindowCreated(Window window)
                {
                     Print("OnWindowCreated " + window.ToString() );
                }
                
                protected override void OnWindowDestroyed(Window window)
                {
                     Print("OnWindowDestroyed " + window.ToString() );
                }
                When recompiling your addon will reload because it is part of the NinjaScript collection. You should then see the windows in OnWindowCreated again to loop through them.

                It really depends on how you wanted to approach the logic here, you can react to the individual windows being created or you can loop over the Globals.AllWindows in one shot after State.Active. Both are valid ways but will require different approaches.

                To learn more about this subject I would suggest to study the help guide. If you are proficient in C# and have read any other programming API documentation, the Ninja Script manual works very similar. The Addon section is helpful to see what tools addons have available, there is also a large addon sample in the education resource:



                If you plan to work with UI elements, the addon sample basic is a good baseline which demonstrates a lot of the core UI concepts that are being used. You can also find a lot of good samples on the forum if you needed to look for a specific topic related to UI development. Usually just searching for part of the related syntax can bring up topics, like OnWindowCreated or Window or AtmStrategySelector as some examples.


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

                Comment


                  #9
                  I'm super interested in this feature as I have the same problem. It really is quite essential to be able to synchronize ATM strategies throughout your windows. I have zero knowledge in coding, is there a simple solution for this or an upgraded feature available?

                  Comment


                    #10
                    Hello BoliTrader08,

                    This would be a scripting solution, unfortunately there is not currently a easy way to do this besides what has been posted here.

                    Please let me know if I may be of further assistance.
                    JesseNinjaTrader Customer Service

                    Comment


                      #11
                      Was this ever submitted as a feature request? I too need to be able to synch my ATM across multiple order entry windows/tabs.

                      Comment


                        #12
                        Hello jculp,

                        Yes this was submitted, you can track this using the ID: SFT-958




                        Please let me know if I may be of further assistance.
                        JesseNinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by usazencort, Today, 01:16 AM
                        0 responses
                        1 view
                        0 likes
                        Last Post usazencort  
                        Started by kaywai, 09-01-2023, 08:44 PM
                        5 responses
                        603 views
                        0 likes
                        Last Post NinjaTrader_Jason  
                        Started by xiinteractive, 04-09-2024, 08:08 AM
                        6 responses
                        22 views
                        0 likes
                        Last Post xiinteractive  
                        Started by Pattontje, Yesterday, 02:10 PM
                        2 responses
                        21 views
                        0 likes
                        Last Post Pattontje  
                        Started by flybuzz, 04-21-2024, 04:07 PM
                        17 responses
                        230 views
                        0 likes
                        Last Post TradingLoss  
                        Working...
                        X