Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Saving image of minimized chart of running strategy

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

    Saving image of minimized chart of running strategy

    I am trying to save the image of the chart in which my strategy is running. The code below works perfectly for saving the image of the currently displayed chart but I would like to save the image of a chart that is not in the forefront. I have several different strategies running and would like my strategy to save the current chart it is attached too, even if it is minimized. I assumed that using "this.ChartContol" would select the current chart that the strategy was attached too but it doesn't.

    PHP Code:
    public void zSaveChart() 
            {
                
                if(!zIsRealTime()) return; // Only save chart for real time trades
                
                if(ChartControl == null) // Strategy is not attached to a chart
                {
                    if(File.Exists(strategyPath + "\\image.png")) 
                        return; // Default image already saved to strategy directory
                    else
                    {
                        string path = NinjaTrader.Core.Globals.UserDataDir + "\\bin\\Custom\\Strategies\\image.png";
                        
                        if(File.Exists(path))
                        {
                            File.Copy(path,strategyPath + "\\image.png");
                        }                
                    }
                }
                else
                {
                
                    if (0 == Interlocked.Exchange(ref threadLock, 1))  //0 indicates that the method is not in use.
                    {
                        try
                        {
                            this.ChartControl.Dispatcher.InvokeAsync(() =>
                            {
                                NinjaTrader.Gui.Chart.Chart chart = Window.GetWindow(this.ChartControl) as NinjaTrader.Gui.Chart.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}", strategyPath, "image.png"))) png.Save(stream);
                                        NinjaTrader.Code.Output.Process("Screenshot saved to " + strategyPath, PrintTo.OutputTab1);
                                    }
                                    catch (IOException)
                                    {
                                        NinjaTrader.Code.Output.Process("ScreenshotTakerExample: Could not take screenshot", PrintTo.OutputTab1);
                                    }
                                }
                            });
                        }
                        catch (Exception ex)
                        {
                            NinjaTrader.Code.Output.Process("Could not save screenshot   " + ex, PrintTo.OutputTab1);
                        }
    
    
                        Interlocked.Exchange(ref threadLock, 0); //Release the lock
                    }
                }
            } 
    

    #2
    Hello cutzpr,

    Thank you for your note.

    There is no supported method for taking a screen shot of a minimized chart however I will submit a feature request for this.

    I have attached a sample using a different approach and if the chart is minimized the saved imagine will be a chart window with no data displayed.

    Please let us know if you need further assistance.
    Attached Files
    Alan P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    63 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    40 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    21 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    23 views
    0 likes
    Last Post TheRealMorford  
    Started by Mindset, 02-28-2026, 06:16 AM
    0 responses
    51 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X