Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

ScreenShot Addon

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

    ScreenShot Addon

    I am trying to convert the screenshot indicator found here https://ninjatrader.com/support/foru...d.php?p=474845 to an addon but I keep receiving the error below but this is exactly how the indicator cast the Window as a chart.

    Cannot implicitly convert type 'NinjaTrader.Custom.AddOns.Chart' to 'NinjaTrader.Gui.Chart.Chart'
    Cannot convert type 'System.Windows.Window' to 'NinjaTrader.Custom.AddOns.Chart' via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion
    From my strategy I am calling it using
    PHP Code:
    ScreenShot.chart Window.GetWindow(ChartControl) as Chart
    ScreenShot
    .SaveChart(); 
    Addon
    PHP Code:
    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using System.IO;
    using System.Windows.Media.Imaging;

    #endregion

    namespace NinjaTrader.Custom.AddOns
    {
        public static class 
    ScreenShot
        
    {        

            public static 
    NinjaTrader.Gui.Chart.Chart    chart
            
    getset; }
                    
            private static 
    System.Windows.Media.Imaging.BitmapFrame        outputFrame;
            
            
            public static 
    void SaveChart()
            {
                try    
                {
                    
    RenderTargetBitmap    screenCapture    chart.GetScreenshot(ShareScreenshotType.Chart);
                    
    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"MyScreenshot.png"))) png.Save(stream);
                            
    NinjaTrader.Code.Output.Process("Screenshot saved to " Core.Globals.UserDataDirPrintTo.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);
                }
            }
        
        }
        



    #2
    Hello cutzpr,

    Thank you for the post.

    I was unable to see the same error you had, but I did see a threading error when I tried this as you would need to use a dispatcher for this type of code.

    I created a small sample in an addon of the previous code and simplified the use. From the strategy you could call:

    Code:
    NinjaTrader.Custom.AddOns.ScreenShot.SaveChart(ChartControl);
    I look forward to being of further assistance.
    Attached Files
    JesseNinjaTrader Customer Service

    Comment


      #3
      I had errors importing the ninjascript addon you provided. I get the following errors. I am using 8.0.15.0 64-bit .
      Default Error compiling import assembly: c:\Users\XXXXX\Documents\NinjaTrader 8\tmp\Import\Files\bin\Custom\AddOns\ScreenShotAdd on.cs(35,65) : error CS1061: 'NinjaTrader.Custom.AddOns.Chart' does not contain a definition for 'GetScreenshot' and no extension method 'GetScreenshot' accepting a first argument of type 'NinjaTrader.Custom.AddOns.Chart' could be found (are you missing a using directive or an assembly reference?)
      Default Error compiling import assembly: c:\Users\CuTzP\Documents\NinjaTrader 8\tmp\Import\Files\bin\Custom\AddOns\ScreenShotAdd on.cs(34,20) : error CS0039: Cannot convert type 'System.Windows.Window' to 'NinjaTrader.Custom.AddOns.Chart' via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion

      Comment


        #4
        Hello cutzpr,

        Thank you for the reply.

        Had you removed the test you were conducting prior to importing the provided zip file using the Tools -> Import -> NinjaScript?

        I am not seeing this error when using the attached sample on my side. The error is stating the extension method GetScreenshot cannot be found which would generally indicate a missing using statement. You have also shown an error surrounding a conversion for the window and chart, but that is the same code from the indicator which you provided a link to and I assume you had tried and had success with?



        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Yes I removed my previous test before importing. I am not sure why this is occurring, I gave up and will just call it as an indicator vice an static addon.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by jclose, Today, 09:37 PM
          0 responses
          5 views
          0 likes
          Last Post jclose
          by jclose
           
          Started by WeyldFalcon, 08-07-2020, 06:13 AM
          10 responses
          1,413 views
          0 likes
          Last Post Traderontheroad  
          Started by firefoxforum12, Today, 08:53 PM
          0 responses
          11 views
          0 likes
          Last Post firefoxforum12  
          Started by stafe, Today, 08:34 PM
          0 responses
          11 views
          0 likes
          Last Post stafe
          by stafe
           
          Started by sastrades, 01-31-2024, 10:19 PM
          11 responses
          169 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Working...
          X