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

Saving chart image to file from ninjascript.

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

    Saving chart image to file from ninjascript.

    Disclaimer: I know this is not supported by NinjaTrader.
    I would like to hear if there are any other developers who may have some insight.

    I am using the following lines of code:

    HTML Code:
    Bitmap bmp = new Bitmap(chartControl.ChartPanel.Width, 
    					chartControl.ChartPanel.Height, 
    					PixelFormat.Format16bppRgb555);
    chartControl.ChartPanel.DrawToBitmap(bmp, chartControl.ChartPanel.ClientRectangle);
    bmp.Save(fileName, ImageFormat.Jpeg);
    When it runs, I do get an output file, but it always shows an empty picture.

    Can anybody suggest how to make this code save a valid image of the chart?

    BTW, the 3 lines of code above were found in some old ninjascript code I found that attached the image to an email. I just want to save it to a file.

    Thanks,
    Gary Albers

    #2
    As a follow up to my question...

    I discovered that the code works when run from a strategy, just not from an indicator.

    I can work with that.

    However, if any one knows how to make the code work from an indicator as well I would appreciate the information.

    Thanks,
    Gary

    Comment


      #3
      Originally posted by GaryAlbers View Post
      I discovered that the code works when run from a strategy, just not from an indicator.

      I can work with that.

      However, if any one knows how to make the code work from an indicator as well I would appreciate the information.

      Thanks,
      Gary
      Did you ever find a solution? I'm looking to create a toolbar button (I can already do that), that will save a screenshot to a temp folder (your code), then FTP it to my site (using this FTP code below (haven't tested it yet, but I hear it works)).

      PHP Code:
      WebClient myWebClient = new WebClient();

      Uri ftp_path = new Uri("ftp://FTPLOGIN:[email protected]/file.txt"); // file.txt
      myWebClient.UploadFile(ftp_path.ToString(), @"/temp/anyfile.txt"); // anyfile.txt - 
      I'm not sure if I can create a toolbar within a strategy, but I know I can in an indicator, so I'm curious if you've made any progress on this idea.

      Thanks!
      Daniel

      Comment


        #4
        I have no further info on saving a chart image from an indicator.

        I have used the same code in both indicators and strategies to add tool bar items.

        -Gary

        Comment


          #5
          Thanks for the reply. I created an indicator and it seemed to grab the screen shot just fine. The only difference I see from the Image > Save As... functionality is it doesn't put a nice header telling the instrument and time frame, but it does produce a higher quality image doing this programmatically.

          I went a few steps further to upload the screenshot to Imgur and put the returned URL into the clipboard for the user. A single click gets you a URL to your screenshot! Works perfect, except it seems to freeze Ninjatrader while it is processing and communicating with Imgur. I put a timeout of 4s so it doesn't get too out of hand.

          Thanks,
          Daniel

          Comment


            #6
            I think you could do most of that work on a separate, short lived thread.

            Comment


              #7
              Originally posted by GaryAlbers View Post
              I think you could do most of that work on a separate, short lived thread.
              Do you have a code snippet of how to implement that?

              Thanks!
              Daniel

              Comment


                #8
                How do you turn off chart trader so that i can run a ninjascript from the chart?

                Comment


                  #9
                  Originally posted by Camron View Post
                  How do you turn off chart trader so that i can run a ninjascript from the chart?
                  There should be an icon on the toolbar.

                  Daniel

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Tim-c, Today, 03:54 AM
                  0 responses
                  3 views
                  0 likes
                  Last Post Tim-c
                  by Tim-c
                   
                  Started by FrancisMorro, Today, 03:24 AM
                  0 responses
                  2 views
                  0 likes
                  Last Post FrancisMorro  
                  Started by Segwin, 05-07-2018, 02:15 PM
                  10 responses
                  1,772 views
                  0 likes
                  Last Post Leafcutter  
                  Started by Rapine Heihei, 04-23-2024, 07:51 PM
                  2 responses
                  31 views
                  0 likes
                  Last Post Max238
                  by Max238
                   
                  Started by Shansen, 08-30-2019, 10:18 PM
                  24 responses
                  945 views
                  0 likes
                  Last Post spwizard  
                  Working...
                  X