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

Using ZigZag indicator to determine pivot points

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

    Using ZigZag indicator to determine pivot points

    Hello,

    I want to incorporate Pivot Point stop into my strategy. To achieve this, I would be using ZigZag indicator and 4 variables:
    1) Low_Pivot_Current - Current value of Pivot Low, i.e., whenever ZigZag stops going down and turns back up (does "V"), I would update it., I can think or such a calculation: (ZigZag[0]>ZigZag[1] && ZigZag[1]<ZigZag[2]), But I improvised with ZigZag name usage, It may be different and have additional parameters.
    2) Low_Pivot_Previous - Previous value of Pivot Low, i.e. whenever Low_Pivot_Current is updated, previous value of Low_Pivot_Current becomes current value of Low_Pivot_Previous.
    3) High_Pivot_Current - Current value of Pivot High, i.e., whenever ZigZag stops going up and turns back down (does "/"), I would update it., I can think or such a calculation: (ZigZag[0]<ZigZag[1] && ZigZag[1]>ZigZag[2]), But I improvised with ZigZag name usage, It may be different and have additional parameters.
    4) High_Pivot_Previous - Previous value of Pivot High, i.e. whenever High_Pivot_Current is updated, previous value of High_Pivot_Current becomes current value of High_Pivot_Previous.

    I use such settings for ZigZag:
    Deviation type: Points
    Deviation value: 2
    Use high low: True

    So how can I make 1), 2), 3), 4) variable formulas?

    And then my stop formula would be for longs: if (Close[0] <= Low_Pivot_Current, then ExitLong()
    For shorts: If (Close[0] >= High_Pivot_Current, then ExitShort()

    #2
    Hello UltraNIX,

    Are you asking for help with logic or help with syntax?
    Are you asking how to declare a method?
    What do you mean by variable formulas?

    Below is a link to a forum post with helpful information about getting started with NinjaScript and C#.


    Are you asking how to call the ZigZag indicator?

    Below is a link to the help guide.


    For example:
    Code:
    if (High[ZigZag(DeviationType.Points, 2, true).HighBar(0, 1, 100)] > High[ZigZag(DeviationType.Points, 2, true).HighBar(0, 1, 100) + 1] && High[ZigZag(DeviationType.Points, 2, true).HighBar(0, 1, 100) + 1] < High[ZigZag(DeviationType.Points, 2, true).HighBar(0, 1, 100)] + 2])
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I used prints and something must be off.

      Code:
      2020-06-29 20:58:06 | ZigZag High[0]: 3039,5 | ZigZag High[1]: 3038,25 | ZigZag High[2]: 3036,5
      2020-06-29 21:00:59 | ZigZag High[0]: 3039,5 | ZigZag High[1]: 3038,25 | ZigZag High[2]: 3036,5
      2020-06-29 21:04:26 | ZigZag High[0]: 3039,5 | ZigZag High[1]: 3038,25 | ZigZag High[2]: 3036,5
      2020-06-29 21:05:56 | ZigZag High[0]: 3037,75 | ZigZag High[1]: 3037 | ZigZag High[2]: 3037
      2020-06-29 21:07:54 | ZigZag High[0]: 3037,75 | ZigZag High[1]: 3037 | ZigZag High[2]: 3037
      2020-06-29 21:11:21 | ZigZag High[0]: 3037,75 | ZigZag High[1]: 3037 | ZigZag High[2]: 3037
      2020-06-29 21:15:47 | ZigZag High[0]: 3037,75 | ZigZag High[1]: 3037 | ZigZag High[2]: 3037
      If code worked correctly, High[0] of 2020-06-29 21:04:26 bar (3039,5) would be High[1] of next bar, i.e. 2020-06-29 21:05:56, but instead it returns 3037.

      Formula for Prints:
      Print(Time[0] + " | ZigZag High[0]: " + High[ZigZag(DeviationType.Points, 2, true).HighBar(0, 1, 100)] + " | ZigZag High[1]: " + High[ZigZag(DeviationType.Points, 2, true).HighBar(0, 1, 100) + 1] + " | ZigZag High[2]: " + High[ZigZag(DeviationType.Points, 2, true).HighBar(0, 1, 100) + 2]);

      Comment


        #4
        Hello UltraNIX,

        What are you comparing to?

        Are you comparing to a chart?

        Can we see a screenshot? (use the crosshairs and databox to highlight the time and other values of the bar)
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Screenshot of what? NinjaScript output window? Chart?

          I mean whole logic should be, if the High[0] is the current High of Zigzag, then High[1] should be High of Zigzag of 1 bar ago, High[2] should be High of ZIgzag of 2 bars ago.

          So let's take this example from my previously stated NinjaScript Output window with print result, which I am going to re-paste:
          Code:
          2020-06-29 20:58:06 | ZigZag High[0]: 3039,5 | ZigZag High[1]: 3038,25 | ZigZag High[2]: 3036,5 2020-06-29 21:00:59 | ZigZag High[0]: 3039,5 | ZigZag High[1]: 3038,25 | ZigZag High[2]: 3036,5 2020-06-29 21:04:26 | ZigZag High[0]: 3039,5 | ZigZag High[1]: 3038,25 | ZigZag High[2]: 3036,5 2020-06-29 21:05:56 | ZigZag High[0]: 3037,75 | ZigZag High[1]: 3037 | ZigZag High[2]: 3037 2020-06-29 21:07:54 | ZigZag High[0]: 3037,75 | ZigZag High[1]: 3037 | ZigZag High[2]: 3037 2020-06-29 21:11:21 | ZigZag High[0]: 3037,75 | ZigZag High[1]: 3037 | ZigZag High[2]: 3037 2020-06-29 21:15:47 | ZigZag High[0]: 3037,75 | ZigZag High[1]: 3037 | ZigZag High[2]: 3037
          We have

          2020-06-29 20:58:06 | ZigZag High[0]: 3039,5 |
          2020-06-29 21:00:59 | ZigZag High[0]: 3039,5 |
          2020-06-29 21:04:26 | ZigZag High[0]: 3039,5 |

          So, according to the previously stated logic, if 2020-06-29 21:04:26 | ZigZag High[0]: 3039,5 |, then Zigzag High [1] should be the previous value of Zigzag High[0], or 3039,50 (value of 2020-06-29 21:00:59) and ZigZag High[2] should be the value of 2 bars ago, same 3039,5 (value of 2020-06-29 20:58:06). Instead, ZigZag High[1] returns 3038,25 (not 3039,50) and ZigZag High[2] returns 3036,5 (not 3039,50).

          I cannot explain it any better, however, I could provide you with additional information if needed. By the way, since it is no part of any strategy or script, you could check this code yourself, use my code for Print and you will get something similar.

          Comment


            #6
            Hello UltraNIX,

            I can't confirm any of these values.

            Everything is looking fine on my end. The high of the bar with the zig zags last high is spot on when comparing to the chart on my end..

            How do you know the values are wrong?
            What are you comparing with?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Can you insert my print formula and paste fragment of output window results?

              Comment


                #8
                Here, I am adding a marked screenshot. I cannot explain it any better. But your code really doesn't work as it suppose to.
                Attached Files

                Comment


                  #9
                  Anybody willing to help?

                  Comment


                    #10
                    Solved this with advice of NinjaTrader_Kate in another topic to use Strategy Builder for calling indicators.

                    This determines a change in lower pivot (V)
                    (((ZigZag(DeviationType.Points, 2, true).ZigZagLow[0] != ZigZag(DeviationType.Points, 2, true).ZigZagLow[2])) ? true : false)

                    This determines a change in higher pivot (/\)
                    (((ZigZag(DeviationType.Points, 2, true).ZigZagHigh[0] != ZigZag(DeviationType.Points, 2, true).ZigZagHigh[2])) ? true : false)

                    In case anyone needed it in future.

                    Comment


                      #11
                      Thanks UltraNIX for posting the answer. Helped with my situation

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by algospoke, Yesterday, 06:40 PM
                      2 responses
                      19 views
                      0 likes
                      Last Post algospoke  
                      Started by ghoul, Today, 06:02 PM
                      3 responses
                      14 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Started by jeronymite, 04-12-2024, 04:26 PM
                      3 responses
                      45 views
                      0 likes
                      Last Post jeronymite  
                      Started by Barry Milan, Yesterday, 10:35 PM
                      7 responses
                      20 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Started by AttiM, 02-14-2024, 05:20 PM
                      10 responses
                      180 views
                      0 likes
                      Last Post jeronymite  
                      Working...
                      X