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

Pivots calculations

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

    Pivots calculations

    I am having a boatload of trouble solving this calculation. The Ninja team has been very helpful but so far, I am still stumped. I am reaching out to the forum participants to see if there is someone that has a better idea to completing this math.

    To start with, I found this formula for Pivot points on Investopdia and is from Tom Mark at Market Studies, Inc. His chart is located at the bottom of this message.

    So I created formulas to try and draw this onto a NT chart but I end up with pivot points that are WAY off the scale. No matter how many times I comb through this code, I cannot find what is causing the lines to be so far off. Here is the code for reference.

    //PIVOT POINTS BASED ON RECENT MARKET CONDITIONS
    //For Decling market (today's open is lower than yesterday's open)

    if ((PriorDayOHLC(BarsArray[1]).PriorOpen[0]) > (Opens[1][0]))

    //Upper Pivot Point = sum of yesterday's (((high + close)+(low*2))/2)-low)
    PivotUp.Set((((((PriorDayOHLC(BarsArray[1]).PriorHigh[0]) +(PriorDayOHLC(BarsArray[1]).PriorClose[0])) + ((PriorDayOHLC(BarsArray[1]) .PriorLow[0]) * 2))) /2) - (PriorDayOHLC(BarsArray[1]) .PriorLow[0]));
    //Lower Pivot Point = sum of yesterday's (((high + close)+(low*2))/2)-high)
    PivotDown.Set ((((((PriorDayOHLC(BarsArray[1]).PriorHigh[0]) +(PriorDayOHLC(BarsArray[1]).PriorClose[0]) + (PriorDayOHLC(BarsArray[1]) .PriorLow[0]) * 2))) /2) - (PriorDayOHLC(BarsArray[1]) .PriorHigh[0]));

    //For Inclining market (today's open is higher than yesterday's open)

    if (PriorDayOHLC(BarsArray[1]).PriorOpen[0] < Opens[1][0])

    //Upper Pivot Point = sum of yesterday's (((low + close)+(high*2))/2)-low)
    PivotUp.Set ((((((PriorDayOHLC(BarsArray[1]).PriorLow[0]) +(PriorDayOHLC(BarsArray[1]).PriorClose[0]) + (PriorDayOHLC(BarsArray[1]).PriorHigh[0]) * 2))) /2) - (PriorDayOHLC(BarsArray[1]) .PriorLow[0]));
    //Lower Pivot Point = sum of yesterday's (((low + close)+(high*2))/2)-high)
    PivotDown.Set ((((((PriorDayOHLC(BarsArray[1]).PriorLow[0]) +(PriorDayOHLC(BarsArray[1]).PriorClose[0]) + (PriorDayOHLC(BarsArray[1]).PriorHigh[0]) * 2))) /2) - (PriorDayOHLC(BarsArray[1]) .PriorHigh[0]));

    //For Flat Market (today's open is even with yesterday's open)

    if (PriorDayOHLC(BarsArray[1]).PriorOpen[0] == CurrentDayOHL(BarsArray[1]) .CurrentOpen[0])

    //Upper Pivot Point = sum of yesterday's (((high + low)+(close*2))/2)-low)
    PivotUp.Set ((((((PriorDayOHLC(BarsArray[1]).PriorHigh[0]) +(PriorDayOHLC(BarsArray[1]).PriorLow[0]) + (PriorDayOHLC(BarsArray[1]).PriorClose[0]) * 2))) /2) - (PriorDayOHLC(BarsArray[1]).PriorLow[0]));
    //Lower Pivot Point = sum of yesterday's (((high + low)+(close*2))/2)-high)
    PivotDown.Set ((((((PriorDayOHLC(BarsArray[1]).PriorHigh[0]) +(PriorDayOHLC(BarsArray[1]).PriorLow[0]) + (PriorDayOHLC(BarsArray[1]).PriorClose[0]) * 2))) /2) - (PriorDayOHLC(BarsArray[1]) .PriorHigh[0]));



    The rest of my indicator works fine. Any help at all is much appreciated.

    Best regards,

    Dolfan
    Attached Files
    Last edited by Dolfan; 08-17-2016, 12:50 AM. Reason: Picture didn't load

    #2
    Hello Dolfan,

    Thank you for your post.

    Can you detail what you are comparing the values from NinjaTrader to? Do you have a working example in another platform or on a website?

    Comment


      #3
      Patrick,

      Based on yesterday's OHLC bar (1440 minute) for CL 09-16, I have an open of 45.50, a high of 46.73, low of 45.34 and a close of 46.41. Today's open is 46.37. With the open today being higher then yesterday we see an inclining market so the math would be thus;

      Since starting this post I have made a correction to my math. Simply put, I am 'blinded' by the myriad of parenthesis and brackets and the following corrects the math to fit what I already have in my spreadsheets working for me. Still, my chart paints the lines in outer space and I need to find the error in the syntax.

      //Upper Pivot Point = sum of yesterday's ((low + close)+(high*2))/2-low
      ((45.34+46.41)+(46.73*2))/2-45.34= Upper Pivot Point of 47.265
      //Lower Pivot Point = sum of yesterday's ((low + close)+(high*2))/2-high
      ((45.34+46.41)+(46.73*2))/2-46.73= Lower Pivot Point of 45.875

      Here is a current oil chart with my support and resistance lines correctly located and my pivot lines somewhere around Jupiter. http://screencast.com/t/WlynSWzGBMDN

      I have not seen this done on another website and you may note that I have taken some liberties with his formula. For example while Tom measures yesterday's close with today's open (a number I feel will be very close together) I prefer to measure yesterday's open to today's open. When I can get the lines down out of outer space I can test the merits of that decision.

      Thanks for your interest.

      Best regards,

      Dolfan

      PS Should I be able to print the value to the Output window by placing Print in front of any of the .Set commands? ex.

      Print ((((PriorDayOHLC(BarsArray[1]).PriorLow[0]) +(PriorDayOHLC(BarsArray[1]).PriorClose[0]) + (PriorDayOHLC(BarsArray[1]).PriorHigh[0]) * 2))) /2 - (PriorDayOHLC(BarsArray[1]) .PriorLow[0]);
      Last edited by Dolfan; 08-17-2016, 10:17 AM.

      Comment


        #4
        Dolfan,

        I created the indicator using the following code and I see the values as shown in the attached screenshot.
        Code:
            public class DolfanPivots : Indicator
            {
                private double x = double.MinValue;
        		
                protected override void Initialize()
                {
        			Add(new Plot(Color.Blue, "High"));
        			Add(new Plot(Color.Red, "Low"));
                    Overlay				= true;
                }
        
                protected override void OnBarUpdate()
                {
                    if (PriorDayOHLC().PriorClose[0] < PriorDayOHLC().PriorOpen[0])
        			{
        				x = PriorDayOHLC().PriorHigh[0] + PriorDayOHLC().PriorLow[0] + PriorDayOHLC().PriorClose[0] + PriorDayOHLC().PriorLow[0];
        			}
        			else if (PriorDayOHLC().PriorClose[0] > PriorDayOHLC().PriorOpen[0])
        			{
        				x = PriorDayOHLC().PriorHigh[0] + PriorDayOHLC().PriorLow[0] + PriorDayOHLC().PriorClose[0] + PriorDayOHLC().PriorHigh[0];
        			}
        			else
        			{
        				x = PriorDayOHLC().PriorHigh[0] + PriorDayOHLC().PriorLow[0] + PriorDayOHLC().PriorClose[0] + PriorDayOHLC().PriorClose[0];
        			}
        			
        			Values[0][0] = x/2 - PriorDayOHLC().PriorLow[0];
        			Values[1][0] = x/2 - PriorDayOHLC().PriorHigh[0];
                }
            }
        Attached Files

        Comment


          #5
          ARRRRGGGGG!!!! Just what I need, another complete rewrite! :-) Actually I do need this exercise. Thanks! I'll take a look and see how I can apply it to my current indicator. May just have to create a separate indicator for pivots alone.

          Can you take a look at my PS question about printing the values? I have not had trouble printing values in the past so this leads me to believe there is a syntax error as well.

          Also, this journey began with me cannibalizing a couple of indicators to create one with support and resistance lines, and now adding pivot points. To clean things up I went to the Indicator Wizard and started a new indicator which greatly cleaned up my coding. I then cut and pasted the syntax from the S/R coding that is known to work, added in the pivot syntax, adjusted the 'declarations', 'variables' and 'properties' regions to account for the syntax. I went to compile and it returns many errors, none of which I encountered earlier when creating this code. I made sure that the 'declarations', 'variables' and 'properties' regions matched the indicator that is working and everything in OnBarUpdate is cut and pasted. But the OnBarUpdate area is chock full of errors, most of which are "Class Member Declaration" errors or some error associated with a bracket, number in a bracket, +-= sign, or some other part that was not found to be in error in the other indicator. I have checked and rechecked the declarations area and I find nothing that does not match. Any thoughts?

          Thanks once again for your help.

          Best regards,

          Dolfan

          Comment


            #6
            PS Should I be able to print the value to the Output window by placing Print in front of any of the .Set commands?
            Yes, you should be able to print the values before setting them to the plot.

            For the errors I would need the full file to test. Please attach the .cs file version found under Documents\NinjaTrader 7\bin\Custom\Indicator.

            Comment


              #7
              Patrick,

              I appreciate your help but I would rather not abuse it. Let me continue to pound away it. I REALLY appreciate the streamlined effort you have already provided. Thanks!

              Best regards,

              Dolfan

              Comment


                #8
                Patrick,

                Trying to understnad what "
                double.MinValue" means. Hit F1 and did a search but it returned nothing. Please tell me about this command. Thanks!

                Best regards,

                Dolfan

                Comment


                  #9
                  OK, I tried to create a new indicator through the wizard and used the name you have here in the syntax, then cut an pasted your syntax into the file. It compiled just fine but when I go to a chart and tried to load it, it does not appear in the list. The indicator I have tried to load with all the errors also does not show anywhere on my list. What have I done? Is it terminal? Will I have to put her down?

                  Dolfan

                  Comment


                    #10
                    Dolfan,

                    double.MinValue means the minimum value a double could be. I used it as the initial value before x was set, that is all.

                    For the indicator I would need to see the full code to know what is occurring. Please attach the .cs file version found under Documents\NinjaTrader 7\bin\Custom\Indicator.

                    Comment


                      #11
                      File Sent

                      Dolfan

                      Comment


                        #12
                        Received a message that said attachment not sent, let me know if this is true.

                        Dolfan

                        Comment


                          #13
                          Dolfan,

                          I got the attachment.

                          Comment


                            #14
                            Interesting that I was successful at converting this over to NT8 WOOHOO, but it doesn't paint any lines. Additionally, I have the settings set to display in data box but there is nothing there as well. It compiled just fine so where the heck is it?

                            Dolfan

                            Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.

                            Comment


                              #15
                              Hello Dolfan,

                              Thank you for your response.

                              Your indicator is working in my NinjaTrader 7 installation. I will contact you in email to schedule a support call.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Max238, Today, 01:28 AM
                              4 responses
                              36 views
                              0 likes
                              Last Post Max238
                              by Max238
                               
                              Started by r68cervera, Today, 05:29 AM
                              1 response
                              7 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by geddyisodin, Today, 05:20 AM
                              1 response
                              11 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by timko, Today, 06:45 AM
                              2 responses
                              14 views
                              0 likes
                              Last Post NinjaTrader_ChristopherJ  
                              Started by habeebft, Today, 07:27 AM
                              0 responses
                              7 views
                              0 likes
                              Last Post habeebft  
                              Working...
                              X