Please see attached chart screenshot
I am trying to identify where a 10 period ma (broken blue line) does not make a lower low
I thought I could use summation function.
something like
Where 10ma>10ma[1] and 10ma[1]<10ma[2] (ie 10ma has reversed direction)
using summation exmaine the last n bars (lets n = 6) ma10<ma10[1] and look for assets where the count=>5 (remember the for latest bar the ma10>ma10[1])
Then for the prior 10 bars prior to bar 6 I need to see assets where the ma10[]>ma10[]>=7
Then for the 14 bars prior to that i need return assets where ma10[]<ma10[] >=12
If all three criteria are met then include in results.
I hope this making sense. Basically I wish to examine the 6 bars then the prior 10 bars prior and then the 14bars prior to that so looking at total 30 bars
Any help would be appreciated.
Thank you very much
Simon
Also it is possible to check whether the value of 10ma[1] is above the 10ma low of the entire period?
Hi Simon,
I believe there’s a more efficient way to approach the problem to reduce computational time while still getting the results you’re looking for.
Instead of manually iterating over the bars, you can use a combination of the 10-period moving average and a check for direction changes. Additionally, with the summation function, you can quickly verify how many times this change has occurred within a range of N bars. Here’s how the code might look:
// Calculate the 10-period moving average
ma10 = average[10](close)
// Check for the direction change
change = ma10 > ma10[1] and ma10[1] < ma10[2]
// Use summation to check how many times the change occurred in the last 15 bars
check = summation[15](change)
// Use barssince to find how many bars have passed since the last change
bar = barssince(change)
This approach optimizes the calculations and reduces complexity, while being more efficient in terms of runtime. You can adjust the number of bars to examine or combine it with other criteria as needed.
I hope this helps.
Thanks this does help.
Thinking I will only look for those asset where the check = 2
// Use summation to check how many times the change occurred in the last 15 bars
check = summation[15](change)
Is there a way to somehow check whether for the 2nd (latest) change in direction, that MA10 value is above MA10 value at the time of the 1st change in direction?
Many thanks
Simon
Here you have an example:
// Calculate the 10-period moving average
ma10 = average[10](close)
// Check for the direction change
if ma10 >= ma10[1] and ma10[1] < ma10[2] then
prevMAvalue=MAvalue
change=1
MAvalue=ma10[1]
else
change=0
endif
// Use summation to check how many times the change occurred in the last 15 bars
check = summation[15](change)
// Use barssince to find how many bars have passed since the last change
bar = barssince(change)
return ma10 coloured("orange"), MAvalue coloured("darkblue"), prevMAvalue coloured("red")style(dottedline)
Thank for this, although this appears to be an indicator? Just in case I did not make myself clear .
I am seeking to screen for assets where the 2nd change of direction the 10ma value is higher than the 10ma at the point where the first change of direction occurred.