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 CarlTrading, 03-31-2026, 09:41 PM
          1 response
          43 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 04-01-2026, 02:41 AM
          0 responses
          20 views
          0 likes
          Last Post CarlTrading  
          Started by CaptainJack, 03-31-2026, 11:44 PM
          0 responses
          30 views
          1 like
          Last Post CaptainJack  
          Started by CarlTrading, 03-30-2026, 11:51 AM
          0 responses
          47 views
          0 likes
          Last Post CarlTrading  
          Started by CarlTrading, 03-30-2026, 11:48 AM
          0 responses
          38 views
          0 likes
          Last Post CarlTrading  
          Working...
          X