Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

programmatically change a charts dataseries

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

    programmatically change a charts dataseries

    Hello, right now i have an indicator/addon that changes settings at different times of the day, I'm looking to try changing the timeframe bartype when my indicator reloads the new settings for that time, I force a chart refresh via

    Code:
    private void TriggerChartRefresh()
    {
        
                try
                {
                ChartControl.Dispatcher.InvokeAsync((System.Action)(() =>
                {
                    
                        // remove keyboard focus
                        Keyboard.ClearFocus();
    
                        // explicitly give the chart focus
                        ChartControl.OwnerChart.Focus();
    
                        // send an F5 key event
                        Keyboard.FocusedElement.RaiseEvent(
                        new KeyEventArgs(Keyboard.PrimaryDevice, PresentationSource.FromVisual(ChartControl.OwnerChart), 0, Key.F5)
                        { RoutedEvent = Keyboard.PreviewKeyDownEvent });
                        
    
                        ForceRefresh(); // Perform chart refresh
                        
                      
                }));
                }​
    I was wondering if I can do something like this

    Code:
     if (State == State.?)
        {
            if (ChartControl != null && ChartControl.ChartBars != null)
            {
                ChartBars.BarsPeriod.BarsPeriodType = BarsPeriodType.Tick;  // Set to Tick bars
                ChartBars.BarsPeriod.Value = 100;  // Set the value to 100 ticks
            }
        }
    
    or something like this
    
    if (State == State.?)
        {
            // Access the current bars series
            BarsPeriod barsPeriod = BarsPeriod.Clone();
    
            // Modify the barsPeriod to the desired type and interval
            barsPeriod.BarsPeriodType = BarsPeriodType.Minute;  // Change to Minute bars
            barsPeriod.Value = 5;  // Set interval to 5 minutes
    
            // Apply the new bar period
            BarsPeriod = barsPeriod;
        }​

    #2
    Hello KyleMcFar5,

    You can find the default keyboard shortcuts for changing to various types of series in the following link, that would be the only way to change to other bars types from code.

    As a side note ForceRefresh is not needed, changing the dataseries settings automatically reloads the chart. ForceRefresh if used for rendering purposes to mark that re rendering is needed, that has nothing to do with the chart loading.

    Comment


      #3
      ok i can make that work but what about for custom bartype or HA

      Comment


        #4
        Hello KyleMcFar5,

        There would not be a way to do that programmatically, only the supported bars types with keyboard shortcuts could be used.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        576 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        334 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        553 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        551 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X