Need Volume Breakout Pop-up AFL Code

Hi All,

I am new to Amibroker, need AFL code to develop indicator for Amibroker.

Indicator Logic…
On 5 min Chart, i need Volume Bars and on that volume bars need 21 EMA, logic is, if the next candle volume bar is 5 times of the 21 EMA then it should give pop-up alart saying “Volume Breakout”.

Regards,

Sai Parekh.

@Sai.Parekh007112

here you go

//set chart to 5 minute mode
alertString = "Volume Breakout";
SetChartTimeTo(5*1min);
if(volume > 5*EMA(Volume,21)) Alert(alertString);

1 Like

Thanks for this AFL Code, really appreciate your efforts and quick response…

@fourier why haven't you checked your code before posting? You should have. It contains at least 3 errors:

Przechwytywanie

  1. There's no SetChartTimeTo() function in AFL. Just select 5m as the chart interval - that's all.

  2. There's no Alert() function in AFL. Read about Alertif() function and it's many different settings:

https://www.amibroker.com/guide/afl/alertif.html

That's very strange. Why did you come up with non-existent functions?

  1. You confuse IIF function and if statement:

http://amibroker.com/guide/afl/iif.html
http://amibroker.com/guide/h_understandafl.html

The simplest (but of course not the best) code, could look similar to this one:

vAlert = V > EMA( V, 21 ) * 5;
AlertIf( vAlert, "SOUND C:\\Windows\\Media\\Ding.wav", "Volume Alert", 5, 11, 1 );
4 Likes

Hi Milosz,

Thanks for reply… Even i also faced the above 3 errors, i don’t have knowledge on AFL Code, so I thought it was correct code…

But thanks once again…For your corrected code…

Another example. The code below doesn’t use Alertif() and gives another possibilities of alerting the user about some events by (for example) a PopUp window, spoken message or in any other way. It uses TimeNum() function and for this reason should be used on Intraday charts. Alert is triggered only once per bar.

LATN = "LastAlertTN" + GetChartID();
LastAlertTN = Nz( StaticVarGet( LATN ) );
LastBarTN = LastValue( TimeNum() );

vAlert = LastValue( V ) > LastValue( EMA( V, 21 ) ) * 5;

if( vAlert AND LastBarTN != LastAlertTN )
{
    PopupWindow( "Volume Alert:  " + Name(), "Volume Alert", 30 );
    Say( "Volume alert: " + FullName() );
    StaticVarSet( LATN, LastBarTN );
}

I suggest adding the code (along with the volume EMA chart) to the pane with the volume histogram, below the main price chart. If you don’t know how to do it, watch this tutorial: http://www.amibroker.com/video/dragdrop1.html

http://amibroker.com/guide/afl/popupwindow.html
https://www.amibroker.com/guide/afl/say.html

7 Likes

@Milosz

LATN = "LastAlertTN" + GetChartID();
LastAlertTN = Nz( StaticVarGet( LATN ) );
LastBarTN = LastValue( TimeNum() );

vAlert = LastValue( V ) > LastValue( EMA( V, 21 ) ) * 5;

if( vAlert AND LastBarTN != LastAlertTN )
{
   PopupWindow( "Volume Alert:  " + Name(), "Volume Alert", 30 );
   Say( "Volume alert: " + FullName() );
   StaticVarSet( LATN, LastBarTN );
}

One small request, in this pop-up alert, can i get Date and Time also. in same window…

You can for example replace the above PopUp line with this one:

PopupWindow( "Volume Alert:  " + Name() + "  " + DateTimeToStr(LastValue(DateTime()), 3), "Volume Alert", 30 );

Przechwytywanie

3 Likes

@Milosz

Sorry to disturb you again, but i think what i am getting in pop-window is (Empty) text.

Untitled

I have replace the Pop-up Comment as per the above you mentioned.

LATN = "LastAlertTN" + GetChartID();
LastAlertTN = Nz( StaticVarGet( LATN ) );
LastBarTN = LastValue( TimeNum() );

vAlert = LastValue( V ) > LastValue( EMA( V, 21 ) ) * 5;

if( vAlert AND LastBarTN != LastAlertTN )
{
   PopupWindow( "Volume Alert:  " + Name() + "  " + DateTimeToStr(LastValue(DateTime()), 3), "Volume Alert", 30 );
   Say( "Volume alert: " + FullName() );
   StaticVarSet( LATN, LastBarTN );
}

am i doing something wrong??

Please guide me with the error.... OR Can i get your email ID??

Regards,

Sai Parekh.

@Sai.Parekh007112 , is your item ADANIENT a valid entry in your database?

The code works for @Milosz, so it would indicate issue is likely to be on your end.

Also by looking at the code and the output, it would appear that the issue could be that the item has no entries (no data).

Try running against a known good symbol.

Also, while there are many great helpful members, if you have an issue, getting “private” responses takes the learning out of the forum, and does not help other users who might have the same (or similar) issue to what you are dealing with. Forum replies help everyone.

Good Luck

2 Likes

Hi @Milosz, thanks for awesome code! I'm really new to AFL codes as well.

I managed to make your code works, when I click "Explore", alert window pops up, but it show's me stocks even way back 2009? I've already selected current date only. How to make it so that it will only limit to show me stocks for today only?

Second question, Do I need to keep on clicking "Explore" to run the code or will it automatically run and will display the pop up window?

Thanks!

26%20PM

@bluesand22 As I wrote, this code is designed to be used in a chart window (during the session) to generate live alerts. Additionally it should be used on intraday charts (1m, 5m, 1h etc.). It doesn't work properly in Exploration.

The above code (drag drop) when applied to multiple symbols throws an alert through alertif only when the condition is satisfied for selected symbol. For unselected symbols I found no alerts till the symbol is selected.

hi milosz,

Just ran this code in analysis window as explore with automatic analysis every interval (5 min)
Works well. The following page describes how to use it.

http://www.amibroker.com/kb/tag/exploration/

@bluesand22 ,
one possible cause of the alert being triggering on data "way back in 2009", is that the symbol is no longer being traded, ie. the data ends in 2009. Check what setting you have for the "Range" in the Analysis tab.