Yes, we have a very simple change to make to get this working. And since you have posted your own code I will take the time to explain how we get this working.
First, Some Cleanup Work
I have two lines of code that I am removing, by placing a “#” mark at the start of these two lines:
def ATR = average(TRI,1);
def b = (highatr && time);
We do not need the “def ATR” because that is the one period moving average of the TRI variable. A one period moving average of any value is that value. So we don’t need it. This change does nothing to fix the issue. It’s just a matter of cleaning up the code to it minimal required components.
Same thing for the “def b” statement. That assignment can be done directly within the “plot a” statement. So we don’t need this extra step either. Again, this does nothing to fix the issue. It’s just cleaning things up.
Now to Fix the Problem
The mistake is found in this line of code:
def highatr = TRI > Highest(TRI, 10);
But wait. That code is not exactly the same. If you noticed that, good job. You see when I cleaned the code and removed the “def ATR” line I was able to replace ATR in this line of code with TRI. Remember that TRI is exactly the same value as the one period moving average of TRI.
Now that we have it stated in it’s cleanest form, something should jump out at you. We are checking if the current bar’s TRI value is greater than the Highest TRI value of the previous 10 bars (including the current bar). This can never evaluate to true, because you are including the current bar in the “Highest(TRI, 10)”. It’s like saying, the current bar is higher than the current bar. No it’s not, that’s impossible.
The Fix
So we need to use the previous value of TRI within the test for highest:
def highatr = TRI > Highest(TRI[1], 10);
We do this by placing ‘[1]’ at the end of the TRI that is within the test for highest. This excludes the current bar from the test, enabling us to properly compare the highest in 10 to the current bar. Now study this carefully because you may find that you need to reduce that from 10 to 9. Just depends whether your intention was to include the current bar or not, in the test for highest.
The Final Code
input TimeStart = 0950;
def time = SecondsFromTime(TimeStart) >= 0;
def TRI = TrueRange(high, close, low);
#def ATR = average(TRI,1);
def highatr = TRI > Highest(TRI[1], 10);
#def b = (highatr && time);
plot a = (highatr && time);
a.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
a.SetLineWeight(5);
a.SetDefaultColor(Color.YELLOW);
Alert(a, “Trend is up!”, Alert.ONCE, Sound.Chimes);
There it is, all cleaned up and fixed. I left those original lines there but commented out, just in case you decide you need them.
Thank you so much. Your site is great! Thanks Lindsay