• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Drawing rays from a dataseries

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

    Drawing rays from a dataseries

    Hi,

    I'm trying to draw rays from a dataseries where each variable in the dataseries is a pivot point. A ray is drawn when the left pivot point is greater than the right pivot point. There can be multiple rays drawn. I also would like the indicator to know when a price breaks above a ray.

    Could someone please help me with this? Is there a maximum number of rays that can be drawn in a chart?

    Thanks in advance

    Kay Wai

    #2
    Hello Kay,

    There is no limit imposed by NinjaTrader to the amount of drawing objects that can be drawn. This are saved in memory and do require cpu processing to render. The maximum amount of drawn objects will depend on your local computers memory and cpu resources.

    You can call the pivots indicator on each bar.

    Print(Pivots(NinjaTrader.Data.PivotRange.Daily, NinjaTrader.Data.HLCCalculationMode.DailyBars, 0, 0, 0, 20).PP[0]);

    Print(Pivots(NinjaTrader.Data.PivotRange.Daily, NinjaTrader.Data.HLCCalculationMode.DailyBars, 0, 0, 0, 20).R3[0]);

    Print(Pivots(NinjaTrader.Data.PivotRange.Daily, NinjaTrader.Data.HLCCalculationMode.DailyBars, 0, 0, 0, 20).S3[0]);

    I am uncertain about the logic you are wanting. You can always save an indicator value to a variable and check to see if the current value of the indicator is greater, less than , equal to the saved variable.

    double s3 = Pivots(NinjaTrader.Data.PivotRange.Daily, NinjaTrader.Data.HLCCalculationMode.DailyBars, 0, 0, 0, 20).S3[0];

    if (s3 > Pivots(NinjaTrader.Data.PivotRange.Daily, NinjaTrader.Data.HLCCalculationMode.DailyBars, 0, 0, 0, 20).S3[0])
    {
    // execute code
    }
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,
      Apologies for not making myself clearer. Please see attached chart.

      The green squares are known as pivot points and each point is already stored in a dataseries.

      I've drawn a few examples of what I'm trying to achieve, ignoring the purple squares. As long as a pivot point value is higher than the value of a pivot point to its right, I would like to draw a ray connecting those 2 points.

      I'd also like to code a bool to alert whenever there is a cross from below the ray.

      Hope it is clearer now. Please assist. Thanking you in advance.

      Regards

      Kay Wai
      Attached Files

      Comment


        #4
        Hello Kay,

        The green and magenta markers shown on the chart in your post are not made by the Pivots indicator.

        This is instead created by a 3rd party indicator that you have imported into NinjaTrader.
        I
        if that indicator has created a dataseries and this is public, you can call that dataseries like it is a plot. I do not have the exact code needed because I do not have this indicator.

        But the general usage would be similar to CustomIndicatorName().CustomDataSeriesName[0].

        Then use this for drawing the ray.

        For example if the dataseries is synced with the primary series in the script and there is a value for every bar and you want to draw a ray from the dataseries 10 bars ago to the current bar's close.

        DrawRay("myRay", 10, CustomIndicatorName().CustomDataSeriesName[10], 0, Close[0], Color.Blue);

        http://ninjatrader.com/support/helpG...t7/drawray.htm

        As far as determining when there is a dot drawn, this would depend on what is made public by the script and how the information is stored. Is there a value in the data series that is being checked in a condition causing the small squares to be drawn? If so, you can loop through the dataseries in your script and look for that value as well.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi Chelsea,

          I was thinking along the lines of a loop but have no idea how to go about it. The indicator has 2 sets of dataseries, one for the green squares and the other for the magenta squares as I would like to treat them separately. Let's just focus on the green squares dataseries.

          The trouble I'm facing with the logic is:-
          1) How do I draw rays through each green square where the green square to the left of it is greater than it?
          2) How to know when there is a "crossbelow" for each ray?

          Regards

          Kay Wai

          Comment


            #6
            Hi Kay,

            As an example, lets say that the dataseries holds a 1 when there is a dot and a 0 when there is no dot.

            If the current bar is drawing a dot, loop backwards until you find the previous dot. Check to see if the high of that bar is greater than the high of the current bar.

            if (CustomIndicatorName().GreenDataSeries[0] == 1)
            {
            for (int i = 0; i < CurrentBar - 1; i++)
            {
            if (CustomIndicatorName().GreenDataSeries[i] == 1 && High[i] > High[0])
            {
            DrawRay("myRay", i, High[i], 0, Close[0], Color.Blue);
            break;
            }
            }

            This would detect a green bar on the current bar, loop backwards through the bars until it find the previous green bar. Then it compares the high of that bar to the high of the current bar (the high is where the green dot is drawn from the screenshot). If the high of the bar with the previous green dot is greater than the high of the current bar it draws a ray from the previous green dot to the current close.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Thx Chelsea! Lemme try it out!

              Comment


                #8
                Chelsea! Help!

                Not sure where the problem is but this is all of the code. When I try to add your code, I'm not getting any rays around the CurrentBar.

                There also appear to be some zeroes in the dataseries which also be part of the problem.


                Code:
                 if (CurrentBar < 3) return;
                 
                 if (Math.Min(Close[2],Low[1])<Math.Min(Close[1],Low[0]) && Math.Min(Close[2],Low[1])<Math.Min(Close[3],Low[2]))
                 {
                 DemandPoint.Set(Math.Min(Close[2],Low[1]));
                 DrawSquare("DP1"+CurrentBar, true, 1, Math.Min(Close[2],Low[1]), Color.Magenta);
                 }
                 if (Math.Max(Close[2],High[1])>Math.Max(Close[1],High[0]) && Math.Max(Close[2],High[1])>Math.Max(Close[3],High[2]))
                 {
                 SupplyPoint.Set(Math.Max(Close[2],High[1]));
                 DrawSquare("SP1"+CurrentBar, true, 1, Math.Max(Close[2],High[1]), Color.Green);
                 }
                 
                Regards

                Kay Wai
                Last edited by kaywai; 01-03-2016, 08:12 AM.

                Comment


                  #9
                  Hi Chelsea,

                  I've tried changing the dataset from dataseries to List but I keep getting this error:

                  Error on calling 'OnBarUpdate' method for indicator 'TDLINESV2' on bar 10: Object reference not set to an instance of an object.

                  The code is below:

                  Code:
                  
                   if (CurrentBar < 10) return;
                   
                   if (Math.Min(Close[2],Low[1])<Math.Min(Close[1],Low[0]) && Math.Min(Close[2],Low[1])<Math.Min(Close[3],Low[2]))
                   {
                   //DemandPoint.Set(Math.Min(Close[2],Low[1]));
                   DemandPoint.Add(Math.Min(Close[2],Low[1]));
                   DrawSquare("DP1"+CurrentBar, true, 1, Math.Min(Close[2],Low[1]), Color.Magenta);
                   }
                   
                  Please help.

                  Kay Wai

                  Comment


                    #10
                    Originally posted by kaywai View Post
                    Hi Chelsea,

                    I've tried changing the dataset from dataseries to List but I keep getting this error:

                    Error on calling 'OnBarUpdate' method for indicator 'TDLINESV2' on bar 10: Object reference not set to an instance of an object.

                    The code is below:

                    Code:
                    
                     if (CurrentBar < 10) return;
                     
                     if (Math.Min(Close[2],Low[1])<Math.Min(Close[1],Low[0]) && Math.Min(Close[2],Low[1])<Math.Min(Close[3],Low[2]))
                     {
                     //DemandPoint.Set(Math.Min(Close[2],Low[1]));
                     DemandPoint.Add(Math.Min(Close[2],Low[1]));
                     DrawSquare("DP1"+CurrentBar, true, 1, Math.Min(Close[2],Low[1]), Color.Magenta);
                     }
                     
                    Please help.

                    Kay Wai
                    How and where did you create and assign your list.

                    Comment


                      #11
                      In the variables section

                      Private List<double> DemandPoint = new List<double> ();

                      Comment


                        #12
                        Originally posted by kaywai View Post
                        In the variables section

                        Private List<double> DemandPoint = new List<double> ();
                        That looks straightforward enough. Have you brought the generics collection namespace into scope?

                        Comment


                          #13
                          Yes. In the namespace section...using system.collections.generic.

                          If it helps, i had no errors on compiling. The message showed in the output window.

                          Comment


                            #14
                            Originally posted by kaywai View Post
                            Yes. In the namespace section...using system.collections.generic.

                            If it helps, i had no errors on compiling. The message showed in the output window.
                            It sounds as if that is not where your problem may be after all. Time for some judicious "Print" statements to isolate the culprit?

                            Comment


                              #15
                              Any suggestions? It essentially only 1 line of code. which worked in a dataseries except for the zeroes which sent the code haywire when i tried to draw rays.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by jjanguda, 05-19-2015, 01:13 PM
                              15 responses
                              1,371 views
                              0 likes
                              Last Post Eric M.
                              by Eric M.
                               
                              Started by morrnel, Today, 01:13 PM
                              1 response
                              9 views
                              0 likes
                              Last Post NinjaTrader_Jim  
                              Started by babouin77, Today, 12:41 PM
                              7 responses
                              17 views
                              0 likes
                              Last Post NinjaTrader_Jim  
                              Started by punkiy2111, Today, 12:17 PM
                              1 response
                              9 views
                              0 likes
                              Last Post NinjaTrader_Tabor  
                              Started by GLFX005, Today, 11:22 AM
                              8 responses
                              38 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Working...
                              X