Announcement

Collapse
No announcement yet.

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:	33
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 localappleseed, 10-23-2020, 04:10 PM
      1 response
      11 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by StevenNelson, Today, 03:24 PM
      0 responses
      3 views
      0 likes
      Last Post StevenNelson  
      Started by asmmbillah, Today, 08:13 AM
      1 response
      9 views
      0 likes
      Last Post NT-Roland  
      Started by BGWTEX, Today, 02:11 PM
      0 responses
      4 views
      0 likes
      Last Post BGWTEX
      by BGWTEX
       
      Started by Taddypole, Today, 12:44 PM
      0 responses
      7 views
      0 likes
      Last Post Taddypole  
      Working...
      X