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

Why aren´t these rays parallel?

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

    Why aren´t these rays parallel?

    Hi guys!

    30 min chart. Same K value - still not parallel. What did I miss? //FREEN


    // highray
    double highestprice = MAX(Highs[0], lookback)[0];
    int highestbar = HighestBar(Highs[0], lookback);
    double hprice = (Kvalue * -CurrentBar) + highestprice;
    DrawRay(
    "Highray", true, CurrentBar, hprice, highestbar, highestprice, Color.Gray, DashStyle.Dash, 1);



    // lowray
    double lowestprice = MIN(Lows[0], lookback)[0];
    int lowestbar = LowestBar(Lows[0], lookback);
    double lprice = (Kvalue * -CurrentBar) + lowestprice;
    DrawRay(
    "Lowray", true, CurrentBar, lprice, lowestbar, lowestprice, Color.Gray, DashStyle.Dash, 1);

    #2
    Hello FREEN,

    Thank you for your post.

    Gave your code a quick test using a Kvalue of 1 and lookback of 5 (complete guesses) and the rays are parallel.

    You may want to use Print() to output the values of your hprice, lprice values to ensure they are as expected.

    Also when using DrawRay(), having autoscale true will squish the chart down and make it hard to read, I set auto scale to false to make it easier to compare the lines.
    DexterNinjaTrader Customer Service

    Comment


      #3
      I´m using K = 0.0137 (main trend) and lookback 500 (30 min chart still). It seems the error accumulates with bars lookback. Can you replicate that error?

      Edit: autoscale true/false = same error.

      Comment


        #4
        Hello FREEN,

        I tried those settings on an ES 06-11 chart and they are still drawn parallel for me. Note that if automatic scaling is on, they may shift in angle but again, they were still correct as far as I can tell.

        If you are still doubting they are not parallel, you could Print() the difference between the two rays (the visible gap), the highest highs and lowest lows, and the and see if that changes unexpectedly on any bars. Printing before and after your Kvalue calculation will let you see if the math is pushing them out of line as well.
        DexterNinjaTrader Customer Service

        Comment


          #5
          Thanks Dexter!

          Is there a way to refer to the "Lowray" and "Highray" draw objects as variables? " double diff = Highray - Lowray " would be conventient in your debug suggestion?!

          Comment


            #6
            Hello FREEN,

            You can keep track of objects with IDrawObject but it is a little more advanced. Unfortunately, you could not subtract two IDrawObjects to get the relevant underlying positions. You can however Print these objects to see what values were used, or do the math yourself. For example:

            Code:
            IDrawObject lowRay;
            lowRay = DrawRay("Lowray", true, CurrentBar, lprice, lowestbar, lowestprice, Color.Gray, DashStyle.Dash, 1);
            Print(lowRay.ToString());
            This will output something along these lines:

            Name='Ray' Time='4/3/2011 4:15:00 PM', StartBar='0' StartY='1273.90' EndTime='4/18/2011 10:45:00 PM' EndBar='1043' EndY='1295.00'

            Alternatively you can just print the difference between lprice and lowestprice vs hprice and highestprice. Print("hprice - lprice = " + (hprice - lprice)); and so forth.

            If the lines still appear to be not parallel to each other, please attach a screenshot of what you are seeing so we can check it out. Thank you
            DexterNinjaTrader Customer Service

            Comment


              #7
              Sorry my stupidity... "Print(hprice - lprice);" was the obvious answere. I appreciate your explanation on IDrawObjects however.


              I made a test on ES 06-11 as well, but "Print(hprice - lprice)" does not print a consistent diff. I can´t even find the logic since it includes both conv/lower and div/higher values. I´ll post a screenshot, but it´s not really evident there.

              Thanks, Fredrik

              Comment


                #8
                Just in case in matters, here´s the all the code. There´s a midline drawn as well:

                if (CurrentBar < lookback) // Return if not enough bars
                {
                return;
                }


                // highray
                double highestprice = MAX(Highs[0], lookback)[0];
                int highestbar = HighestBar(Highs[0], lookback);
                double hprice = (Kvalue * -CurrentBar) + highestprice;
                DrawRay(
                "Highray", true, CurrentBar, hprice, highestbar, highestprice, Color.Gray, DashStyle.Dash, 1);



                // lowray
                double lowestprice = MIN(Lows[0], lookback)[0];
                int lowestbar = LowestBar(Lows[0], lookback);
                double lprice = (Kvalue * -CurrentBar) + lowestprice;
                DrawRay(
                "Lowray", true, CurrentBar, lprice, lowestbar, lowestprice, Color.Gray, DashStyle.Dash, 1);



                // midray
                double midestprice = (highestprice + (Kvalue * (highestbar - lowestbar)) + lowestprice) / 2;
                double mprice = (hprice + lprice) / 2;
                DrawRay(
                "Midray", true, CurrentBar, mprice, lowestbar, midestprice, Color.LightGray, DashStyle.Dash, 1);


                Print(hprice - lprice);
                Print(
                "");

                Comment


                  #9
                  Hi Fredrik,

                  No problem, give printing all of your values a try.

                  Also just looked at the screenshot, I see what you are talking about now, thanks.

                  I'm suspect that the math of high and lows of the actual price data is causing the convergence. You also might be running into floating point number issues too. Perhaps using Round2TickSize() will help keep it in line with price data on the chart.

                  For more information on Round2TickSize(), please see http://www.ninjatrader.com/support/h...trument_ro.htm

                  If you can't get them in line, it might be a good idea to simplify the formula used for the Ray anchors until it works as expected and then go from there.

                  One last thing, would the Regression Channel indicator that comes with NinjaTrader perform what you need? You could add it to your indicator with a period of 500, and access it's Upper and Lower values. Please see http://www.ninjatrader.com/support/h...on_channel.htm


                  Please give the above a try and let me know if it's still occurring.
                  DexterNinjaTrader Customer Service

                  Comment


                    #10
                    Tnx Dexter! I´ll dig in to the info you provided. Xlnt support as always! : )

                    //Fredrik

                    Comment


                      #11
                      Pickin´up an old thread here since problem persists. I´ve simplified things as in code bellow to try understand where things go wrong. In a 30 min chart the ray plotted behaves erratically when zooming in/out or moving back/forth in time. The ray cuts at different prices at the same bar.

                      Why would this ray not behave as a ray from drawing tools?

                      lookback = 1000
                      Kvalue = .0077

                      double highestprice = MAX(Highs[0], lookback)[0];
                      int highestbar = HighestBar(Highs[0], lookback);
                      double hprice = (Kvalue * -CurrentBar) + highestprice;
                      DrawRay(
                      "Highray", false, CurrentBar, hprice, highestbar, highestprice, Color.Gray, DashStyle.Dash, 1);

                      Comment


                        #12
                        Hi Freen,

                        Thanks for these details. Can you please post the complete script you're using so we can give it a run here. You have a multiseries script but the added series is not known.
                        Ryan M.NinjaTrader Customer Service

                        Comment


                          #13
                          Script enclosed in support mail.

                          Comment


                            #14
                            Originally posted by FREEN View Post
                            Hi guys!

                            30 min chart. Same K value - still not parallel. What did I miss? //FREEN


                            // highray
                            double highestprice = MAX(Highs[0], lookback)[0];
                            int highestbar = HighestBar(Highs[0], lookback);
                            double hprice = (Kvalue * -CurrentBar) + highestprice;
                            DrawRay(
                            "Highray", true, CurrentBar, hprice, highestbar, highestprice, Color.Gray, DashStyle.Dash, 1);



                            // lowray
                            double lowestprice = MIN(Lows[0], lookback)[0];
                            int lowestbar = LowestBar(Lows[0], lookback);
                            double lprice = (Kvalue * -CurrentBar) + lowestprice;
                            DrawRay(
                            "Lowray", true, CurrentBar, lprice, lowestbar, lowestprice, Color.Gray, DashStyle.Dash, 1);
                            I do not see why you expect them to be parallel. The only time that they will be parallel is if your highestbar is also your lowestbar, or if Kvalue == 0. Otherwise the anchor points do not form a parallelogram, so the line joining the upper corners will not be parallel to the line joining the lower corners. i.e., though the vertical distance between corresponding anchor points is the same, the horizontal distances will generally be different, so the lines will have different gradients.

                            Comment


                              #15
                              Thanks for your reply koganam,

                              Not sure I got your point. The ancorpoints derives from [y = kx + m] in wich all lines in a x/y diagram are parallel. As you say, the horizontal distances (the x value) will vary. But that won´t affect the gradient of the rays given the same k value.

                              As stated in my comment #11 even one line behaves erratically when looking in different zooms and time frames. That makes me think the calculations done are right, but the chart drawing behaves strangely.

                              Kindly, Fredrik
                              Last edited by FREEN; 07-28-2011, 04:29 AM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by junkone, Today, 11:37 AM
                              2 responses
                              12 views
                              0 likes
                              Last Post junkone
                              by junkone
                               
                              Started by frankthearm, Yesterday, 09:08 AM
                              12 responses
                              43 views
                              0 likes
                              Last Post NinjaTrader_Clayton  
                              Started by quantismo, 04-17-2024, 05:13 PM
                              5 responses
                              35 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by proptrade13, Today, 11:06 AM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_Clayton  
                              Started by love2code2trade, 04-17-2024, 01:45 PM
                              4 responses
                              35 views
                              0 likes
                              Last Post love2code2trade  
                              Working...
                              X