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

checking tab details / bar type for addon

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

    checking tab details / bar type for addon

    Hello i have an addon that is added for each relevant tab in a chart.

    I manage and process each tab and to create the detail i need - which is all good.

    What i want to determine ... in OnWindowCreated which is called on starting a new chart within here i process the tabs. What is recommended way to check the bartype for each tab being processed in a chart ..

    for each tab being processed from MainTabControl i get the following ...

    ChartTab chartTab = currentTab.Content as ChartTab;

    _currentTabchartControl = chartTab.ChartControl;

    BarsType barType = null;

    barType = Bars.BarsType as NinjaTrader.NinjaScript.BarsTypes.MYCUSTOMEBARType ;

    so now i have the type of my custom type

    can i check this against the bar type of the current tab being processed.
    Is this bar information available at this point?
    eg ... the following but realise this is not the same as bartype .. and will only tell me if tick - minute etc .. i need to know if matches my bartype ideally ... i couldnt see BarsType in the available list here ..

    _currentTabchartControl.BarsPeriod.GetType


    What i would like to do is only process the tab in the iteration if it matches my custom bar type and ignore/not process any other bar type.

    In the OnWindowCreated called from an addon .. i would like to confirm what is available to reliably check for ... ie Bars .. Indicators loaded on the chart ?

    The other way would be to check from the list of indicators...

    foreach (NinjaTrader.Gui.NinjaScript.IndicatorRenderBase currentIndicator in chartIndicators)

    if My indicator is on the tab ....

    so either way .. asking for guidelines as to what is available .. similary to the onstatechange approach and what is available at each stage eg Bars .. Instrument etc

    hope this is clear

    thanks

    #2
    Hello soulfx,

    Thanks for opening the thread.

    I would suggest to look for BarsPeriod.BarsPeriodTypeName to identify the custom BarType.

    Some ways you could get this would be through looping through the ChartObjects to get the ChartBars and then to reference the Bars object of ChartBars to then get the BarsPeriod and then the BarsPeriodTypeName.

    Custom BarType OnStateChange() SetDefaults
    Code:
    BarsPeriod = new BarsPeriod { BarsPeriodType = (BarsPeriodType) 14, BarsPeriodTypeName = "MyCustomBarType(14)", Value = 1 };
    Referencing ChartBars.Bars - http://ninjatrader.com/support/helpG...tbars_bars.htm

    We don't have any documentation that will tell you what is reliable to be accessed on a window creation. To reference something reliably, it is suggested to follow the State system.

    You could also write the BarType and other AddOn's/Indicators/Strategies so they can share data in an AddOn with static variables to work around this. I will provide a link to the NT8 MyShared Methods example for the thread's reference.

    MySharedMethods NT8 - http://ninjatrader.com/support/forum...104#post457104

    Please let me know if I can be of further help.
    JimNinjaTrader Customer Service

    Comment


      #3
      Hello, so i tried to check/process this and it would seem at the time of OnWindowCreated() being called

      the ChartBars.Bars is not available ... so unable to check this as i process each tab

      IList<NinjaTrader.Gui.NinjaScript.IChartObject> myObjects = _currentTabchartControl.ChartObjects;

      foreach (NinjaTrader.Gui.NinjaScript.IChartObject thisObject in myObjects)
      {

      // Does this object relate to ChartBars?

      if (thisObject is ChartBars)
      {
      ChartBars cb = thisObject as ChartBars;

      if (cb.Bars != null)
      {
      if (cb.Bars.BarsPeriod.BarsPeriodTypeName.ToString(). Equals("MyCutomBartype1"))
      {
      _MyBartTypeChartFound = true;


      }
      }

      }
      }

      So checking on the bar type .. doesnt seem available - hence my question to you in the original message. Is there a way to get an indication once a Tab is loaded by Ninja in the addon - i do register for this in the addon once the window is created but this is for new tabs added after the initialisation - so i know when to process a new tab after startup. Is there a way to know this on startup in a similar way - that way i could wait before i load my Xaml for the addon and set various properties

      thanks

      Comment


        #4
        Hello soulfx,

        Here is some code that will search through all tabs in all open windows to find a specific BarType by name and change some parameters in an AddOn:

        Code:
        private void CheckChartTabs()
        {
        	foreach (var window in 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.BeginInvoke(new Action(() =>
        		{
        			//try to cast as a Chart, if it fails it will be null
        			var foundChart = window as NinjaTrader.Gui.Chart.Chart; 
        			if (foundChart == null) return;	
        
        			foreach (TabItem tab in foundChart.MainTabControl.Items)
        			{
        				var foundChartTab = tab.Content as NinjaTrader.Gui.Chart.ChartTab;
        				//Print("");//foundChartTab.ChartControl.PrimaryBars.Bars.BarsType.Name);
        				if(foundChartTab.ChartControl.PrimaryBars.Bars.BarsType.Name.Contains("Minute"))
        				{
        					Dispatcher.BeginInvoke(new Action(() =>
        					{
        						Caption = "Minute";
        						Width = 400;
        						Height = 250;
        					}));
        				}
        			}
        		}));
        	}
        }
        This can be used in the AddOn's constructor, or you can call this method at another time in your AddOn to check if there is a tab that includes a specific custom bar type.

        As far as detecting a new tab, I am not aware of a NinjaTrader signal that could be used. You may wish to use some code similar to the following to detect new tabs.

        Code:
        var view = System.Windows.Data.CollectionViewSource.GetDefaultView(foundChart.MainTabControl.Items);
        view.CollectionChanged += (o, e) =>
        {
            var newItem = e.NewItems[0] as System.Windows.Controls.TabItem;	
        };
        The code demonstrated above uses many undocumented components, and as such the amount of support we can provide will be very limited.

        EDIT 2/16/2018: NOTE! BarsPeriodTypeName is deprecated. It would then be advised to use the index for your custom bartype and cast it with BarsPeriodType when adding a custom bar type. Detecting chart tabs with a certain BarType by name can be done by following the example above.

        Please let me know if I can be of further help.
        Last edited by NinjaTrader_Jim; 02-19-2018, 08:43 AM.
        JimNinjaTrader Customer Service

        Comment


          #5
          Hello, i just got that very annoying ninja message on submission and timing and lost all my text,

          briefly i got it working but it does not work in the way you proposed. It was along the lines of what i had already coded.

          The _currentTabchartControl.BarsPeriod.BarsPeriodTypeN ame.ToString().Equals("MyCustomBarType")

          is available and i am able to filter out the tabs i want.

          The PrimaryBars is not available and tests as null

          Im not sure if you have tested what you proposed or was just sample code, the onwindowCreated seems to be called after all the ninjatrader initialisation - so for now i am testing this more but wondering why this is available and the other information ie Bars is not - all i need is the BarsPeriod to make my check - so if this is reliable then i am good as far as this goes for now

          let me know
          thanks

          Comment


            #6
            Hello soulfx,

            Yes. I tested the posted code in the constructor of an AddOn.

            Here is a demonstration: https://www.screencast.com/t/5udXx96vtph

            As I mentioned in my initial reply, we don't have any documentation that will tell you what is reliable to be accessed on a window creation. You may find something that works, but we only recommend using the State system for reliable references. This is why I tested in the AddOn's constructor to loop through all charts and tabs to find the custom BarsType.

            Of course, further code will have to be implemented to track what you are doing after you detect your BarsType and make changes in the AddOn window.

            Since OnWindowCreated() would not guarantee a valid reference, we could submit a feature request for a method that gets called when a new tab is created (and ready.) Other than that, I would suggest to devise a solution based on looping through the Charts and tabs.
            JimNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Gerik, Today, 09:40 AM
            2 responses
            6 views
            0 likes
            Last Post Gerik
            by Gerik
             
            Started by RookieTrader, Today, 09:37 AM
            2 responses
            11 views
            0 likes
            Last Post RookieTrader  
            Started by alifarahani, Today, 09:40 AM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by KennyK, 05-29-2017, 02:02 AM
            3 responses
            1,285 views
            0 likes
            Last Post NinjaTrader_Clayton  
            Started by AttiM, 02-14-2024, 05:20 PM
            11 responses
            186 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Working...
            X