Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Ninja Function to Save Chart Image to a file

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

    Ninja Function to Save Chart Image to a file

    Hi ,

    is there a function I can call inside my indicator to save the current chart image to a file if certain logic conditions are met?

    Thanks

    #2
    Hi mefTrader,

    Thank you for your post.

    Unfortunately this option is not available at this time within NinjaTrader however, I will forward this to our development team for future considerations.

    Please let me know if I may be of further assistance.
    Christopher J.NinjaTrader Customer Service

    Comment


      #3
      Has someone written a function like this?

      Someone has written a function " SendMailChart function" and put it in the misc area which is quite handy but I am getting a "The SMTP host was not found. " error even though my settings seem to be okay.

      Would be happy to save the image to my local hard drive rather than sending it onto myself!

      Comment


        #4
        Hi mefTrader,

        Thank you for your reply.

        You will need to double check the settings that you are using in the Misc tab of the Options menu with your email provider to make sure the correct settings are used. (Tools > Options > Misc Tab)

        Beyond this, I would suggest following up with this indicator's author to see if they have any additional tips or input.
        KyleNinjaTrader Customer Service

        Comment


          #5
          Chart Saving Strategy

          mefTrader,

          After a couple of months of manually saving charts several times a day, I finally took a shot at automating the process. The "logic conditions" important to me are simply the number of new bars that have been created since the last time the chart was saved, starting a sequence of saves in the premarket, and saving additional charts throughout the day. It was fairly easy to adapt the " SendMailChart function" from OregonSun with your added line for saving a chart instead of emailing it. It was more difficult to figure out how to capture the chart that included the final bar of the day. To accomplish that, I needed to incorporate elements of Josh's CustomEvents handler.

          In my case, I need to save a chart after as few as 5 bars for an indicator that only works in real time, so I leave NT running overnight and have it start saving charts in the premarket. I implemented this as a Strategy that does nothing more than save charts after some number of bars, with a counter that starts at a specified bar time and resets at each chart save. As the end of trading hours approaches (4:15 ET for me because I am capturing futures charts) I start a timer that ticks just after the market closes and triggers the last save of the day. I start the timer 5 minutes before the end of day because one of my charts is a 5-minute chart, but I could just as well start it long before that if I only wanted to run the strategy in real time.

          The strategy works fine with replay data because the start times are based on BAR times. The only subtlety is that the timer works in real time, so there is a delay in capturing the final image when the chart runs out of data if replay is faster than normal. This is why I start the timer only 5 minutes before the market closes. If I started it sooner, I'd have to wait longer for it to trigger after the replay data stopped. But for replay data one could just manually save the last chart of the day and not use the timer at all. (I have an idea for improving this by resetting the timer to the remaining BAR time in the day every time a new bar is generated. I will try to make this change soon. It should minimize the time delay between the end of replay data, and saving the final chart.)
          I "deleted" the quoted paragraph because I implemented the anticipated change. The attached file now incorporates the latest changes made on 11/11/2010. It has been tested running in live time and and fast replay (up to 500x) mode on a 5-minute chart, a 1 range chart and a several thousand volume chart, and seems to work fine, at least for active instruments that have a several ticks per bar.

          The attached file is the source code for the strategy. A couple of features are worth noting. In replay mode at least, and maybe even in some real time conditions, there is a race condition that must be avoided between my indicator, which draws things on my charts, and the strategy. This is accomplished by delaying the chart save a couple of ticks into a new bar. I have run replay at 50x and higher and not had any race problems. It seems replay is self-regulating and slows down when the data gets too fast.

          I changed the saved chart format from *.jpg to *.png because the saved charts are cleaner and smaller, and I only see them on my computer so it is a better format for me. It can easily be changed back to *.jpg if needed. File names have to be unique or they will be overwritten at each new save. I modeled the filenames after the names created by "Save as image" from the chart menu, appending a bar-time stamp to make them unique. All files are directed to one folder; the path needs to be adjusted for each user's environment. I created only one adjustable parameter, the number of bars between saves. It might be more elegant to have others, such as the start times, but I do not need them for myself.

          The print statements can be eliminated. They are there for monitoring progress, and might be useful for a while, especially if the strategy is running on multiple charts.

          I think the logic is reasonably transparent, and I think it would be fairly easy to adapt the code to some set of conditions other than just counting bars. It seems to be working fine for me, and it sounds like it might be close to what you are looking for.
          Attached Files
          Last edited by HNWtrader; 11-11-2010, 07:24 PM.

          Comment


            #6
            Chart Saving Indicator

            There is no reason why the chart saver needs to run as a strategy. There are no trades being managed. I created it that way originally because of the scripts created by others I was using as a starting point. I have now implemented it as an indicator. The source code is attached.

            For reasons I do not understand, sometimes when I connect to some of my older replay files, no historical bars are created. When this happens, the indicator fails to start. If it is reloaded after a few bars are created, it works.
            Attached Files
            Last edited by HNWtrader; 11-11-2010, 07:25 PM.

            Comment


              #7
              Hello,

              You are using a lot of unsupported code in your sample so I am only able to offer advice.

              What i suggest to help debug the code is to start adding Print() statements to the various if statements and locations verify what is running and not running when this occurs to narrow down what the culprit is.

              Let me know if I can be of further assistance.

              Comment


                #8
                Originally posted by NinjaTrader_Brett View Post
                Hello,

                You are using a lot of unsupported code in your sample so I am only able to offer advice.

                What i suggest to help debug the code is to start adding Print() statements to the various if statements and locations verify what is running and not running when this occurs to narrow down what the culprit is.

                Let me know if I can be of further assistance.
                I think the only unsupported parts of the code have to do with capturing the chart images and saving them to files (modeled after the code posted by other contributers), and I don't seem to have any problems with that code. Over the weekend I ran the indicator version on about 50 days of Market Replay data, and had no problems as long as there was historical data showing when the connection was made. I was running the replay at 500x to get through overnight data, and at 50x or 100x during the time I was capturing charts.

                I have no idea why some of the older ntm files do not show historical data upon connection, but I think it only happens on non-time based charts (e.g. volume or range charts). I have not seen that on any of the ntm files from the last couple of months. I do not think this has anything to do with my NinjaScripts, and it seems to no longer be a problem.

                Yesterday, everything was fine throughout the day, but unfortunately the final chart image on my large volume based chart did not trigger as expected. I spent today debugging the timer setting code needed to get the final capture to trigger. I already had a number of Print statements, and I modified some of them. I found and fixed a few things I did not have quite right involving calculations that mixed integers and non-integers. I'm really not very familiar with the language, and learning as I go.

                Most of the difficulty I have is trying to detect how fast the replay is running. If I did not care about replay mode, and not waiting forever for the final chart to be captured after the end of replay data, it would be a lot easier. It would also be a lot easier if I could read the replay speed setting from the system, instead of having to detect it from the times between bars. Apparently, no function exists to read the replay rate setting. I might be better off using my detector anyway, because if the replay speed is set too fast for the processor to keep up, the real replay speed is slower than the setting.

                I think I have it working about as well as can be expected now without being able to read the replay rate. I expect no further problems running in live mode, with no more than a several second delay in capturing the final chart (less than that for time based charts). I will do some more testing tomorrow, and if all goes well post new files for both the strategy and the indicator. It turns out there is an advantage to using the strategy version at times. For charts that can only run in real time (all mine are like this) the strategy can be started after the chart is already running without losing information from all the real-time indicators. This cannot be done with the indicator version.
                Last edited by HNWtrader; 11-10-2010, 07:42 AM.

                Comment


                  #9
                  I replaced the previously posted source code with the latest versions for both the strategy and the indicator. I think I made a significant improvement to the timers that are set to capture the final chart images at the end of the day. Unless I find some error down the road, or hear about problems from anyone who might have tried using these, I am done with them. They are working well for me now, with the final images being saved a few seconds after the 4:15 PM final-capture time.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by bmartz, Today, 09:30 AM
                  2 responses
                  11 views
                  0 likes
                  Last Post bltdavid  
                  Started by f.saeidi, Today, 11:02 AM
                  1 response
                  4 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Started by geotrades1, Today, 10:02 AM
                  4 responses
                  12 views
                  0 likes
                  Last Post geotrades1  
                  Started by rajendrasubedi2023, Today, 09:50 AM
                  3 responses
                  16 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Started by lorem, Today, 09:18 AM
                  2 responses
                  11 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Working...
                  X