Storing 'Bars Since' a Condition from ZigZag
Forums › ProRealTime English forum › ProScreener support › Storing 'Bars Since' a Condition from ZigZag
- This topic has 5 replies, 2 voices, and was last updated 4 years ago by
Vonasi.
-
-
06/06/2020 at 7:38 PM #134919
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.
12345ZZ = ZigZag[17](close)If ZZ < ZZ[1] AND ZZ[1] > ZZ[2] thenCrossingPosition = BarindexEndifX = Barindex - CrossingPositionI 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.
06/06/2020 at 10:20 PM #134934Your 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:
1234567891011x = 10ZZ = ZigZag[17](close)If ZZ < ZZ[1] AND ZZ[1] > ZZ[2] then$CrossingPosition[a] = Barindexa = a + 1Endifc = 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.
06/07/2020 at 7:38 AM #13494206/07/2020 at 8:13 AM #134947v10.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.
12345678ZZ = ZigZag[17](close)If ZZ < ZZ[1] AND ZZ[1] > ZZ[2] thena3 = a2a2 = a1a1 = aa = BarindexEndifX = Barindex - a306/07/2020 at 8:24 AM #134948Hi,
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.
06/07/2020 at 9:45 AM #134957Yes 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.
-
AuthorPosts