Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy chart active screen

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

    Strategy chart active screen

    Hello again, could you help me with a small problem?

    I want to save an image of the chart where a strategy is activated, but in a chart with several tabs, with this method it sends me the active tab, is it possible to send the chart where the active strategy is and not the tab that is visible?​





    public static class ScreenShot
    {
    public static void SaveChart(ChartControl cc)
    {
    try
    {
    cc.Dispatcher.InvokeAsync(()=>{
    Chart chart = Window.GetWindow(cc) as Chart;
    RenderTargetBitmap screenCapture = chart.GetScreenshot(ShareScreenshotType.Chart);
    System.Windows.Media.Imaging.BitmapFrame outputFrame = BitmapFrame.Create(screenCapture);

    if (screenCapture != null)
    {
    try
    {
    PngBitmapEncoder png = new PngBitmapEncoder();
    png.Frames.Add(outputFrame);
    using (Stream stream = File.Create(string.Format(@"{0}\{1}", Core.Globals.UserDataDir, "TelegramImage.png"))) png.Save(stream);
    }
    catch (IOException)
    {
    NinjaTrader.Code.Output.Process("ScreenshotTakerEx ample: Could not take screenshot", PrintTo.OutputTab1);
    }
    }
    });
    }
    catch (Exception ex)
    {
    NinjaTrader.Code.Output.Process("Could not save screenshot " + ex, PrintTo.OutputTab1);
    }
    }

    }​

    #2
    Hi Ruben, thanks for writing in. Unfortunately, It would not be possible to capture graphics from an inactive tab since the graphics are no longer rendered when the tab is not selected. The chart tab must be visible to capture the render target contents.

    Kind regards,
    -ChrisL

    Comment


      #3
      Thank you very much, as always you are a great help, I will discard this one and I will be able to continue working on something else.

      Comment


        #4
        Does it mean it is impossible to save chart in StrategyAnalyzer as well ?
        This code below saves me an empty window.

        Code:
                
        protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
                {
                    // Reset flags when position is closed
                    if (Position.MarketPosition == MarketPosition.Flat)
                    {
                            Dispatcher.InvokeAsync(new Action(() =>
                            {
                                Chart chart = Window.GetWindow(ChartControl) as Chart;
                                if (chart != null)
                                {
                                    Print("Has chart: " + Core.Globals.UserDataDir);
                                    RenderTargetBitmap screenCapture = chart.GetScreenshot(ShareScreenshotType.Window);
                                    if (screenCapture != null)
                                    {
                                        BitmapFrame outputFrame = BitmapFrame.Create(screenCapture);
                                        PngBitmapEncoder png = new PngBitmapEncoder();
                                        png.Frames.Add(outputFrame);
                    
                                        string fileName = string.Format(@"{0}\{1}_{2}.png",
                                            Core.Globals.UserDataDir,
                                            Name,
                                            time.ToString("yyyyMMdd_HHmmss"));
                    
                                        using (Stream stream = File.Create(fileName))
                                        {
                                            png.Save(stream);
                                        }
                    
                                        Print("Screenshot saved to: " + fileName);
                                    }
                                }
                            }));
                    }
                }
        ​

        Comment


          #5
          Hello asxcdcaec,

          When the strategy analyzer is run the chart is not present, it is only present after changing to that tab which is why indicators and other graphic items may not appear as intended.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          50 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          126 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          69 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          42 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          46 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X