How do I get TOS to give an alert at the CLOSE of a 400 tick bar


0
0

I am using the following study on 400 tick charts. It gives “false” signals when the close of current bar is >= high of prior bar. But its not really the “close” its only the last tick >= high of prior bar. The 400 tick chart actually closes < high of prior bar. In other words it shows a true condition during the bar but by the end of the bar it is false. How do I get it to evaluate at the close or at least closer to the end of the bar? For example can I get it to evaluate the condition after 390 ticks of a 400 tick bar? Any help would be appreciated. Thanks Lindsay

 

input TimeStart = 0950;
def time = SecondsFromTime(TimeStart) >= 0;
def opencurrent = (open <= close [1]);
def closecurrent = (close >= high [1]);
def priorclose = (close[1] <= open [1]);
def TRI = TrueRange(high[1], close[1], low[1]);
def prioratr = TRI <= 3;
def priorclosebelow20 = (low [1] <= MovingAverage(AverageType.EXPONENTIAL, close [2], 20));
def b = (opencurrent && closecurrent && priorclose && prioratr && priorclosebelow20 && time);
plot a = (opencurrent && closecurrent && priorclose && prioratr && priorclosebelow20 && time);
a.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
a.SetLineWeight(5);
a.SetDefaultColor(Color.GREEN);
Alert(a, “Trend is up!”, Alert.BAR, Sound.Chimes);

RESOLVED
Marked as spam
Posted by (Questions: 7, Answers: 11)
Asked on June 6, 2018 5:58 pm
641 views
0

Thanks for the help!

( at June 7, 2018 2:14 pm)
0
Private answer

Very simple. In the alert statement, you need to reference the previous bar’s value of the targeted signal. There is nothing “false” about your existing alerts. It’s simply behaving exactly as you have told it to.

I will take a moment to include some comments on the code. I absolutely despise excessive abbreviations in code. Any variable names of a single character should be grounds for punishment. What does ‘a’ actually represent? What does ‘b’ actually represent? Spell it out. Make the code readable.

And why did you not apply “camelCase” to your other variables?

opencurrent should be openCurrent

closecurrent should be closeCurrent

priorclose should be priorClose

prioratr should be priorATR

priorclosebelow20 should be priorCloseBelow20

Finished ranting for now. Here is your solution.

Alert(a[1], “Trend is up!”, Alert.BAR, Sound.Chimes);

Marked as spam
Posted by (Questions: 37, Answers: 4091)
Answered on June 6, 2018 7:25 pm