Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Ratio Chart

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

    Ratio Chart

    What are options available for plotting DIA:SPY (or any combination) chart? I searched the forum and could not find a cleaner solution to it so here is my proposal.

    Can we create a generic connection where we can define the URL. This connection will be similar to yahoo connection but it can connect to my custom server side script for data. The server script can do aggregation and all sort of stuff and will keep the logic isolated from NT.

    There are many use-case examples.

    * The request to http://example.com/data/fetch.php?q=DIA:SPY will make two separate requests to http://ichart.finance.yahoo.com/table.csv and calculate ratio and return the values.

    * The request to http://example.com/data/fetch.php?q=SSO*SDS will make two separate requests to http://ichart.finance.yahoo.com/table.csv and calculate product of these two data series and return the values.

    * The request to http://example.com/data/fetch.php?q=$USD will make a connection to local mysql database and return the values (yahoo does not have historical value for this instrument).

    * The request to http://example.com/data/fetch.php?q=SPY.COMPLEX will make many requests to http://ichart.finance.yahoo.com/table.csv and perform a complex calculation from various data-series and return the values.

    The server side script will also understand the a,b,c,d,e,f parameters (as interpreted in yahoo connection) and will filter data accordingly.

    A generic connection like this will open unlimited possibilities and should be pretty easy to do?

    Connection: Yahoo-generic, Google-generic
    Connection param: Fetch URL

    Do NT make connection source-code available to beta tester or partners?

    #2
    >> Can we create a generic connection where we can define the URL.
    Unfortunately this is not supported.

    Comment


      #3
      Originally posted by NinjaTrader_Dierk View Post
      >> Can we create a generic connection where we can define the URL.
      Unfortunately this is not supported.
      I understood that :-)

      So my request is to create a new connection provider where we can specify the fetch URL. It can be done by cloning the yahoo connection and make URL prefix configurable.

      So the usual request

      http://finance.yahoo.com/q/hp?s=SPY&a=00&b=1&c=1900&d=0&e=2&f=2010&g=m&y=0

      will translate to

      http://example.com/data/fetch.php?s=SPY&a=00&b=1&c=1900&d=0&e=2&f=2010&g=m&y=0

      and my fetch.php can do whatever it want (pull SPY data from local mysql) and return back values in desired format.

      Can you please forward this request to product development team? I can do this change by myself if source code for yahoo connector is made available.

      Comment


        #4
        Thanks for your suggestion. We'll add it to the list of future considerations.

        Comment


          #5
          For those who are looking for an interim solution, please override host definition and have it pointed to your local server

          == C:\WINDOWS\system32\drivers\etc ==

          Code:
          192.168.15.101	finance.yahoo.com
          And add following in your apache conf.d directory

          Code:
          Alias /q/hp   "/var/www/html/fetch.php"
          I'll post my fetch.php after some clean-up.

          Stay tuned.

          Comment


            #6
            I would love to have the ability to plot ratio charts. Is there a less technical way that NT could provide this ability?

            Comment


              #7
              Originally posted by Tartan View Post
              I would love to have the ability to plot ratio charts. Is there a less technical way that NT could provide this ability?
              Not at this time.
              RayNinjaTrader Customer Service

              Comment


                #8
                TraderSU: It looks like your php option is our best bet. Are you still planning on posting it when you have had time to clean things up. Thanks!

                Comment


                  #9
                  Here's a simple NT7 Ratio indicator (attached). You apply it to the chart of the "Numerator" instrument, then add the indicator and specify the "Denominator" instrument symbol as an indicator parameter.

                  I also posted a simple Spread indicator a while ago:

                  http://www.ninjatrader-support2.com/...read+indicator

                  Both of these indicators have potential timing inaccuracies if used in real time on lightly traded instruments, due to the lack of any synchronization capability in NT7. I've built my own generalized solution to the problem, which I plan to post when I think it's finalized (it works fine on indicators, but I'm running into NT7 bugs in strategies). I'll also post updated Spread and Ratio indicators which use it, along with a correlation indicator.

                  -Kevin
                  Last edited by kdoren; 02-07-2010, 07:06 AM. Reason: Deleted Ratio.zip file, please see post #23 for updated version

                  Comment


                    #10
                    Originally posted by Tartan View Post
                    TraderSU: It looks like your php option is our best bet. Are you still planning on posting it when you have had time to clean things up. Thanks!
                    For some reason, I never receive any notifications from this forum when someone replies to my threads so I was not aware of your interest.

                    I can surely share the PHP code and also give you my IP so that you can use it directly. There will be a modification required in "C:\WINDOWS\system32\drivers\etc\hosts" file and that is all. Simply un-comment that line when you want to use my script as a smart replacement of yahoo historical feed.

                    Will post it sometime this weekend.

                    Thanks,

                    Comment


                      #11
                      I did something but the data load is bit glitchy.

                      Created a new instrument named "MYCOMP" for NYSE exchange. On other tab (misc) I have it as "100*QLD:QID" for Yahoo symbol map.

                      A chart request does following request to my server

                      192.168.15.11 - - [18/Jan/2010:21:44:54 +0000] "GET /table.csv?s=100*QLD:QID&d=0&e=28&f=2010&g=d&a=6&b= 7&c=2008&ignore=.csv HTTP/1.1" 200 18327 "-" "-"
                      192.168.15.11 - - [18/Jan/2010:21:44:54 +0000] "GET /table.csv?s=100*QLD:QID&d=0&e=28&f=2010&g=d&a=0&b= 8&c=2010&ignore=.csv HTTP/1.1" 200 336 "-" "-"

                      My host file is fixed to request my server for yahoo connection.

                      If I hit the following URL, I get expected response but NT7 is only loading a single bar :-(



                      My fetch.php is attached in case someone is willing to work in parallel.
                      Attached Files

                      Comment


                        #12
                        Thanks to KDoren for his contribution of the "Ratio" indicator. I'm a novice pairs trader as well and this is really helpful.
                        I wanted to create also a "% from mean" indicator too, so I took the Ratio indicator and used it as a template and tried to modify a few things to it. I'm pretty new at NT programming so of course it failed for probably a very basic reason. Maybe if KDoren or NT support reads this they can help?

                        Basically all I did was take KDoren's "KDRatio" subroutine and add in the necessary calcs for the % from mean. Here's what I did:

                        private double KDRatio(double price1, double price2, bool normal)
                        {
                        if (normal) // Normalized Ratio -> P1/(P1 + P2)
                        if ((price1 + price2) != 0)
                        return (price1 / (price1 + price2));
                        else
                        return (0);
                        else // Standard Ratio -> P1/P2
                        if (price2 != 0)
                        {
                        curratio = price1 / price2;
                        meanratio = SMA(price1 / price2, 14);
                        return ((curratio - meanratio) / meanratio);
                        }
                        else
                        return (0); // Return 0 rather than throw exception
                        // but it's better to check for divide by 0 before calling
                        }


                        ... the only new stuff I added was:

                        curratio = price1 / price2;
                        meanratio = SMA(price1 / price2, 14);
                        return ((curratio - meanratio) / meanratio);


                        ... but when I tried to compile it, it didn't like the SMA stuff. I know there's this "DataSeries" thing and maybe that's what I had to do, but I haven't a clue how that works.

                        Thanks!
                        Shawn

                        Comment


                          #13
                          meanratio = SMA(price1 / price2, 14);

                          You can't just set meanratio to the SMA DataSeries. You need to set it to an actual double value. Please try:

                          meanratio = SMA(price1 / price2, 14)[0];
                          Josh P.NinjaTrader Customer Service

                          Comment


                            #14
                            Thanks Josh, but that still didn't work. I get 2 compile errors on that same line:

                            - The best overloaded method match for "NinjaTrader.indicator.indicator.SMA(Ninjatrader.D ata.IDataSeries.int)" has some invalid arguments (Code CS1502)

                            - Argument '1': cannot convert from 'double' to 'NinjaTrader.Data.IDataSeries' (Code NT1503)

                            Thanks
                            Shawn

                            Comment


                              #15
                              Shawn,

                              My mistake. That is correct. You cannot do price1 / price2 calculations like that and pass it to SMA assuming it would do all the historical back calculations of it. You need to create a custom DataSeries first to store that calculation and then call that DataSeries.



                              myDataSeries.Set(price1 / price2);
                              meanprice = SMA(myDataSeries, 14)[0];
                              Josh P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              601 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              347 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              103 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              559 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              558 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X