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

Draw Image (png) on Chart

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

    Draw Image (png) on Chart

    Hello,

    I'm trying to load an image from file and display it on the chart; a company logo.

    Using the example NinjaJess posted here, I am getting an exception "Unsupported Pixel Format." I have connected with the debugger and changed to the PixedFormat that RenderTarget is using, but the same exception persists.

    Any light you may be able to shed would be helpful.

    Thank you
    mrlogik
    NinjaTrader Ecosystem Vendor - Purelogik Trading

    #2
    Hello mrlogik,

    Thanks for opening the thread.

    I recently made some changes to the example Jesse posted to dispose of any resources needed to create the bitmap on RenderTarget changes and on the indicator's termination.

    Attached is an updated example. If you are still able to encounter issues with this script, could you provide us some steps we could take to reproduce on our end?

    We are happy to look into this further as needed.

    EDIT: Additional changes have been made so best practices are reflected. Resources are no longer disposed in State.Terminated, but disposed in OnRenderTargetChange when RenderTarget is null. (RenderTarget will be null at the end of the scripts life which will dispose resources, but not recreate them.)
    Attached Files
    Last edited by NinjaTrader_Jim; 02-18-2021, 01:34 PM.
    JimNinjaTrader Customer Service

    Comment


      #3
      Works perfectly, thank you Jim
      mrlogik
      NinjaTrader Ecosystem Vendor - Purelogik Trading

      Comment


        #4
        Thank you Jim.

        How can I test if the file exists?

        In NT7 all is very easy with Drawing and Drawing2D namespaces, but in NT8 are limited !? why?

        I cant use the simple code: if (File.Exists(@"C:\Users\Public\signal_short.wav") ...

        Comment


          #5
          Hello ninjo,

          File.Exists would be included with System.IO. You will need to add a using statement to use System.IO with your script. An example that uses System.IO with NT8 can be found below.



          Let us know if you have any questions.
          JimNinjaTrader Customer Service

          Comment


            #6
            Hello Jim,

            i tried using your draw bitmap example in a code I built for a client and NT crashes if the indicator isn't set to OnBarUpdate as the calls to get the picture are too frequent.
            Is there a way to cache the bitmap in memory and just retrieve it without getting the Direct X error?

            Comment


              #7
              Hello MazaMaza,

              Thanks for your post.

              The example disposes and recreates in OnRenderTargetChange and draws in OnRender. It stays in memory until it the RenderTarget changes and we need to update the bitmap.

              If you need to update the bitmap in OnBarUpdate, I would recommend setting some class level variables and a bool for "NeedsUpdate" Then on the next OnRender, you could check the bool and call a method that does the regular disposing and recreating that is done in OnRenderTargetChange to load the new bitmap.

              I'm not exactly sure of the full scope of your issue without seeing an example. If you would like to modify the script so it is showing what you are doing, I could give further insight.

              ​​​​​​​I look forward to assisting.
              JimNinjaTrader Customer Service

              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