Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy trading off yesterday Pivots

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

    Strategy trading off yesterday Pivots

    I have written a strategy to trade of pivot points and for some reason its trading off the previous days levels,

    In the code it is calculating the pivots before making any entry decision so I dont quite understand how this is happening. Here is the calculation and entry logic,

    protected override void OnBarUpdate()
    {
    if(CurrentBars[1] <= 1)
    return;

    if(CurrentBars[1] == null)
    return;

    if(BarsInProgress != 0)
    return;

    // If there is a new session add one to session count.
    if(Bars.SessionBreak)
    sessionCount++;

    #region Calculate and Draw Pivots

    // Calculate Pivot Points

    pp = Math.Round((Highs[1][1] + Lows[1][1] + Closes[1][1])/3,2);
    r1 = Math.Round((2 * pp) - Lows[1][1],2);
    s1 = Math.Round((2 * pp) - Highs[1][1],2);
    r2 = Math.Round(pp + (Highs[1][1] - Lows[1][1]),2);
    s2 = Math.Round(pp - (Highs[1][1] - Lows[1][1]),2);
    r3 = Math.Round(r1 + (Highs[1][1] - Lows[1][1]),2);
    s3 = Math.Round(s1 - (Highs[1][1] - Lows[1][1]),2);

    // Draw Pivot Points



    DrawLine("r3" + sessionCount, false, Bars.BarsSinceSession, r3, 0, r3 ,Color.Crimson,DashStyle.Dash,2);
    DrawLine("r2" + sessionCount, false, Bars.BarsSinceSession, r2, 0, r2 ,Color.Crimson,DashStyle.Dash,2);
    DrawLine("r1" + sessionCount, false, Bars.BarsSinceSession, r1, 0, r1 ,Color.Crimson,DashStyle.Dash,2);
    DrawLine("pp" + sessionCount, false, Bars.BarsSinceSession, pp, 0, pp ,Color.Black,DashStyle.Dash,2);
    DrawLine("s1" + sessionCount, false, Bars.BarsSinceSession, s1, 0, s1 ,Color.DarkGreen,DashStyle.Dash,2);
    DrawLine("s2" + sessionCount, false, Bars.BarsSinceSession, s2, 0, s2 ,Color.DarkGreen,DashStyle.Dash,2);
    DrawLine("s3" + sessionCount, false, Bars.BarsSinceSession, s3, 0, s3 ,Color.DarkGreen,DashStyle.Dash,2);

    // Draw Lables

    DrawText("r3l" + sessionCount, "R3 " + r3, 0, r3 + TickSize*1, Color.Crimson);
    DrawText("r2l" + sessionCount, "R2 " + r2, 0, r2 + TickSize*1, Color.Crimson);
    DrawText("r1l" + sessionCount, "R1 " + r1, 0, r1 + TickSize*1, Color.Crimson);
    DrawText("pp1" + sessionCount, "pp " + pp, 0, pp + TickSize*1, Color.Black);
    DrawText("s1l" + sessionCount, "S1 " + s1, 0, s1 + TickSize*1, Color.DarkGreen);
    DrawText("s2l" + sessionCount, "S2 " + s2, 0, s2 + TickSize*1, Color.DarkGreen);
    DrawText("s3l" + sessionCount, "S3 " + s3, 0, s3 + TickSize*1, Color.DarkGreen);


    #endregion


    // Entry Logic
    Print (ToTime(Time[0]));
    if((ToTime(Time[0])) == 80000);
    {
    if(EMA(fEMA)[0]>EMA(sEMA)[0]) // LONG ENTRYS
    {
    if(Open[0] > pp && Open[0] < r1)
    {
    longEntryPP = EnterLongLimit(0,true, 1,pp + entryAllowance * TickSize , "Long Entry PP");
    }

    else if(Open[0] > r1 && Open[0] < r2)
    {
    longEntryR1 = EnterLongLimit(0,true, 1,r1 + entryAllowance * TickSize, "Long Entry R1");
    }

    else if(Open[0] > r2 && Open[0] < r3)
    {
    longEntryR2 = EnterLongLimit(0,true, 1,r2 + entryAllowance * TickSize, "Long Entry R2");
    }

    else if(Open[0] > s1 && Open[0] < pp)
    {
    longEntryS1 = EnterLongLimit(0,true, 1,s1 + entryAllowance * TickSize, "Long Entry S1");
    }

    else if(Open[0] > s2 && Open[0] < s1)
    {
    longEntryS2 = EnterLongLimit(0,true, 1,s2 + entryAllowance * TickSize, "Long Entry S2");
    }

    else if(Open[0] > s3 && Open[0] < s2)
    {
    longEntryS3 = EnterLongLimit(0,true, 1,s3 + entryAllowance * TickSize, "Long Entry S3");
    }
    }

    if(EMA(fEMA)[0]<EMA(sEMA)[0]) // SHORT ENTRYS
    {
    if(Open[0] > pp && Open[0] < r1)
    {
    shortEntryR1 = EnterShortLimit(0,true, 1,r1 - entryAllowance * TickSize, "Short Entry R1");
    }

    else if(Open[0] > r1 && Open[0] < r2)
    {
    shortEntryR2 = EnterShortLimit(0,true, 1,r2 - entryAllowance * TickSize, "Short Entry R2");
    }

    else if(Open[0] > r2 && Open[0] < r3)
    {
    shortEntryR3 = EnterShortLimit(0,true, 1,r3 - entryAllowance * TickSize, "Short Entry R3");
    }

    else if(Open[0] > s1 && Open[0] < pp)
    {
    shortEntryPP = EnterShortLimit(0,true, 1,pp - entryAllowance * TickSize, "Short Entry PP");
    }

    else if(Open[0] > s2 && Open[0] < s1)
    {
    shortEntryS1 = EnterShortLimit(0,true, 1,s1 - entryAllowance * TickSize, "Short Entry S1");
    }

    else if(Open[0] > s3 && Open[0] < s2)
    {
    shortEntryS2 = EnterShortLimit(0,true, 1,s2 - entryAllowance * TickSize, "Short Entry S2");
    }
    }

    }
    }

    #2
    Hello GKonheiser,

    Thank you for your post.

    The following code is looking to one bar back:
    Code:
    pp = Math.Round((Highs[1][1] + Lows[1][1] + Closes[1][1])/3,2);
    r1 = Math.Round((2 * pp) - Lows[1][1],2);
    s1 = Math.Round((2 * pp) - Highs[1][1],2);
    r2 = Math.Round(pp + (Highs[1][1] - Lows[1][1]),2);
    s2 = Math.Round(pp - (Highs[1][1] - Lows[1][1]),2);
    r3 = Math.Round(r1 + (Highs[1][1] - Lows[1][1]),2);
    s3 = Math.Round(s1 - (Highs[1][1] - Lows[1][1]),2);
    Is the strategy ran on daily bars?

    I look forward to your response.

    Comment


      #3
      Hi

      Yup that is looking one bar back on Daily bars( Add(PeriodType.Day, 1); ). As I assumed that that Bars[1][0] would be the day bar forming during the day. BUT i am running it on 5 min charts, I added the day bars to the script.

      The Pivots are displaying correctly just not trading correctly, and its the same double????
      Last edited by GKonheiser; 10-28-2013, 09:41 AM.

      Comment


        #4
        Hello GKonheiser,

        Thank you for your response.

        Is the desired effect to base trades off of the previous day's Pivots or the current day's Pivots?

        I look forward to your response.

        Comment


          #5
          desired effects is it trades off today's pivots which are calculated from yesterdays Day Bar

          Comment


            #6
            Hello GKonheiser,

            Thank you for your response.

            Are you using CalculateOnBarClose = true?

            Are the DrawLine()s placed at the correct levels for the current day? Or are these also for the previous day?

            I look forward to your response.

            Comment


              #7
              CalculateOnBarClose = true yes

              The DrawLines are in the correct position, I have attached a screen shot where you can see an entry based on the previous days pivots.
              Attached Files

              Comment


                #8
                Hello GKonheiser,

                Thank you for your response.

                This can be seen when there is a difference in the Session Template applied for the primary series and the Daily bar series from your data feed provider uses another Session.

                What Session Template is applied to the chart? You can check this by right clicking in your chart > select Data Series > Session Template?

                Who do you connect to for data? This is displayed in green at the bottom left hand corner of the NinjaTrader Control Center.

                What instrument is applied to the chart?

                I look forward to your response.

                Comment


                  #9
                  The data is all historical data that I have mostly from kinetick(some I imported myself from a different source), saying that when i am testing the strategies I do connect to end of day Kinetick, but wouldn't it take my historical data anyway?

                  Im sure that the contract im testing on was from Kinetick.

                  The instrument on the chart is FGBL 03-13. and the session template is (use instrument settings).

                  Comment


                    #10
                    Hello,

                    Thank you for your response.

                    The Kinetick EOD will not provide today's Daily bar until after the close. What is the primary bar series for the strategy? And who do you connect to for real-time data?

                    Comment


                      #11
                      Originally posted by NinjaTrader_PatrickH View Post
                      Hello,

                      Thank you for your response.

                      The Kinetick EOD will not provide today's Daily bar until after the close. What is the primary bar series for the strategy? And who do you connect to for real-time data?
                      The primary data series is 5 min bars.

                      Real time provider is Kinetick but that is not on this machine. I am testing this strategy with historical data on a different PC

                      i don't need today daily bar as today's pivots are calculated from yesterdays day bar, or am i missing something?

                      Comment


                        #12
                        Hello GKonheiser,

                        Thank you for your response.

                        If it is all historical data then it should not matter here. However, it appears the S1 value is still yesterday's value when the order is placed.

                        Can you add a Print() line to when the order is placed? Something like Print("S1 placed at " + Time[0] + " S1 Pivot value is " + s1);

                        This should give you a better idea if the s1 Pivot value just hasn't changed yet.

                        If you open a daily chart of the FGBL 03-13 (make sure the end date of the chart is within the 03-13 contract time period) and then a 1440 minute chart for the same end date do the Open and Close prices match?

                        Comment


                          #13
                          Morning Patrick,

                          With regards to the 1440 min chart and the day chart, the Open, High & Low are the same but the close is different which is understandable due to settlement price.

                          I included some print statements in my code and found some very strange issues.

                          It is drawing the pivots absolutely correctly based on the previous days bar.

                          However it is tradeing off Yesterday Pivots calculated from 2 days ago. I have attached a screen shot where you can see the pivots displayed correctly on the chart for the 21st Feb but if you look at the output window for the 21st the levels and pivots are based on the day bar 2 days ago??

                          Its very strange as it is using the same double for both purposes???

                          I have attached the code as well.
                          Attached Files

                          Comment


                            #14
                            Hello GKonheiser,

                            Thank you for your response.

                            The results are actually correct. In my testing I find that your code plots yesterday's values for today (the use of Lows[1][1] for example) until the next day arrives and then plots those values.

                            So if today is the third, the values plotted and positions taken are based on yesterday's values. Then on the fourth the third's values change to it's values for the day. If you want today's values today then use Closes[1][0] and Lows[1][0].

                            Please let me know if I may be of further assistance.

                            Comment


                              #15
                              Hi Patrick.

                              What I'm not getting and where the inconsistency is is that it is piloting the pivots correctly based on yesterdays day bar, so if we take just the pp from the code,

                              pp = Math.Round((Highs[1][1] + Lows[1][1] + Closes[1][1])/3,2);

                              and then draw a line based on that,

                              DrawLine("pp" + sessionCount, false, Bars.BarsSinceSession, pp, 0, pp ,Color.Black,DashStyle.Dash,2);

                              So when I look at my chart for say the 5th March I see the pivot line at 144.55

                              which is what I want and is correct when I manually calculate the pivots from the bar of 4th March.
                              However when I look at the Print results from the 5th it has a different pp value of 145.34.

                              How can one be correct and one not if they are based on the same calculation.

                              If I just change the calculation to use ie Highs[1][0] , then the lines will not be plotted correctly and logically speaking it should be using the previous days values so ie Highs[1][1].

                              or am i missing something?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              656 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              371 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              109 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              574 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              579 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X