Alert on ‘outside bar reversal study’ (no such function issue)


0
0

Hello

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[1] and close > high[1] and ((high – low) >= (AverageCandle * BarMultiplier)) then Bar else Double.NaN; def Short = if high > high[1] and close < low[1] 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.
Thank you.

Attachments:
Marked as spam
Posted by (Questions: 3, Answers: 7)
Asked on January 15, 2020 2:13 pm
261 views
0
Private answer

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.

input barMultiplier = 1.25;
input barsBack = 50;
def myCandleSize = (high - low);
def averageCandle = Average(myCandleSize, barsBack);
def long = if low < low[1] and close > high[1] and ((high - low) >= (averageCandle * barMultiplier)) then 1 else Double.NaN;
def short = if high > high[1] and close < low[1] and ((high - low) >= (averageCandle * barMultiplier)) then 1 else Double.NaN;
def longSignal = !IsNaN(long);
def shortSignal = !IsNaN(short);
# use this to alert or scan for long signals
plot alert = longSignal;
# use this to alert or scan for short signals
#plot alert = shortSignal;

Marked as spam
Posted by (Questions: 37, Answers: 4079)
Answered on January 16, 2020 12:20 pm
0
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?
( at January 22, 2020 8:49 am)
0
The most effective way to force the bar to close before alert is this: plot alert = longSignal[1]; plot alert = shortSignal[1];
( at January 22, 2020 12:48 pm)
0
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.
( at January 28, 2020 7:20 am)
0
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.
( at January 28, 2020 8:40 am)
0
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.
( at January 28, 2020 9:06 am)
0
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.
( at January 28, 2020 1:34 pm)
0
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.
( at January 28, 2020 2:05 pm)
0
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.
( at January 28, 2020 2:25 pm)
0
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.
( at January 29, 2020 5:01 am)