Storing 'Bars Since' a Condition from ZigZag

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #134919 quote
    scoot3r83
    Participant
    Average

    Hello,

    I am new to PRT and coming from a Metastock background. I am trying to store the number of bars since a set of criteria into a variable for later use in my code but cannot find how to correctly do this. The code I have is below, any help will be appreciated.

    ZZ = ZigZag[17](close)
    If ZZ < ZZ[1] AND ZZ[1] > ZZ[2] then
    CrossingPosition = Barindex
    Endif
    X = Barindex - CrossingPosition

    I am unsure but believe the first line saves the zigzag values as an array and within the if statement am trying to reference to those array elements.

    #134934 quote
    Vonasi
    Moderator
    Master

    Your code does not use arrays. Arrays are only available in PRT v11. Your code simply stores the last barindex value when the event occurred.

    In v11 using arrays the code would be:

    x = 10
    
    ZZ = ZigZag[17](close)
    If ZZ < ZZ[1] AND ZZ[1] > ZZ[2] then
    $CrossingPosition[a] = Barindex
    a = a + 1
    Endif
    
    c = LastSet[$CrossingPosition]
    
    mycrossingindex= $CrossingPosition[c-x]

    ‘mycrossingindex’ would then return the barindex of the zigzag peak 10 zigzag peaks back in this example.

    Not tested.

    #134942 quote
    scoot3r83
    Participant
    Average

    Thank you for the reply. I do not have V11, I believe I use V10.3.

    In V10.3, what would be the method to access the peaks and troughs of the zigzag function?

    #134947 quote
    Vonasi
    Moderator
    Master

    v10.3 does not have arrays. Store them in different variable names and drop the oldest when you get a new one. Obviously you are limited to how much repetitive typing you are willing to do!

    I assume that you are aware that the ZigZag indicator redraws and so you will be storing many changes in direction that will later no longer exist?

    Are you coding this for a screener? If not then you have posted it in the wrong forum.

    ZZ = ZigZag[17](close)
    If ZZ < ZZ[1] AND ZZ[1] > ZZ[2] then
    a3 = a2
    a2 = a1
    a1 = a
    a = Barindex
    Endif
    X = Barindex - a3
    #134948 quote
    scoot3r83
    Participant
    Average

    Hi,

    Thanks again for the reply, I see what you mean about storing each variable, I can do that as I won’t need to store too many occurrences but believe the ZigZag function works from the most recent bar and then proceeds to the left of the chart.

    Yes I am using this code as a screener, apologies for posting this in the incorrect forum, I am new to this site as of yesterday so a bit unfamiliar with it. I will see if I can have my post relocated to the correct forum.

    #134957 quote
    Vonasi
    Moderator
    Master

    Yes I am using this code as a screener, apologies for posting this in the incorrect forum, I am new to this site as of yesterday so a bit unfamiliar with it. I will see if I can have my post relocated to the correct forum.

    You posted it in the correct forum. I just felt the need to ask as it is so rare these days for a newbie forum member to actually do that!

    Because the ZigZag repaints you can have a change of direction at the close of the latest bar that the bar after that disappears so you will have stored the position of a change of direction that no longer exists. It is why indicators like the ZigZag look so good – they change their mind once they have seen what happens in the future.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.

Storing 'Bars Since' a Condition from ZigZag


ProScreener: Market Scanners & Detection

New Reply
Author
author-avatar
scoot3r83 @scoot3r83 Participant
Summary

This topic contains 5 replies,
has 2 voices, and was last updated by Vonasi
5 years, 9 months ago.

Topic Details
Forum: ProScreener: Market Scanners & Detection
Language: English
Started: 06/06/2020
Status: Active
Attachments: No files
Logo Logo
Loading...