Count condition help
Forums › ProRealTime English forum › ProBuilder support › Count condition help
- This topic has 11 replies, 2 voices, and was last updated 6 years ago by robertogozzi.
-
-
04/07/2018 at 3:11 PM #67507
Hi,
I am trying to code an indicator which does a count. The count is set to zero and rises to one when high and low of a candle is less than the high and low of the previous candle. The count would be increased by one every time the high and low of a candle are lower than the high and low of the most recent candle on which the count was increased.
The count would continue until X (to be defined).
The count will reset to zero when a new high is formed; this means when the new high is higher than the high of the candle which preceded the count one candle.
Any candles not adhering to the conditions above are to be ignored.
Managed to write a code but it only looks at the previous candle rather than at the one on which the count increased, also can’t get the reset condition in. Code is below
12345678910Decrease = High < High[1]Count = 0WHILE Low < Low[1] DOIF Decrease[Count] THENCount = Count + 1CONTINUEENDIFBREAKWENDRETURN CountCould anyone please help me build up this code?
Thanks
04/07/2018 at 3:19 PM #67509Try this (not tested)
123456789101112Decrease = High < High[1]Count = 0x = 1WHILE Low < Low[x] DOIF Decrease[Count] THENCount = Count + 1x = CountCONTINUEENDIFBREAKWENDRETURN Count04/07/2018 at 6:28 PM #67520Hi, thanks for the input, but your code is doing the same as the original code i put in.
I need it to look at the candle which increased the count rather than the previous candle, and to reset to zero when a new high is formed.
Any ideas?
Thanks
04/09/2018 at 12:09 AM #67574Can you attach a screenshot where you draw numbers or something to better explain what you mean?
Thank you.
04/23/2018 at 9:50 PM #69028Hi,
Please find attached photo as an example. Whenever the high and low of a candle are less than or equal to the high and low of the candle with a new high(which has a 0 count), the count begins and is set to 1. The count increases to 2 when the high and low of a following candle are less than or equal to the high and low of the candle that increased the count to 1. The count increases to 3 when the high and low of a following candle are less than or equal to the high and low of the candle that increased the count to 2. The count increases to 4 when the high and low of a following candle are less than or equal to the high and low of the candle that increased the count to 3. The count continues only until it reaches 4.
Whenever a new high is formed(whenever the high of a candle is higher than the high of the candle that had the previous count 0), the count resets to 0. Any other candles that do not meet the criteria are ignored. I hope this makes sense and someone could help with this.
Thanks
04/24/2018 at 9:51 AM #69054There you go. Give me some feedback. Thanks.
Candlestick Count123456789101112131415ONCE MaxCount = 4 //no more than 4 candles before restarting from 0ONCE Count = 0ONCE MaxHigh = 999999IF low < low[1] AND high < high[1] THEN //when a candle meets requirements...count = count + 1 //... increment count...IF Count = 1 THEN //... if it's the first one...MaxHigh = high[1] //... set MaxHigh to the previous HIGH (candle 0)ENDIFDRAWTEXT("#count#", barindex, low - 5 * pipsize, Dialog, Bold, 12) COLOURED(255,10,10,255) //display countENDIFIF Count > MaxCount OR high > MaxHigh THEN //reset to 0 after max candles OR when a higher high is metCount = 0MaxHigh = 999999ENDIFRETURN2 users thanked author for this post.
04/24/2018 at 10:16 PM #69103Hi,
Thank you for your help again. Unfortunately is not returning what I am looking for; is the same problem as previously; rather than increasing the count when the high and low of a candle are equal to or less than the high and low of the candle that previously increased the count, is increasing the count when the high and low are equal to or less that the high and low of the preceding candle.
Also when checking if a new high is formed, it looks at the previous candle rather than at the candle which was the previous high.
I think the condition should be something like: “IF low < low[low of candle that increased the count] AND high < high[high of candle that increased the count] THEN “. Is something like this possible? Or can it only look at a specified candle eg. 1=previous candle?
Thanks
04/25/2018 at 12:35 AM #69107I hope this will do, I tested it on Eur/Chf, 15min and it seems to be working.
12345678910111213141516171819ONCE MaxCount = 4 //no more than 4 candles before restarting from 0ONCE Count = 0ONCE MaxHigh = 999999IF MaxHigh = 999999 THENLookBack = 1ELSELookBack = BarIndex - BarCountENDIFIF (low <= low[LookBack]) AND (high <= high[LookBack]) THEN //when a candle meets requirements...count = count + 1 //... increment count...MaxHigh = high //... set MaxHigh to this high..BarCount = BarIndexDRAWTEXT("#count#", barindex, low - 15 * pipsize, Dialog, Bold, 12) COLOURED(255,10,10,255) //display countENDIFIF Count >= MaxCount OR high > MaxHigh THEN //reset to 0 after max candles OR when a higher high is metCount = 0MaxHigh = 999999ENDIFRETURN04/25/2018 at 10:01 PM #69179The count of the candles is working now, thank you.
The only problem left is that when checking if a new high is formed, it looks at the previous candle rather than at the candle which was the previous high.
For example, on the chart you attached, let’s look at the first candles on the left which have the numbers 1 2 3 underneath. The candle which has the number 3 is followed by a red one and then by a blue one. The blue candle should have been number 4 (the high and low of this are less than the high and low of candle with count 3; red candle after the candle with the count of 3 should be ignored as the high of this is not higher than the high of candle 0)but it doesn’t because the red candle after the one with the count of 3 resets the count to 0 because is looking at the candle with the count 3 and a new high is formed. The high of the red candle should be looking at the high of the candle before the candle with the count 1 as this was the previous candle with the count 0.
I hope this makes sense, as is quite complicated to explain.
Thanks
04/26/2018 at 4:46 PM #69229For example, on the chart you attached, let’s look at the first candles on the left which have the numbers 1 2 3 underneath. The candle which has the number 3 is followed by a red one and then by a blue one. The blue candle should have been number 4 (the high and low of this are less than the high and low of candle with count 3; red candle after the candle with the count of 3 should be ignored as the high of this is not higher than the high of candle 0)but it doesn’t because the red candle after the one with the count of 3 resets the count to 0 because is looking at the candle with the count 3 and a new high is formed. The high of the red candle should be looking at the high of the candle before the candle with the count 1 as this was the previous candle with the count 0.
Should it reference candle 0 or the candle that incremented the count?
04/26/2018 at 5:04 PM #69232The count will reset to zero when a new high is formed; this means when the new high is higher than the high of the candle which preceded the count one candle.
You warned me not to reference candle 0 to increment count, but the previous candle that caused the count to be incremented, is that correct?
When you talk about a new high, should I reference the high of candle 0 or the high of the candle that most recently caused the count to be incremented?
04/26/2018 at 5:17 PM #69233I modified the code to reflect your last post (I hope I could understand what you meant)
123456789101112131415161718192021222324ONCE MaxCount = 4 //no more than 4 candles before restarting from 0ONCE Count = 0ONCE MaxHigh = 999999ONCE Candle0High = 999999IF MaxHigh = 999999 THENLookBack = 1ELSELookBack = BarIndex - BarCountENDIFIF (low <= low[LookBack]) AND (high <= high[LookBack]) THEN //when a candle meets requirements...count = count + 1 //... increment count...MaxHigh = high //... set MaxHigh to this high..BarCount = BarIndexDRAWTEXT("#count#", barindex, low - 2 * pipsize, Dialog, Bold, 12) COLOURED(255,10,10,255) //display countIF Count = 1 THENCandle0High = high[1]ENDIFENDIFIF Count >= MaxCount OR high > Candle0High THEN //reset to 0 after max candles OR when a higher high is metCount = 0MaxHigh = 999999Candle0High = 999999ENDIFRETURN -
AuthorPosts
Find exclusive trading pro-tools on