Need alert to sound only after candle is closed


0
0

Hi Pete, I took the Marubozu candlestick pattern and created a study with it that includes audio alerts.  Problem is the alert goes off constantly while the candles are forming.  Is there a way to have the alert go off only after the candle is closed? Also, is there a quick way to add a script where the volume bar of the Marubozu candlestick should be greater than the avg of the prior “x” number of bars? Your help would be greatly appreciated. The script is below:

input length = 20;

def ErrMargin = 0.05 * Average(BodyHeight(), length);

plot Bearish = IsLongBlack(length) and
high – open <= ErrMargin and
close – low <= ErrMargin;

plot Bullish = IsLongWhite(length) and
open – low <= ErrMargin and
high – close <= ErrMargin;

Bearish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Bearish.SetDefaultColor(GetColor(7));
Bearish.SetLineWeight(2);
Bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Bullish.SetDefaultColor(GetColor(8));
Bullish.SetLineWeight(2);
alert(IsLongWhite(length), “BULLISH MARUBOZU”, alert.bar, sound.ring);
alert(IsLongBlack(length), “BEARISH MARUBOZU”, alert.bar, sound.ding);

Thanks,

Mike

RESOLVED
Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on July 5, 2019 12:12 am
786 views
0
Private answer

Not sure you realize this but....

plot Bullish = IsLongWhite(length) and open – low <= ErrMargin and= high – close <= ErrMargin;

Is your signal and your alerts are only triggering on a very small portion of that signal:

IsLongWhite(length)

So that could be the entire problem right there. You will need to explain why your alert only contains a small portion of the signal. If it was intentional, then we can simply do this:

Alert(IsLongWhite(length)[1], “BULLISH MARUBOZU”, Alert.BAR, Sound.RING);

If you actually intended to alert based on the entire signal then we would do this:

Alert(Bullish[1] “BULLISH MARUBOZU”, Alert.BAR, Sound.RING);

Either way, I think you get the idea. Using this '[1]' is how we reference the previous data point in the code. When applied to a signal, this forces the code to wait for the signal candle to be closed before the alert can trigger.

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on July 5, 2019 12:05 pm
0
Perfect, thanks Pete! I actually put a "1" where you did, but was using parentheses instead of brackets lol. Also, is there a way to make it so it doesn't paint the arrow (and alert the msg ctr) until after the stick closes? I'd still like to get the msg ctr alert when the Marubozu candle has completed, since that's where I go to see which stock it is. I'd also like to get an alert by text, but don't see a way to do it. Thanks again for taking the time and I just made a contribution for your effort. Mike
( at July 5, 2019 3:28 pm)
0
You can do that, yes. However when you do so, the alert is going to be delayed two bars unless you undo the changes I recommended in my answer. I'll show you how to do it with one of the two signals and you can apply it to the other:

Change this...

plot Bearish = IsLongBlack(length) and high – open <= ErrMargin and close – low <= ErrMargin;

To this...

def sigBearish = IsLongBlack(length) and high – open <= ErrMargin and close – low <= ErrMargin; plot Bearish = sigBearish[1];

Alert by text, that cannot be done using a chart study. You will need to move your code into a scan, then use that scan to create a dynamic alert. I demonstrate this starting at the 29:50 mark of this video: https://www.hahn-tech.com/thinkorswim-overnight-range-scan-alert/

( at July 6, 2019 8:45 am)
0
Hi Pete, I made the change to "def sigBearish" (and sigBullish) scripts and used them to fix the "alerts are only triggering on a very small portion of that signal" problem you referenced earlier: Alert (sigbullish[1], “BULLISH MARUBOZU”, Alert.BAR, Sound.Ring); Alert(sigbearish[1], “BEARISH MARUBOZU”, Alert.BAR, Sound.Ding); but as you can see, I kept the [1] in there instead of putting it at the end of the "def sigBearish" and "def sigBullish" scripts because it worked perfectly that way in testing. Now I get the arrow painting on the Marubozu candle as it forms (which is fine) and once it's done, but only get messages and audio alerts after the candle is closed. Thanks a ton for all your help! Mike
( at July 7, 2019 1:38 pm)