Pop Up window in Amibroker

#1
Hi Friends,

I wish to add PopUp window to my afl. For example:

Buy = Cross( MACD(), Signal() );
Sell = Cross( Signal(), MACD() );

Now I want that when BUY is generated, a pop up window is generated displaying a custom text (for eg. BUY - MACD Crossed Upwards) in custom colour (Green for Buy and red for sell). Seniors please help me in how I can add the same to my AFL.

Thanks

Sanjeev Bhatia

P. S. I Don't want to use AlertIf function since the alert is displayed in alerts window. I need a pop up window.
 
#5
// http://www.amibroker.org/userkb/2008/08/30/popup-window-preventing-pile-ups/
// http://www.amibroker.com/members/feedback/view_bug.php?bug_id=1528

function GetSecondNum()
{
Time = Now( 4 );
Seconds = int( Time % 100 );
Minutes = int( Time / 100 % 100 );
Hours = int( Time / 10000 % 100 );
SecondNum = int( Hours * 60 * 60 + Minutes * 60 + Seconds );
return SecondNum;
}

function secleft()
{
currtime = Now ( 4 );
hr = int ( currtime / 10000 );
mnt = int ( ( currtime - hr * 10000 ) / 100 );
sec = currtime - hr * 10000 - mnt * 100;
totalsec = hr * 60 ^ 2 + mnt * 60 + sec;
left = Interval() - totalsec % Interval();
return left;
}

function PopupWindowEx( popupID, bodytext, captiontext, timeout, left, top )
{
displayText = bodytext + "_" + captiontext;
if ( ( StaticVarGetText( "prevPopup:" + popupID ) != displayText) OR
( StaticVarGet( "prevPopupTime" + popupID ) < GetSecondNum() ) )
{
StaticVarSetText( "prevPopup:" + popupID, displayText);
StaticVarSet( "prevPopupTime" + popupID, GetSecondNum() + timeout );
PopupWindow( bodytext, Captiontext + popupID, timeout, Left, top );
}
}

/////////////////////////////////////////////////////////////////////////
// one time popup example by trash ....
// http://www.traderji.com/newreply.php?do=postreply&t=78419
/////////////////////////////////////////////////////////////////////////

Buy = type condison ;
Sell = type condison ;

if( Status( "action" ) == actionIndicator )
{
Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );

alertstr = Name() + "_Last Bartime:" + DateTimeToStr( LastValue( DateTime() ) );

buyid = "ID:1";
sellid = "ID:2";

duration = secleft(); // one popup ocurrence AFTER confirmed signal

if ( LastValue( Ref( Buy, -1 ) ) )
PopupWindowEx( buyid, "Buy " + alertstr, "Buy Alert", duration, -1, -1 );

if ( LastValue( Ref( Sell, -1 ) ) )
PopupWindowEx( sellid, "Sell " + alertstr, "Sell Alert", duration, 0, 0 );

// Title = "Intrabar " + StaticVarGetText( "prevPopup:" + buyid ) +
// "\nIntrabar " + StaticVarGetText( "prevPopup:" + sellid ) +
// "\nBartime left: "+ duration;

// Plot( Buy, "True Buy Sig", colorGreen,C, 0, 1, 0, 0, width = -80 );
// Plot( Sell, "True Sell Sig", colorRed, C, 0, 1, 0, 0, width );
}


/*
Buy = Cross(MACD(),Signal());
Sell = Cross(Signal(),MACD());
Plot(MACD(),"MACD",colorRed,styleThick);
Plot(Signal(),"SIGNAL",colorBlue,styleThick);
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);

Filter = Buy OR Sell;
//alert
AlertIf( Buy , "SOUND C:\\Windows\\Media\\chimes.wav", "jim-Audio Buy Alert", 2 );//correct
AlertIf( Sell , "SOUND C:\\Windows\\Media\\Ding.wav", "Jim-Audio SELL Alert=" , 1+2 );//correct
//AlertIf( Buy, "Buy", "BUY@ +C=", 1, 1+2 );
AlertIf( Buy, "", "BUY @ " + C, 1 );
AlertIf( Sell, "", "SELL @ " + C, 1 );//2



shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( shape, IIf( Buy, colorGreen, colorRed ), 0, IIf( Buy, Low, High ) );



function GetSecondNum()
{
Time = Now( 4 );
Seconds = int( Time % 100 );
Minutes = int( Time / 100 % 100 );
Hours = int( Time / 10000 % 100 );
SecondNum = int( Hours * 60 * 60 + Minutes * 60 + Seconds );
return SecondNum;
}

function PopupWindowEx( popupID, bodytext, captiontext, timeout, left, top )
{
displayText = bodytext + captiontext;
if ( ( StaticVarGetText( "prevPopup" + popupID ) != displayText) OR ( StaticVarGet( "prevPopupTime" + popupID ) < GetSecondNum() ) )
{
StaticVarSetText( "prevPopup" + popupID, displayText);
StaticVarSet( "prevPopupTime" + popupID, GetSecondNum() + timeout );
PopupWindow( bodytext, Captiontext + popupID, timeout, Left, top );
}
}

PopupWindowEx( "ID:1", "BUY", "BUY alert ", 5, -1, -1 );
PopupWindowEx( "ID:2", "SELL", "SELL alert ", 5, 0, 0 );
 
#6
you can try:
Code:
//CalcTrendProcedure=ParamToggle("CalcTrendProcedure","ON|OFF");

_SECTION_BEGIN("CalcTrendProcedure");

Length=25;//Param("Length",25, 2); 
Deviation=2;//Param("Deviation",2);
MoneyRisk=1;//Param("Money Risk", 1);
LineStyle=0;//ParamToggle("Display line mode", "No|Yes", 0); 
cUpTrendLine =18;// ParamColor("UpTrendLine", colorGold);
cDnTrendLine = 18;//ParamColor("DownTrendLine", colorGold);

TurnedUp=Nz(StaticVarGet("TurnedUp"));
TurnedDown=Nz(StaticVarGet("TurnedDown"));
SoundON = ParamToggle("Sound","Off|On",1);



// your buy condition goes here
//ie. buy=...

// your sell condition goes here
//ie. sell=...

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

procedure CalcTrend_proc(bbtop,bbbot,Length,MoneyRisk,SoundON,TurnedUp,TurnedDown){
	global UpTrendLine;
	global DownTrendLine;
	global smax;
	global smin;

	UpTrendLine=Null;
	DownTrendLine=Null;
	smax=Null;
	smin=Null;
	trend=0;

	for (i=Length+1; i<BarCount; i++){ 
		smax[i]=bbtop[i];
		smin[i]=bbbot[i];
		
		if (C[i]>smax[i-1]) trend=1;
		if (C[i]<smin[i-1]) trend=-1;
		if(trend>0 && smin[i]<smin[i-1]) smin[i]=smin[i-1];
		if(trend<0 && smax[i]>smax[i-1]) smax[i]=smax[i-1];
		
		bsmax[i]=smax[i]+0.5*(MoneyRisk-1)*(smax[i]-smin[i]);
		bsmin[i]=smin[i]-0.5*(MoneyRisk-1)*(smax[i]-smin[i]);
		
		if(trend>0 && bsmin[i]<bsmin[i-1]) bsmin[i]=bsmin[i-1];
		if(trend<0 && bsmax[i]>bsmax[i-1]) bsmax[i]=bsmax[i-1];
		
		if (Buy[i]) { 
			UpTrendLine[i]=bsmin[i];
			if (SoundON==True && !TurnedUp && i==BarCount-1){// && IsEmpty(UpTrendLine[i-1])) { 
				Say("attention please, Market Going, UP");
				PopupWindow(Date()+ "\n  > " +  Name() + "\n  > Buy : " + L[ i ] + "\n  > Target : " +(L[i]*1.005) +"\n  > Stop Loss : " +(L[i]*0.9975),"Buy alert", 100, 640*mtRandom(), 480*mtRandom());				TurnedUp=StaticVarSet("TurnedUp",1);
				TurnedDown=StaticVarSet("TurnedDown",0);

			} 
		} 
	
	 
		if (Sell[i]) 	{ 
			DownTrendLine[i]=bsmax[i];
			if (SoundON==True && !TurnedDown && i==BarCount-1){// && IsEmpty(DownTrendLine[i-1])) {
				Say("attention please, Market Going, DOWN");
				PopupWindow( Date()+ "\n  > " + Name() + "\n  > Sell : " + H[i] + "\n  > Target : " + (H[i]*0.995)+"\n  > Stop Loss : " +(H[i]*1.0025),"Sell alert", 100, 640*mtRandom(), 480*mtRandom());
				TurnedUp=StaticVarSet("TurnedUp",0);
				TurnedDown=StaticVarSet("TurnedDown",1);
			} 
		} 
	} 
} 
	bbtop=BBandTop(C,Length,Deviation);
	bbbot=BBandBot(C,Length,Deviation);
//if(CalcTrendProcedure){
	CalcTrend_proc(bbtop,bbbot,Length,MoneyRisk,SoundON,TurnedUp,TurnedDown);
//}	
	UpTrendSigNal=UpTrendLine aND IsEmpty(Ref(UpTrendLine,-1));
	DownTrendSigNal=DownTrendLine aND IsEmpty(Ref(DownTrendLine,-1));

//}
/*

dist = 0.8*aTR(10);
dist1 = 2*aTR(10);
for( i = 0; i < BarCount; i++ ) { 
	if( UpTrendSignal[i] ) {
		PlotText( "\nBuy:" + L[ i ] + "\nT= " + (L[i]*1.005) + "\nSL= " + (L[i]*0.9975), i, L[ i ]-dist[i], colorGreen, colorWhite );
	 }
	 if( DownTrendSignal[i] ) {
		PlotText( "Sell:" + H[ i ] + "\nT= " + (H[i]*0.995) + "\nSL= " + (H[i]*1.0025), i, H[ i ]+dist1[i], colorRed, colorWhite ); 
	 }
}
*/
-----
regards
manoj
 
Last edited:

Similar threads