Two buy alert on same bar!

//************************************Demand / Supply Study Setup***************************************************

SU =	 			Study("su", 2302 ) ;
ST=		 			Study("ST", 2302 );
proSign=			1.009;
tmSU=				(su/prosign);  
proBUY=				Cross(C,tmSU) ;
proBUY2=   	    	  Cross(C,su/1.001);
Buy=				(C>=tmSU );
Sell = 				Cross(st,C);
target1=				su + abs(su-st) *1.99;
target2=				su + abs(su-st) *2.99;

AlertIF( PROBuy  , "SOUND C:\\Program Files (x86)\\AmiBroker5.60\\Sound\\alert.wav", "Audio alert", 1 ,2+4+8);
AlertIF( proBuy2  , "SOUND C:\\Program Files (x86)\\AmiBroker5.60\\Sound\\buzz.wav", "Audio alert", 1 ,2+4+8);
AlertIF(Cross(C, target1) OR Cross(C, target1*1.001), "SOUND C:\\Program Files (x86)\\AmiBroker5.60\\Sound\\laser.wav", "Audio alert", 5 ,2+4+8);
alertIF( Sell , "SOUND C:\\Program Files (x86)\\AmiBroker5.60\\Sound\\Censor.wav", "Audio alert", 2 ,2+4+8);
Filter=				( probuy OR Buy OR Sell) ;//OR (proBuy OR proSell);
SetOption("NoDefaultColumns", True );

Above code has error !

I know that two alertif wan't work !
I am looking for solution , What I am doing is

  1. want buy alert on just before cross line i.e. probuy in code
  2. want another buy alert on actual cross i.e. probuy2
  3. sell alert on target1 i.e alertif close cross target1

on 3rd condition if happens on same day / bar , code goes into loop give buy and sell signal repeatedly , but obvious because of entry and target triggered on same bar.

any idea to overcome this repeated signal AND two buy alert on same bar ? Please share !

Hello sandeep,

to setup such a workflow in my mind you have to persist the current "AB system/trading state". This could be done by build up any file structure on your harddisk and fputs your bit/str "occurency" array.

On every iteration by AB AFL script execution you first check your "AB system/trading state" by fgets that array and decide what to do next step via AFL script execution.

By reaching your traget event reset that array, our game will start again ...

Best regards,

@sandeep If your idea is to simply do not repeat the part of the code on the same bar use the suggestion given in here and use it something like below.

// // 

lastBartime = Status( "lastbarend" );
varName = Name() + "_lastdt";
recordedTimestamp = Nz( StaticVarGet( varName ) );
Newbar = lastBarTime != recordedTimestamp;

if( LastValue( Sell ) && Newbar )
    AlertIF( Sell , "SOUND C:\\Program Files (x86)\\AmiBroker5.60\\Sound\\Censor.wav", "Audio alert", 2 , 2 + 4 + 8 );

if( LastValue( PROBuy ) && Newbar )
    AlertIF( PROBuy , "SOUND C:\\Program Files (x86)\\AmiBroker5.60\\Sound\\Censor.wav", "Audio alert", 2 , 2 + 4 + 8 );
1 Like

For what it is worth, if you use examples from KB, copy them precisely.
The example in Knowledge Base does not have LastValue(Buy) and it is also NOT needed here because AlertIf by itself contains that conditional check.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.