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 benmarkal, Yesterday, 12:52 PM
                3 responses
                22 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by helpwanted, Today, 03:06 AM
                1 response
                18 views
                0 likes
                Last Post sarafuenonly123  
                Started by Brevo, Today, 01:45 AM
                0 responses
                11 views
                0 likes
                Last Post Brevo
                by Brevo
                 
                Started by aussugardefender, Today, 01:07 AM
                0 responses
                6 views
                0 likes
                Last Post aussugardefender  
                Started by pvincent, 06-23-2022, 12:53 PM
                14 responses
                244 views
                0 likes
                Last Post Nyman
                by Nyman
                 
                Working...
                X