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

Need little help with Ticks Per minute indicator development

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

    Need little help with Ticks Per minute indicator development

    I use tick charts mainly and have found the time histogram helpful to graphically display when the market is moving fast or slow. Yesterday I had the thought of displaying the range (in ticks) per minute based on this indicator which comes with Ninja I believe.

    I have got it to plot accurately but there are two problems:

    a) I would like to concurrently plot an MA over the basic values
    b) Something is wrong with the display sometimes. I have a sneaking suspicion it might have something to do with null/void issues (which unfortunately I don't understand yet as I am not good at Ninja coding), but usually it is fine, but then for a while it displays all bars at some sort of maximum value that has nothing to do with the accurate value and I have no idea why.

    I attach code + two pictures, one with it displaying properly (the green histogram indicator in a lower panel) and one with it displaying incorrectly.

    Any help with how to put together a moving average of the base plot would be much appreciated. I have copied/adapted from various examples I have found, but nothing works and I am stumped as to what I am doing wrong.

    I find this indicator slightly better than the Time Histogram in that you can instantly see/compare how much it is moving in range terms per minute (per second is too fast to be all that meaningful). This helps compensate for one of the (visual) disadvantages of tick charts in that the time factor is not easily apparent.

    OK, I can't upload the pic because it is 127 k and that is too large and don't know how to decrease it. (It's a very tight limitation!) But if anyone loads the indicator and displays it on a tick chart hopefully the same problem will be apparent. I will try to make a smaller picture with less memory.
    Attached Files

    #2
    OK, two smaller pics, one with indicator working fine, the second with it 'ballsed up'.
    Attached Files

    Comment


      #3
      Hi there. There is another indicator that counts ticks per second here. It could easily be modified to make it ticks per minute.

      To get a moving average of ticks per minute, all you'd have to do is run a SMA calculation against the TPM dataseries.

      For some funny reason, I feel like I've tried to do this before but there were some weird results; I think I ended up having to code my own moving average.
      AustinNinjaTrader Customer Service

      Comment


        #4
        Originally posted by NinjaTrader_Austin View Post
        Hi there. There is another indicator that counts ticks per second here. It could easily be modified to make it ticks per minute.

        To get a moving average of ticks per minute, all you'd have to do is run a SMA calculation against the TPM dataseries.

        For some funny reason, I feel like I've tried to do this before but there were some weird results; I think I ended up having to code my own moving average.
        Thanks. Looked at it but since the whole thing is configured for ticks per second it is very differently written and would require quite a makeover for tick charts using language I don't yet know.

        The one I supplied works but has problems. I am interested in figuring out what those problems are and that way I, and any others who read the thread, learn more about coding protocols. So the issue/thread is not just about the goal of creating the indicator, but learning how to code better and figure out the problems. There are no error messages and I don't have a clue why sometimes it plots fine and other times it doesn't. That is the real issue more than getting the indicator per se.

        Simply put: do you (or anyone else) have any idea based one what I wrote why it sometimes displays incorrectly?

        And again, I am baffled as to why I can't plot a moving average of the base ticks-per-minute values.

        Comment


          #5
          Cclsys, it appears you will have to debug your script. Here is a link to a reference for an introduction to debugging.

          Unfortunately, we don't provide custom programming (debugging) services. If you'd like a professional solution, you can contact one of our NinjaScript consultants.
          AustinNinjaTrader Customer Service

          Comment


            #6
            debugging

            Originally posted by NinjaTrader_Austin View Post
            Cclsys, it appears you will have to debug your script. Here is a link to a reference for an introduction to debugging.

            Unfortunately, we don't provide custom programming (debugging) services. If you'd like a professional solution, you can contact one of our NinjaScript consultants.
            Thanks. Since I cannot use the Print command - at least have not been able to figure it out even using simple examples in the Help Menu which never produce any results in the Output Window - that won't help me at this stage.

            Am not interested in paying for something simple like this. Since this is a forum, perhaps another Ninja user will find the concept of interest and/or the programming challenge a good source of information/learning. That is one of the benefits of a forum, after all. I also understand that Ninja staff are not allowed to help with programming problems, so don't feel obliged to keep responding. Maybe others will!

            Comment


              #7
              Originally posted by cclsys View Post
              Thanks. Since I cannot use the Print command - at least have not been able to figure it out even using simple examples in the Help Menu which never produce any results in the Output Window - that won't help me at this stage.
              I can help you with this. Using the print command is absolutely essential for debugging purposes. Please find attached a very simple indicator that just prints the last price to the output window. It is named PrintSample.

              You'll find the print line: Print("Last price:\t" + Close[0]) and the \t might throw you off--\t just means tab.
              Attached Files
              AustinNinjaTrader Customer Service

              Comment


                #8
                debugging 2

                Originally posted by NinjaTrader_Austin View Post
                Cclsys, it appears you will have to debug your script. Here is a link to a reference for an introduction to debugging.

                Unfortunately, we don't provide custom programming (debugging) services. If you'd like a professional solution, you can contact one of our NinjaScript consultants.
                Here are the instructions you kindly linked:

                "The first step you should do is to strip your code down into simple code segments. You want to start your debugging at a point where you know the code works as expected."

                Since the code in question is:
                int timeGap=(int)ts1.TotalSeconds-(int)ts2.TotalSeconds; // from the Time Histogram indicator supplied

                TPM.Set (Range()[0])/ timeGap *60 / TickSize);

                It is not easy to discern how one could strip it down much further. Of course, if I could use the Print command I could separatre each element, but still the issue remains: when it works it is accurate, but somettimes it just doesn't display properly.

                viz. Print command, for example, I inserted the following from your link into the indicator:


                if (Close[0] > Open[0])
                {
                Print("Code has entered If statement. Close: "+ Close[0] + " Open: " + Open[0]);
                // Do something
                }

                Nothing (as always) displays in the Output window when I open it up. Then I go back to the code, hit F5, and look again in the Output window. Nothing. Have never managed to get anything into that Output Window!
                Last edited by cclsys; 07-16-2009, 01:24 PM.

                Comment


                  #9
                  A quick glance popped this thought into my head: if timeGap = 0, then you'd get a divide by zero error.

                  You never get anything to the output window? Are you running the indicators with CalculateOnBarClose = true or false? If false, OnBarUpdate gets called for every tick, and thus, everything inside of OnBarUpdate will run once for every tick. If true, if you're running the script on a 1 minute chart for example, it would only print once every minute. You do need to compile the indicator and reload the NinjaScripts on the chart (right-click chart -> Reload NinjaScript or 'F5' again).

                  Now, back to the debugging process. It is true you need to split it up. I'd split it up into just two sections.
                  1. timeGap. Print this value out.
                  2. Range()[0])/ timeGap *60 / TickSize. Print that value out as well.
                  This code shows how I'd debug this:
                  Code:
                  protected override void OnBarUpdate()
                          {
                              if (CurrentBar<10) return;
                              
                              TimeSpan ts1 = Time[0] - new DateTime(1970,1,1,0,0,0);
                              TimeSpan ts2 = Time[1] - new DateTime(1970,1,1,0,0,0);
                  
                              int timeGap=(int)ts1.TotalSeconds-(int)ts2.TotalSeconds;
                              Print("timeGap:\t" + timeGap);
                  
                              double ticksPerMinute = (Range()[0] / timeGap * 60 / TickSize);
                              Print("TPM:\t" + ticksPerMinute);
                  
                              TPM.Set (ticksPerMinute); 
                  
                              // worry about this stuff later
                              //AvgTPM.Set ( SMA (TPM,15)[0]);        
                       }
                  In addition to using Print to debug, the logs (right-most tab in the Control Center) usually contain information about any errors you may have.

                  Please let me know if you have any other questions. I want to help you get to the debugging stage.
                  Last edited by NinjaTrader_Austin; 07-16-2009, 01:41 PM.
                  AustinNinjaTrader Customer Service

                  Comment


                    #10
                    Thanks.
                    Does it matter if I have several charts open at the same time with the same indicator? I used your:
                    Print("timeGap:\t" + timeGap);

                    but it didn't come out.

                    However, for some reason when I first opened the Output Window again - have not been doing anything in Ninja for an hour or so but have left it running - the Open-Close code output was there. However, when I added in your code, and without changing the other stuff, again nothing in the Output window. Blank.

                    Thanks for the info on the Log Menu. Never noticed that. But nothing in there after F5-ing the indicator and getting nothing in the Output Window. Also added in another two lines:

                    double ticksPerMinute = (Range()[0] / timeGap * 60 / TickSize);
                    Print("TPM:\t" + ticksPerMinute);

                    But no different result.

                    Are you saying that you cannot test an indicator/ get a Print Output if you hare in on bar update mode?

                    Update: I had changed workspaces between one post and the other and the indicator was not being applied anywhere. Now I am getting something in the Output Window. Not sure why didn't get earlier (when indicator was certainly loaded in active workspace) but will try to figure out what the differences were. Thanks. Though hopefully some help from someone with display issue and/or moving average issue will be forthcoming in the thread.
                    Last edited by cclsys; 07-16-2009, 02:18 PM.

                    Comment


                      #11
                      We need to make sure your print function works correctly. If you don't mind, I'm going to lay out a test for you so we can get on the same page.
                      1. Exit NinjaTrader and then get back into it.
                      2. Download and then import PrintSample. I've attached it again. (File -> Utilities -> Import NinjaScript)
                      3. Connect to Simulated Data Feed
                      4. Open up a new chart with <None> for the chart template.
                      5. Open up the output window.
                      6. From your chart, open up the indicators window and only add PrintSample. On the right side of the window, verify Calculate on bar close is false. Click OK.
                      7. Go back to the output window. Is there data streaming in?
                      Attached Files
                      Last edited by NinjaTrader_Austin; 07-16-2009, 02:25 PM.
                      AustinNinjaTrader Customer Service

                      Comment


                        #12
                        Austin,
                        thanks. I ran your sample code but before that had figured something out that is not mentioned in the Help Menu: in order to print something into the Output Window it is not sufficient to simply hit F5 with a chart open with the indicator. (I 'grew up' on Tradestation wherein you just hit F3 and the indicator/code runs wherever it is applied and then output is generated into the output window). It never occurred to me that I had to reload the instruments on the actual chart window. Now it works fine.

                        SUGGESTION: include this information in the Help Menu, i.e.: in order to get data into the Output window, after compiling the code with F5, run the indicator again in an open Chart by choosing/opening Indicators from an open chart, and then press the OK button.

                        As far as I can tell this simple - albeit necessary - procedure, is not explained anywhere. I could not, for example, find anything about the Output Window in the Help menu; the Print help section only gives coding examples, not how to get the data into the Output Window.

                        The other questions from the beginning of the thread remain, but thanks to this interchange at least I have figured out how to get print command outputs!

                        Comment


                          #13
                          Originally posted by cclsys View Post
                          Austin,
                          The other questions from the beginning of the thread remain, but thanks to this interchange at least I have figured out how to get print command outputs!
                          Great! That is a very serious first step towards getting what you want out of NinjaTrader. I'll forward your comments to the people who need to see them.

                          Since we got way out of the way of your original question, my post #9 is where we left off. The next time your indicator doesn't plot correctly, check the logs right away. There will most likely be something there about the error.
                          AustinNinjaTrader Customer Service

                          Comment


                            #14
                            Well, I made a small change to limit the bars that spike 10* more than the usual, which happens with tick charts of course, by using ATR, so now if the range per minute is > 9* the 21 ATR, it plots at 9* the current ATR(21). But any time I try to get an average price I get stuck.

                            The main reason I want the average value is both to see any sort of regular oscillation and/or rising/falling momentum in range per minute, but also to use the average as the base for limiting the bar display. But the ATR 'governor' probably works fine in that regard, so the main issue remaining is how to get that average plotted.

                            On some charts it plots fine the way I coded and on others the average does not plot at all and the values are incorrect. There is no message in the Logs either. I suspect that someone who knows how to write these sort of things could make quick work of it. In the Print Output, when the chart is fine the base price and averages are fine, when the chart doesn't work it says the average is N/A, but I have no idea why, furthermore why it works in some charts and not others (all tick charts, all the same instrument, but some faster and slower charts.) Probably there is a problem with things being too fast, or a negative value creeping in somewhere but I haven't figured it out yet.

                            I have run out of time today, but I suspect I will have to create a couple of data series first to hold the values using the second to hold the average of the first, and then Set the two Plots from those data series. But I have only made a data series once and have to go through the steps carefully to do so because there are quite a few of them unlike making basic doubles and ints etc.

                            All the above said, I suspect this will be a very handy indicator for those using tick charts because it is often easy to miss that movement is accelerating or decelerating time-wise when using them, and yet it is often much better to take signals during times when the range over time is accelerating, and it is exactly this acceleration that usual indicators like ATR, range etc. do not show when using tick charts, although they work very well with time charts. This indicator will compensate for that disadvantage in terms of not just seeing time-per-bar, as with the Time Histogram provided, but showing the range-over-time, and especially acceleration/deceleration of the same. It works, but it would be best to have an average on it, although not absolutely necessary of course.

                            I attach the latest version with the ATR governor versus the originally attempted MA governor (not in the code attached earlier but anyway).

                            Two examples this morning using a relatively 'fast' 45 tick chart in the Sept Bonds 30 yr. The first around 8.30 happened around a report and the TickTime indicator spiked up to its limit immediately of course.

                            But then later on on this same snapshot around 836 a similar spike up that indeed was the start of a decent ( for scalper types) trade. No report then. When looking at the chart it's a typical bar. But with the TickTime display, you get an immediate heads-up that range-over-time momentum has just picked up considerably. Obviously this doesn't always work for signals etc. but it is good to see this range-time momentum graphically on a tick chart.
                            Attached Files
                            Last edited by cclsys; 07-16-2009, 04:06 PM.

                            Comment


                              #15
                              cclsys,

                              If you want to print out the values for the series that the average runs on to see if there is any funny data (like a negative value), you could do a for loop:
                              Code:
                              for (int i = 0;i<15;i++)
                              {
                                   Print("TPM[" + i + "]:" + "\t" + TPM[i]);
                              }
                              AustinNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by inanazsocial, Today, 01:15 AM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_Jason  
                              Started by rocketman7, Today, 02:12 AM
                              0 responses
                              10 views
                              0 likes
                              Last Post rocketman7  
                              Started by dustydbayer, Today, 01:59 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post dustydbayer  
                              Started by trilliantrader, 04-18-2024, 08:16 AM
                              5 responses
                              23 views
                              0 likes
                              Last Post trilliantrader  
                              Started by Davidtowleii, Today, 12:15 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post Davidtowleii  
                              Working...
                              X