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 (
    == Interlocked.Exchange(ref threadLock1))  //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 " strategyPathPrintTo.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   " exPrintTo.OutputTab1);
                        }


                        
    Interlocked.Exchange(ref threadLock0); //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 trilliantrader, Yesterday, 03:01 PM
    3 responses
    30 views
    0 likes
    Last Post NinjaTrader_Clayton  
    Started by cmtjoancolmenero, Yesterday, 03:58 PM
    4 responses
    26 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by Brevo, Today, 01:45 AM
    1 response
    14 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by rjbtrade1, 11-30-2023, 04:38 PM
    2 responses
    74 views
    0 likes
    Last Post DavidHP
    by DavidHP
     
    Started by suroot, 04-10-2017, 02:18 AM
    5 responses
    3,022 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Working...
    X