Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Pivot indicator shows zero in Ninjascript when DailyBars method used for priorDayHLC.

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

    Pivot indicator shows zero in Ninjascript when DailyBars method used for priorDayHLC.

    Hi, this question has popped up a few times before and unfortunately all the threads I read are not resolving it for me.
    I have the Pivots indicator running on a 5 min chart and it works fine. I like what I see on the chart.
    I noticed on the chart it calculates the values when the second bar starts to be drawn and not on the first, not sure why that is.
    In any event, I wanted to use the values of this indicator in Ninjascript strategy.

    This if from the online reference page for the indicator:

    if (Pivots(PivotRange.Daily, HLCCalculationMode.DailyBars, 0, 0, 0, 20).PP.ContainsValue(0))
    {

    // Prints the current pivot point value

    double value = Pivots(PivotRange.Daily, HLCCalculationMode.DailyBars, 0, 0, 0, 20).PP[0];
    Print("The current Pivots' pivot value is " + value.ToString());

    }


    When I use it without the IF block it produces zero.
    When I use it with the IF block it doesn't produce anything since it appears the block is not executed.
    BTW, I am using AMP CQG as a provider and my daily chart draws without a problem.

    I read many posts suggesting this indicator is not working well with DailyBars and to use CalcFromIntradayData method instead for priorDayHLC. On the chart I am using DailyBars which seems to be the default.
    I have tried that but the values I get are completely different from the values I get on the chart and are useless.

    So, why can't Ninjatrader provide a way to get the same values from an indicator in ninjascript strategy as the ones on a chart?
    I am running 7.0.1000.42

    I also read that the above limitations of the indicator would be resolved (this was on some old posts and wonder if that was ever completed).
    Wonder also if version 8 has the same problem.


    Thanks,
    -George

    Last edited by gg2NT; 12-26-2020, 09:10 AM.

    #2
    The only time I get non-zero values when using HLCCalculationMode.DailyBars is when I put the print statements under daily time frame as below..
    But the values for all are the same PP, R1, S1, etc..

    if (BarsInProgress == 2) //this is for daily time frame
    {
    Print(Pivots(PivotRange.Daily, HLCCalculationMode.DailyBars, 0, 0, 0, 20).R3[0].ToString());
    Print(Pivots(PivotRange.Daily, HLCCalculationMode.DailyBars, 0, 0, 0, 20).R2[0].ToString());
    Print(Pivots(PivotRange.Daily, HLCCalculationMode.DailyBars, 0, 0, 0, 20).R1[0].ToString());
    Print(Pivots(PivotRange.Daily, HLCCalculationMode.DailyBars, 0, 0, 0, 20).PP[0].ToString());
    Print(Pivots(PivotRange.Daily, HLCCalculationMode.DailyBars, 0, 0, 0, 20).S1[0].ToString());
    Print(Pivots(PivotRange.Daily, HLCCalculationMode.DailyBars, 0, 0, 0, 20).S2[0].ToString());
    Print(Pivots(PivotRange.Daily, HLCCalculationMode.DailyBars, 0, 0, 0, 20).S3[0].ToString());
    }

    I get different values for PP, R1, S1, etc. when I use HLCCalculationMode.CalcFromIntradayData under the 5 min time frame..
    But they are useless to me since they are not the same as the values the Pivots indicator shows on the 5 min chart..

    if (BarsInProgress == 0) //this is for the main, 5 min time frame
    {
    Print(Pivots(PivotRange.Daily, HLCCalculationMode.CalcFromIntradayData, 0, 0, 0, 20).R3[0].ToString());
    Print(Pivots(PivotRange.Daily, HLCCalculationMode.CalcFromIntradayData, 0, 0, 0, 20).R2[0].ToString());
    Print(Pivots(PivotRange.Daily, HLCCalculationMode.CalcFromIntradayData, 0, 0, 0, 20).R1[0].ToString());
    Print(Pivots(PivotRange.Daily, HLCCalculationMode.CalcFromIntradayData, 0, 0, 0, 20).PP[0].ToString());
    Print(Pivots(PivotRange.Daily, HLCCalculationMode.CalcFromIntradayData, 0, 0, 0, 20).S1[0].ToString());
    Print(Pivots(PivotRange.Daily, HLCCalculationMode.CalcFromIntradayData, 0, 0, 0, 20).S2[0].ToString());
    Print(Pivots(PivotRange.Daily, HLCCalculationMode.CalcFromIntradayData, 0, 0, 0, 20).S3[0].ToString());
    }

    Comment


      #3
      OK, made a bit of a progress.
      This link explains how Pivots are calculated to begin with.
      https://ninjatrader.com/support/foru...culated?t=4676
      So, the calculations on the chart are dependent on what is displayed on that chart in terms of start and end time.
      That is the case if you have picked CalcFromIntradayData mode.
      If you have picked DailyBars and your provider supplies that the start and end times on your chart shouldn't matter.
      But if your provider doesn't supply daily bars data you will fall back to CalcFromIntradayData even if you have selected DailyBars.

      OK, all above is true for the chart.
      Now, when I play with Ninjascript, how do I enforce session start and end times so that when I use CalcFromIntradayData mode the Pivots values will match with the values calculated on the chart?
      Question to myself of course.. but if anybody knows the answer I won't look the other way

      Comment


        #4
        OK, let me wrap up my monologue.
        This turned out to be easier that I originally thought.

        So, if I wanted to calculate Pivots that take into account the specific session beginning and end I use the UserDefinedValues method and fill in the values for CHL with the relevant values from the PriorDayOHLC indicator.. Below I am printing the PP value calculated this way.

        Print(Pivots(PivotRange.Daily, HLCCalculationMode.UserDefinedValues, PriorDayOHLC().PriorClose[0], PriorDayOHLC().PriorHigh[0], PriorDayOHLC().PriorLow[0], 10).PP[0].ToString());

        If I wanted to calculate based on the daily chart values I refer to these values instead (they are the second time frame I added to my script hence the [2]).

        Print(Pivots(PivotRange.Daily, HLCCalculationMode.UserDefinedValues, Closes[2][0], Highs[2][0], Lows[2][0], 10).PP[0].ToString());

        I added the daily time frame in the Initialize() block as follows:

        Add(PeriodType.Day, 1);

        Phew, that was a good NT refresh for me.
        BTW, this was all tried on NT 7.

        Comment


          #5
          Hello gg2NT,

          One note, if you want to use daily bars as the input for the Pivots, then the PivotRangeType needs to be set to either Weekly or Monthly.

          The Daily PivotRangeType would be used on intra-day bars like minute, etc,

          Attached is an example.
          Attached Files
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Chelsea,

            Thanks very much for this! That is a very good insight which I didn't consider.

            Regards,
            -George

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Haiasi, 04-25-2024, 06:53 PM
            2 responses
            16 views
            0 likes
            Last Post Massinisa  
            Started by Creamers, Today, 05:32 AM
            0 responses
            4 views
            0 likes
            Last Post Creamers  
            Started by Segwin, 05-07-2018, 02:15 PM
            12 responses
            1,786 views
            0 likes
            Last Post Leafcutter  
            Started by poplagelu, Today, 05:00 AM
            0 responses
            3 views
            0 likes
            Last Post poplagelu  
            Started by fx.practic, 10-15-2013, 12:53 AM
            5 responses
            5,407 views
            0 likes
            Last Post Bidder
            by Bidder
             
            Working...
            X