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

ZigZag

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

    ZigZag

    With this code I hoped to compare the last 3 highs / lows of the ZigZag line with the values of the last Envelope upper and lower lines at the same bars, like in the circled points of my attachment:

    if (ZigZag(DeviationType.Percent, 0.5, false).LowBar(0, 2, 100) < MAEnvelopes(0.1, 3, 60).Lower[2]
    && ZigZag(DeviationType.Percent, 0.5, false).HighBar(0, 1, 100) > MAEnvelopes(0.1, 3, 60).Upper[1]
    && ZigZag(DeviationType.Percent, 0.5, false).LowBar(0, 0, 100) > MAEnvelopes(0.1, 3, 60).Lower[0]
    && ZigZag(DeviationType.Percent, 0.5, false).LowBar(0, 0, 100) < MAEnvelopes(0.1, 3, 60).Upper[0])


    I want to know whether the highs (or lows) - when they occur - are above (or below) the Envelope.
    Unfortunately, the code doesn't help me here.
    First of all I get an error for the first member of the equation, i.e. ZigZag(Deviation......), whose syntax is probably wrong (although I copied it from the HelpLine).
    Furthermore, the second member (MAEnvelope(.....)) does identify the values of the Envelope lines, but everywhere - not when the ZigZag highs/lows occur, as I need for my comparations.
    Please don't send me the usual link http://www.ninjatrader.com/support/forum/showthread.php?t=63231&goto=newpost,
    since I already watched it without understanding anything of that page.
    Attached Files
    Last edited by Mauripasto; 07-25-2014, 04:10 PM.

    #2
    Hello,

    Thank you for your note.

    Since you are calling the LowBar or HighBar you need to pass this int into a DataSeries. For example:
    Code:
    if ([B]Low[ZigZag(DeviationType.Percent, 0.5, false).LowBar(0, 2, 100)][/B] < MAEnvelopes(0.1, 3, 60).Lower[2]
    && [B]High[ZigZag(DeviationType.Percent, 0.5, false).HighBar(0, 1, 100)][/B] > MAEnvelopes(0.1, 3, 60).Upper[1]
    && [B]Low[ZigZag(DeviationType.Percent, 0.5, false).LowBar(0, 0, 100)][/B] > MAEnvelopes(0.1, 3, 60).Lower[0]
    && [B]Low[ZigZag(DeviationType.Percent, 0.5, false).LowBar(0, 0, 100)][/B] < MAEnvelopes(0.1, 3, 60).Upper[0])
    Please make sure to review the syntax and when it is used for the ZigZag indicator method at the following link: http://www.ninjatrader.com/support/h...nt7/zigzag.htm

    Comment


      #3
      Many thanks for your answer, which helped me a lot.
      Yet, even if the code now is more correct, I get the same error as before (see the Output window), since it seems that the mentioned function IS NOT ALLOWED to be 0 (why?).
      I believe this is the reason of the immediate unchecking / disabling of the boxes in the strategies tool as soon as I try to enable / check them (see attachment, only currency pairs keep the check sign, while stocks and futures don't).
      I'm also attaching my code.
      Attached Files

      Comment


        #4
        Hello Mauripasto,

        Thank you for your response.

        The instance of the HighBar and LowBar cannot be 0, it must be at least 1. 1 being the most recent occurrence. So the code should reflect the following:
        Code:
        			if (Low[ZigZag(DeviationType.Percent, 0.5, false).LowBar(0, 2, 100)] < MAEnvelopes(0.1, 3, 60).Lower[2]
        			&& High[ZigZag(DeviationType.Percent, 0.5, false).HighBar(0, 1, 100)] > MAEnvelopes(0.1, 3, 60).Upper[1]
        			&& Low[ZigZag(DeviationType.Percent, 0.5, false).LowBar(0, 1, 100)] > MAEnvelopes(0.1, 3, 60).Lower[0]
        			&& Low[ZigZag(DeviationType.Percent, 0.5, false).LowBar(0, 1, 100)] < MAEnvelopes(0.1, 3, 60).Upper[0])
        
        			if (High[ZigZag(DeviationType.Percent, 0.5, false).HighBar(0, 2, 100)] > MAEnvelopes(0.1, 3, 60).Upper[2]
        			&& Low[ZigZag(DeviationType.Percent, 0.5, false).LowBar(0, 1, 100)] < MAEnvelopes(0.1, 3, 60).Lower[1]
        			&& High[ZigZag(DeviationType.Percent, 0.5, false).HighBar(0, 1, 100)] > MAEnvelopes(0.1, 3, 60).Lower[0]
        			&& High[ZigZag(DeviationType.Percent, 0.5, false).LowBar(0, 1, 100)] < MAEnvelopes(0.1, 3, 60).Upper[0])

        Comment


          #5
          Fine, with your lines the strategies remain checked and enabled for ALL instruments.
          That's great. However, I confess I really don't understand this, namely that I'm not allowed to look at the LAST zigzag high/low with the functions ending .......Bar (0,0,100).

          Since for my purposes I must anyway compare three ZigZag values and I can't call the last occurred one, then I'm forced to use ......Bar (0,1,100), ......Bar (0,2,100) and ......Bar (0,3,100), i.e. ..1..2..3.. instead of ..0.., ..1.., ..2.. as I did in my code: am I right ?

          But what if one exactly needs to know the last (or current) ZigZag high or low ?

          Comment


            #6
            Hello Mauripasto,

            I understand your confusion but 1 is the most recent occurrence. This works differently than the 0 that is used for the data series objects like Open, High, Low and Close.

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

            Comment


              #7
              I see.
              Now I have a last problem hindering the strategy.
              I must compare the ZigZag highs/lows (yellow circles in the attachment) with the Envelope's values (red circles) at the same moments when the highs / lows occur.
              Calling MAEnvelopes(0.1, 3, 60).Lower[2] doesn't help me, since this does identify the Envelope lower value, however at the bar -2, not at the one when the ZigZagLow happened.
              Do I need something like this:
              MAEnvelopes(0.1, 3, 60).Lower[Low[ZigZag(DeviationType.Percent, 0.5, false).LowBar(0, 2, 100)] ?
              Otherwise, how may I solve the problem ?
              Attached Files
              Last edited by Mauripasto; 07-28-2014, 02:45 PM.

              Comment


                #8
                Hello Mauripasto,

                Thank you for your response.

                You have the right idea:
                Originally posted by Mauripasto View Post
                MAEnvelopes(0.1, 3, 60).Lower[Low[ZigZag(DeviationType.Percent, 0.5, false).LowBar(0, 2, 100)] ?
                Otherwise, how may I solve the problem ?
                But instead you would use the following:
                Code:
                MAEnvelopes(0.1, 3, 60).Lower[ZigZag(DeviationType.Percent, 0.5, false).LowBar(0, 2, 100)]

                Comment


                  #9
                  Thanks. However, why do the functions
                  ZigZag(DeviationType.Percent, 0.05, true).LowBar(0, 1, 20)
                  and
                  ZigZag(DeviationType.Percent, 0.05, true).HighBar(0, 1, 20)
                  (which record how many bars ago the previous ZigZagLow and ZigZagHigh occurred) so often change to -1 without a new ZigZagLow or ZigZagHigh (in which case they would be reset to 1), i.e. without any apparent reason, this way losing the important track of the previous Low / High ?

                  Ok, the reset to -1 happens whenever the limit value "21" is reached, but what about all other cases ?
                  Last edited by Mauripasto; 08-23-2014, 02:53 AM.

                  Comment


                    #10
                    Or does this occur since an apparent or temporary reverse occurs, that is not confirmed later as a ZigZag Low/High ?

                    If so, how is it possible to identify a REAL ZigZag Low/High in our programming ?
                    Last edited by Mauripasto; 08-23-2014, 03:33 AM.

                    Comment


                      #11
                      Hello Mauripasto,

                      Thank you for your posts.

                      A value of -1 is returned if a swing point is not found within the look back period. Meaning, the ZigZag did not find anew high or low within the number of bars used for your look back period.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by ender_wiggum, Today, 09:50 AM
                      1 response
                      5 views
                      0 likes
                      Last Post NinjaTrader_Gaby  
                      Started by rajendrasubedi2023, Today, 09:50 AM
                      1 response
                      10 views
                      0 likes
                      Last Post NinjaTrader_BrandonH  
                      Started by geotrades1, Today, 10:02 AM
                      0 responses
                      4 views
                      0 likes
                      Last Post geotrades1  
                      Started by bmartz, Today, 09:30 AM
                      1 response
                      8 views
                      0 likes
                      Last Post NinjaTrader_Erick  
                      Started by geddyisodin, Today, 05:20 AM
                      3 responses
                      24 views
                      0 likes
                      Last Post NinjaTrader_Gaby  
                      Working...
                      X