Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Why can't draw in other tab chart ?

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

    Why can't draw in other tab chart ?

    Hi!

    I'm trying to iterate through all charts within a window (it has tabs), draw a text when I change the tab and then save to an .png image.

    The problem is only drawing in the indicator window, not on the others.

    Also, I want to obtain the timeframe of every tab and use it on filename image.

    My actual code:
    Code:
    ...
    private NinjaTrader.Gui.Chart.Chart chart;
    ...
    
    private void CaptureAllCharts()
    {​
    ChartControl.Dispatcher.InvokeAsync(async () =>
    {
         var chartWindow = Window.GetWindow(ChartControl.Parent) as Chart;
         var chartControl = chartWindow.ActiveChartControl;
         int i = 0;
         var tabs = chartWindow.MainTabControl.Items;
         if (tabs == null || tabs.Count == 0) return;
    
         int tabActual = chartWindow.MainTabControl.SelectedIndex;
         string safeDateTime;
         foreach (TabItem tab in chartWindow.MainTabControl.Items)
         {
         safeDateTime = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss");
         chartWindow.MainTabControl.SelectedIndex = i;
    
         await Task.Delay(1000);
         chartControl = chartWindow.ActiveChartControl; //no necesario??
         Draw.TextFixed(this, safeDateTime + i, BarsPeriod.Value.ToString() + "_" + BarsPeriod.BarsPeriodType, TextPosition.BottomLeft);
         chartControl.InvalidateVisual();
         CaptureChartImage(chartControl, i, BarsPeriod.Value.ToString(), BarsPeriod.BarsPeriodType.ToString());
         RemoveDrawObject(safeDateTime + i);
         i++;
    
    }
         chartWindow.MainTabControl.SelectedIndex = tabActual;
    });​
    }
    
    
    
    private void CaptureChartImage(ChartControl chartControl, int i, string barsValue, string barsPeriodType)
    {
    if (chartControl != null) {
    
    string path = Core.Globals.UserDataDir + "SavedImages\\";
    chart = Window.GetWindow(chartControl) as Chart;
    
    if (chart != null)
    {
    try
    {
    if (!Directory.Exists(path))
    {
    Directory.CreateDirectory(path);
    }
    
    RenderTargetBitmap screenCapture = chart.GetScreenshot(ShareScreenshotType.Chart);
    BitmapFrame outputFrame = BitmapFrame.Create(screenCapture);
    if (screenCapture != null)
    {
    PngBitmapEncoder png = new PngBitmapEncoder();
    png.Frames.Add(outputFrame);
    string safeDateTime = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss");
    string fileName = Instrument.FullName + "_" + BarsPeriod.Value + "_" + barsPeriodType + "_" + safeDateTime + "_" + i;
    fileName = fileName.Replace('/', '_').Replace('\\', '_').Replace(':', '_').Replace(' ', '_');
    
    string filePath = Path.Combine(path, fileName + ".png");
    
    using (Stream stream = File.Create(filePath))
    {
    png.Save(stream);
    }
    
    Print("Captura guardada: " + filePath);
    }
    }
    catch (Exception ex)
    {
    Print("Error al guardar la captura: " + ex.Message);
    }
    }
    
    }
    }​
    Last edited by franjcy; 08-03-2024, 02:47 PM.

    #2
    Hello franjcy,

    Drawing in other tabs from a single script is not supported, you would need to apply the script to that tab to draw in that tab.

    One note on the code you provided it is using the async/await pattern which is not supported, I would suggest to avoid that type of use in NinjaScript.

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello franjcy,

      Drawing in other tabs from a single script is not supported, you would need to apply the script to that tab to draw in that tab.

      One note on the code you provided it is using the async/await pattern which is not supported, I would suggest to avoid that type of use in NinjaScript.
      So If i can't draw in other tabs, what can i do to draw the timeframe on saved .png and thus differentiate them? The function "chartWindow.SaveChartImage()" with it contextual menú does save the timeframe.

      Comment


        #4
        Hello franjcy,

        The method you mentioned only saves an image, there is not anything in NinjaScript which can be used to edit that image in any way. That is not a documented/supported method so it is limited to the use it has. While you can save images with that you would have to come up with your own logic for naming or defining what is in the image if you needed that information at a later time.

        You could use the first sample from this post: https://forum.ninjatrader.com/forum/...are#post717865

        That shows an alternate unsupported method which can be used but that allows you to save it with a specific name so you could include any details in the filename that you wanted.

        Comment


          #5
          Originally posted by NinjaTrader_Jesse View Post
          Hello franjcy,

          The method you mentioned only saves an image, there is not anything in NinjaScript which can be used to edit that image in any way. That is not a documented/supported method so it is limited to the use it has. While you can save images with that you would have to come up with your own logic for naming or defining what is in the image if you needed that information at a later time.

          You could use the first sample from this post: https://forum.ninjatrader.com/forum/...are#post717865

          That shows an alternate unsupported method which can be used but that allows you to save it with a specific name so you could include any details in the filename that you wanted.
          Thanks Jessy, I'll try with it.

          Comment


            #6
            Originally posted by NinjaTrader_Jesse View Post
            Hello franjcy,

            The method you mentioned only saves an image, there is not anything in NinjaScript which can be used to edit that image in any way. That is not a documented/supported method so it is limited to the use it has. While you can save images with that you would have to come up with your own logic for naming or defining what is in the image if you needed that information at a later time.

            You could use the first sample from this post: https://forum.ninjatrader.com/forum/...are#post717865

            That shows an alternate unsupported method which can be used but that allows you to save it with a specific name so you could include any details in the filename that you wanted.
            Sorry, last question.

            You said "chartWindow.SaveChartImage()​" is a function undocumented. Isn't that funcion that it's executed when right click on chart Save Chart Image?? That image does save the timeframe on image saved.

            Comment


              #7
              Hello franjcy,

              I am not sure because that is not documented, we have no way to look at the internals of the platform and the methods the menu actions use.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              597 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              343 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              103 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              556 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              555 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X