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

programatically stretch bars

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

    programatically stretch bars

    hello everyone,

    Is it possible to programatically stretch the bars?

    for example : with this snippet below found here in the forum, I'd like the bars to have a specific stretch value (space between) when the window focuses on the tab.
    Code:
    this.Dispatcher.Invoke(() =>
    {
    chart = Window.GetWindow(this.ChartControl.Parent) as Chart;
    foreach (System.Windows.Controls.TabItem tab in chart.MainTabControl.Items)
    {
    tabName = tab.Header.ToString();
    if (tab.Header.ToString().Contains(BarsPeriods[0].ToString()) )
    {
    tab.Focus();
    // break;
    }
    }
    });
    can we define a stretch value ?

    #2
    Hi Amedeus, thanks for posting. The bars can be adjusted through the keyboard command Alt+Up/Down arrows. There's no supported way of adjusting this programmatically, you might be able to use SendKeys() to get this done though.
    https://docs.microsoft.com/en-us/dot...owsdesktop-6.0 (publicly available)

    Kind regards,
    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      hey Chris, thank you very much, brilliant idea.

      have a great week-end.

      Comment


        #4

        hey Chris, hey everyone,

        below is what I came to since having a zoomValue looks like something handy, works beautifully, thanks Chris.

        Code:
        // to paste in state setDefaults
        private void setDefaultInputParameters()
        {
        zoomOutValue = 0; // make this as big as the chart might be zoomed in
        zoomInValue = 0; // make this THE value looked after
        }
        
        // our initial tabSearch method, which focuses on the tab at hand, to be put somewhere in one's code
        private void tabSearch()
        {
        this.Dispatcher.Invoke(() =>
        {
        chart = Window.GetWindow(this.ChartControl.Parent) as Chart;
        foreach (System.Windows.Controls.TabItem tab in chart.MainTabControl.Items)
        {
        if (tab.Header.ToString().Contains(BarsPeriods[0].ToString()) )
        {
        tabName = tab.Header.ToString();
        tab.Focus();
        // our new method in action, what a show !
        setBarsSpacing(zoomOutValue, zoomInValue);
        // break;
        }
        }
        });
        }
        
        // our new method
        private void setBarsSpacing(int a, int b)
        {
        for (var i = 0; i < a; i++) { SendKeys.SendWait("%{DOWN}"); }
        for (var i = 0; i < b; i++) { SendKeys.SendWait("%{UP}"); }
        }
        
        
        #region // Properties // let's make it an input parameter
        
        [NinjaScriptProperty] [Display(Name = "zoomOutValue",
        Description = "number of hits on the zoomOut hotkey (hotkey must be set as default alt+down in ControlCenter/Tools/Hot Keys/Bar Spacing)",
        Order = 2, GroupName = "Parameters")]
        public int zoomOutValue { get; set; }
        
        [NinjaScriptProperty] [Display(Name = "zoomInValue",
        Description = "number of hits on the zoomIn hotkey (hotkey must be set as default alt+up in ControlCenter/Tools/Hot Keys/Bar Spacing)",
        Order = 3, GroupName = "Parameters")]
        public int zoomInValue { get; set; }
        
        #endregion // Properties //
        have a good one.
        Last edited by Amedeus; 04-22-2022, 05:01 PM.

        Comment


          #5

          Hi everyone,

          I've come to another code to avoid the systematic zoomOut/ZoomIn movements every time tabsearch() is called.
          we set a tabIdealNbOfBars number of bars in state.dataloaded, then later we SendKeys() depending on the actualTabNbOfBars.

          here it is :
          Code:
          private NinjaTrader.Gui.Chart.Chart chart;
          private System.Windows.Controls.TabItem tab_0;
          private string tabName;
          private int tabIdealNbOfBars;
          private int actualTabNbOfBars;
          
          
          else if (State == State.DataLoaded)
          {
          tabDefault();
          }
          
          
          public void tabDefault()
          {
          this.Dispatcher.Invoke(new Action(() =>
          {
          chart = Window.GetWindow(this.ChartControl.Parent) as Chart;
          
          foreach (TabItem tab in chart.MainTabControl.Items)
          {
          if (tab.Header.ToString().Contains(BarsPeriods[0].ToString()) )
          {
          tab_0 = (chart.MainTabControl.Items.GetItemAt(chart.MainTa bControl.SelectedIndex) as TabItem);
          tabName = tab.Header.ToString();
          }
          }
          
          for (var i = 0; i < zoomOutValue; i++) { SendKeys.SendWait("%{RIGHT}"); }
          for (var i = 0; i < zoomInValue; i++) { SendKeys.SendWait("%{LEFT}"); }
          tabIdealNbOfBars = ChartBars.ToIndex-ChartBars.FromIndex;
          }));
          }
          
          
          // later, somewhere in the code
          public void tabSearch()
          {
          this.Dispatcher.Invoke(() =>
          {
          chart = Window.GetWindow(this.ChartControl.Parent) as Chart;
          
          foreach (System.Windows.Controls.TabItem tab in chart.MainTabControl.Items)
          {
          if (tab == tab_0 )
          {
          tab.Focus();
          actualTabNbOfBars = ChartBars.ToIndex-ChartBars.FromIndex;
          if (actualTabNbOfBars != tabIdealNbOfBars )
          {
          if (actualTabNbOfBars < tabIdealNbOfBars )
          {
          while (actualTabNbOfBars < tabIdealNbOfBars)
          {
          SendKeys.SendWait("%{RIGHT}");
          actualTabNbOfBars = ChartBars.ToIndex-ChartBars.FromIndex;
          }
          }
          if (actualTabNbOfBars > tabIdealNbOfBars )
          {
          while (actualTabNbOfBars > tabIdealNbOfBars)
          {
          SendKeys.SendWait("%{LEFT}");
          actualTabNbOfBars = ChartBars.ToIndex-ChartBars.FromIndex;
          }
          }
          }
          }
          }
          
          });
          }
          
          // we keep the properties from the previous post, containing zoomIn/zoomOut values determined by the users bar spacing likings
          by.

          Comment


            #6
            hi Chris,

            Would you expect the bars of the chart to stop moving if we are on another program, like a browser, under the script post #5 ?
            That is what happens, until we click on the chart to have focus back on it, then the bars wake up and keep moving.
            This does not happen if we stay focused on the chart all along.

            when we comment the while snippets, the bars do not stop if we are on another app.

            tabSearch() is called in OnExecutionUpdate().

            is this to be expected, and what could we do about it ?

            Comment


              #7
              Hi Amedeus, thanks for the follow up. Make sure IsSuspendedWhileInactive is false in State.SetDefaults. This will keep the indicator running while the chart is inactive.


              Please let me know if this does not resolve the issue.
              Chris L.NinjaTrader Customer Service

              Comment


                #8
                hi Chris, thank you,

                IsSuspendedWhileInactive was allready set to true.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by zstheorist, Today, 07:52 PM
                0 responses
                5 views
                0 likes
                Last Post zstheorist  
                Started by pmachiraju, 11-01-2023, 04:46 AM
                8 responses
                150 views
                0 likes
                Last Post rehmans
                by rehmans
                 
                Started by mattbsea, Today, 05:44 PM
                0 responses
                6 views
                0 likes
                Last Post mattbsea  
                Started by RideMe, 04-07-2024, 04:54 PM
                6 responses
                33 views
                0 likes
                Last Post RideMe
                by RideMe
                 
                Started by tkaboris, Today, 05:13 PM
                0 responses
                6 views
                0 likes
                Last Post tkaboris  
                Working...
                X