Use of AlertIf and sending mail when it is a Buysignal or Sellsignal or both

My code to scan is this:

ChannelBreakUp = H > Ref( HHV( High, 20 ), -1 );
Buy = ChannelBreakUp;
ChannelBreakUpDown = L < Ref( LLV( Low, 20 ), -1 );
Sell = ChannelBreakUpDown;


Buy = ExRem (Buy,Sell);
Sell = ExRem (Sell,Buy);

SetTradeDelays( 1, 1, 1, 1 );
BuyPrice = SellPrice = Open;

AlertIF( Buy, "EMAIL", "Buy this stock: "+FullName(),1);
AlertIF( Sell, "EMAIL", "Sell this stock: "+FullName(), 2 );

Its sending mail, but not the result from the scan. What wrong?

@herbertioz I just did a test with your code using AB 6.27.1 Beta 64-bit and it worked as expected.

I received all the scan results, in the following mail format:

Subject: Alert: Sell (2) AMP on 31/01/2018
Message: Sell this stock: AMERIPRISE FINANCIAL SERVICES, INC.

What kind of messages are you receiving?

Ok, hmm. I've tested it again and I see the error now. This code:

Buy = ExRem (Buy,Sell);
Sell = ExRem (Sell,Buy);

do not work with AlertIF. I am getting signals from the day before also, not only the last bar. How can I use ExRem in the AlertIF?

@herbertioz, the documentation explains that the ExRem function:

removes excessive signals:
returns 1 on the first occurrence of "true" signal in Array1
then returns 0 until Array2 is true even if there are "true" signals in Array1

If you want to see/receive alerts for all the raw Buy/Sell signals, then simply do not use it in your formula (but, in general, you'll see it employed explicitly in almost any basic trading system, precisely to avoid the excess of signals).

To better understand its usage, I suggest you spend some time reading also other threads on this topics here in the forum (search for "exrem").

1 Like

No, the simple and good solution is this:

ChannelBreakUp = H > Ref( HHV( High, 20 ), -1 );
Buy = ChannelBreakUp;
ChannelBreakUpDown = L < Ref( LLV( Low, 20 ), -1 );
Sell = ChannelBreakUpDown;

Buy = ExRem (Buy,Sell);
Sell = ExRem (Sell,Buy);

SetTradeDelays( 1, 1, 1, 1 );
BuyPrice = SellPrice = Open;

if( LastValue( Buy ) )
 SendEmail("Buysignal","Buy this stock: "+FullName(),0);
 
 if( LastValue( Sell ) )
 SendEmail("Sellsignal","Sell this stock: "+FullName(),0);

:smile:

1 Like