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

Custom ChartStyle: Icon missing when first starting NinjaTrader

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

    Custom ChartStyle: Icon missing when first starting NinjaTrader

    I have my own custom ChartStyle with it's own 16x16 icon (I've also tried 24x24).

    Everything displays normally in the chart bar type selection list and in the toolbar after changing to my style BUT my icon is missing from the toolbar when Ninja Trader starts -- it shows a blank space.

    Click image for larger version

Name:	Screenshot 2020-09-29 112057.png
Views:	342
Size:	3.4 KB
ID:	1120328
    EXPECTED: You should see the icon between "4 Minute" and to the pencil, not just when selecting but on start-up too.


    I saw samples with multiple ways to load the icon and I even tried making it static so that it would always be there but that doesn't seem to fix this.

    Some code...

    Code:
    namespace NinjaTrader.NinjaScript.ChartStyles
    {
        public class MyCustomStyle : ChartStyle
        {
            private BitmapImage iconBitmapImage = null ;
            private object icon = null;
    
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Name = "* Custom *";
                    ChartStyleType = (ChartStyleType)99;
                }
                else if (State == State.Configure)
                {
                    ..............
                    // Set the BitmapImage's UriSource to the location o f an image file - see https://ninjatrader.com/support/helpGuides/nt8/?cs0103.htm
                    try
                    {
                        if (icon == null && iconBitmap Image == null)
                        {
                            string fname = NinjaTrader.Core.Globals.UserDataDir + "bin\\Custom\\MyMedia\\icon_bk16x16.png";
                            if (!File.Exists(fname))
                            {
                                icon = Gui.Tools.Icons.ChartEquivolume;
                            }
                            else
                            {
                                iconBitmapImage = new  BitmapImage();
                                iconBitmapImage.BeginI nit();
                                iconBitmapImage.UriSou rce = new Uri(fname);
                                iconBitmapImage.EndIni t();
                            }
                        }
                    }
                    catch (Exception exIcon)
                    {
                        Print("☰☰☰☰ ERROR - exception.\n" +  exIcon.ToString());
                        icon = Gui.Tools.Icons.ChartEq uivolume;
                    }
                }
            }
    ........
    
            public override object Icon
            {
                get
                {
                    if (icon != null)
                        return icon;
    
                    try
                    {
                        // Instantiate a Grid on which to place the image
                        Grid myCanvas = new Grid { Height = 16, Width = 16 };
    
                        // Instantiate an Image to place on the Grid
                        Image image = new Image
                        {
                            Height = 16, Width = 16,
                            // Height = 24, Width = 24,
                            Source = iconBitmapImage
                        };
    
                        // Add the image to the Grid
                        myCanvas.Children.Add(image);
                        icon = myCanvas;
                    }
                    catch (Exception ex)
                    {
                        Print("☰☰☰☰ ERROR - exception getting icon canvas, reverting to normal icon.\n" + ex.ToString());
                        icon = Gui.Tools.Icons.ChartEq uivolume;
                    }
                    return icon;
                }
            }
    It's all pretty straight-forward.

    * Am I doing something wrong? Or do I need to hook something else up?

    * Is there a problem with using a PNG image as my icon?


    I can find no examples where someone used their own icon.

    #2
    Hello ntdev,

    Thanks for the post.

    One comment I would have here is that you used a try/catch but you are routing that to the output window which may not be loaded before your chart to get any errors.

    I used what you provided and made a test from that, on further inspection you are using State.Configure which is only called when you configure the type. Your image loading should go in SetDefaults as you need a default value for it when the type is created. I have attached a quick sample of how you might want to structure loading the image.




    I look forward to being of further assistance.
    Attached Files
    Last edited by NinjaTrader_Jesse; 09-29-2020, 09:06 AM.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Your image loading should go in SetDefaults as you need a default value for it when the type is created. I have attached a quick sample of how you might want to structure loading the image.
      Wow, Jesse. That was TOO EASY! Thank you, thank you, thank you.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by RookieTrader, Today, 09:37 AM
      3 responses
      14 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by kulwinder73, Today, 10:31 AM
      0 responses
      5 views
      0 likes
      Last Post kulwinder73  
      Started by terofs, Yesterday, 04:18 PM
      1 response
      23 views
      0 likes
      Last Post terofs
      by terofs
       
      Started by CommonWhale, Today, 09:55 AM
      1 response
      3 views
      0 likes
      Last Post NinjaTrader_Erick  
      Started by Gerik, Today, 09:40 AM
      2 responses
      7 views
      0 likes
      Last Post Gerik
      by Gerik
       
      Working...
      X