I use this Outside bar reversal study:
input aggregationPeriod = AggregationPeriod.HOUR; input showOnlyLastPeriod = no; declare once_per_bar; input BarMultiplier = 1.25; input BarsBack = 50; def MyCandleSize = (high – low); def AverageCandle = Average(MyCandleSize, BarsBack); def Bar = BarNumber(); def Long = if low < low and close > high and ((high – low) >= (AverageCandle * BarMultiplier)) then Bar else Double.NaN; def Short = if high > high and close < low and ((high – low) >= (AverageCandle * BarMultiplier)) then Bar else Double.NaN; plot LongSignal = if !IsNaN(Long) then low else Double.NaN; LongSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP); LongSignal.SetLineWeight(1); LongSignal.SetDefaultColor(Color.GREEN); plot ShortSignal = if !IsNaN(Short) then high else Double.NaN; ShortSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN); ShortSignal.SetLineWeight(1); ShortSignal.SetDefaultColor(Color.RED);
It triggers a buy/sell setup If the current bar is an outside candle. In this case it’s not my intention to use the script to do a scan on watchlist. Rather create an StudyAlert on just one symbol which send me an email every time a signal is triggered. I would like to get alerts by email, So I can those alerts use in Tasker. It’s an automation app for android. I like to create profiles around notifications which allows to determine under which circumstances notifications gets handled. This can be very handy to override a sound profile on android such as silent mode.
I added a screenshot which shows a Buy signal and a Sell Signal.
The Issue I get is when I want create the StudyAlert I receive the error:
No such function: BarNumber at 13:11, which get triggered by:
def Bar = BarNumber();
As mentioned in another thread ( https://www.hahn-tech.com/ans/how-do-i-add-custom-indicators-to-condition-wizard/ ) I copied and pasted the full code instead of just select the custom study.
May be someone have an advice how to get it working.
Marked as spam
It is not possible to use your screenshot to confirm the accuracy of this solution. This is because your screenshot does not show the full chart. We cannot see the ticker symbol or the selected time frame. Not sure why, but many of the folks posting in the forum don't feel it's important to include the full chart in the screenshots they provide. But if you don't include the full chart, you might as well omit the screenshot altogether.
Nevertheless, we can provide a solution to this. The BarNumber() issue was only one of many issues that needed to be corrected here. Here is the code that runs in the Study Alert tool found under the MarketWatch tab on the Thinkorswim platform. Please note that this is the exact same code you would use to run a scan.
Marked as spam
Thank you. This code works. Not sure if I should open another thread for this question. I would like to add a function which lets the alert only trigger when the 1 hour candle is done. Otherwise, it may trigger many times while the candle is in progress of building. If I add this line: input displace = 1; Should this be the solution?
The most effective way to force the bar to close before alert is this: plot alert = longSignal; plot alert = shortSignal;
Thank you. That worked. The last issue: Since on alert settings 'reverse crossover' is enabled, the alert goes off every full hour once it got triggered. I thought I could solve this issue when I set input barsBack=1 But it still happens.
If the alert is being triggered every hourly bar after the initial signal then the problem is in how the code is written. There was no list of specifications (what the code is supposed to do). You provided the code and I only provided the corrections required to reproduce that signal in the Study Alert tool. The input named barsBack. This is actually the length of the moving average used to measure the average candle height. Reducing that input to 1 only forces the code to use the current candle as the average candle height.
I see. Can you suggest at what I should look to avoid repeating triggering? Sure, when I disable ’recreate alert for reverse crossover’, it won’t trigger anymore. I just stumbled over this thread: https://www.hahn-tech.com/ans/recursive-alerts/ I’m not sure if this is similar to my issue. If so, I could keep ’recreate alert for reverse crossover’ on, but enable ’silent alert’ in hope that it gives me only an alert (in my case an e-mail) when a new alert gets triggered. But somehow I doubt the solution is that easy.
Ok, Silent Alert did the trick. I switched to 1 Minute chart to get more triggers. So I could do some tests. Now it alerts only if there is really a new trigger. Thanks very much for your effort Pete. Much appreciated.
Nah, I was too early. Just realized that TOS generated countless pop-ups on the main screen. Had even difficulties to close the application. That's unreal. Still hoping you have another Idea.
Nope. I am out of ideas. There is nothing in the code that produces this behavior. I suggest you take this up with TDA support. The issue has to be something do with how you have your alerts setup.
I was able to found the error. It was my fault. With that, the code you provided and set recursive alerts to silent works just perfect. Once again, thank you Pete.
Please log in to post questions.