Experts Help Plz. with simple EMA with wait function. (Twist for good)

I've a simple EMA BUY SELL script And I want to add a wait function to it.
ie: if EMA 1 is > than Ema2 and remains > for more than 5 seconds BUY. (This is a intraday script)
I've tried wait function (not sure if it will work in this case)
I've searched a couple of forums and KBs but did not get what I'm looking for. (Got some wait function for look back for bars, but this doesnt serve the purpoes here.

Buy = E1 > E2;
// If E1 is > than E2 for more than 5000 MilliSec (5 sec) Buy.

Complete Script:
Plot( C, "Price", colorDefault, styleBar );

P = ParamField("Price field",-1);
per1 = Param("EMA1",3,1,20,1);
per2 = Param("EMA2",6,1,50,1);

Plot( EMA( P, per1 ), "EMA1", ParamColor( "EMA 1", colorCycle ), ParamStyle("Style") );
Plot( EMA( P, per2 ), "EMA2", ParamColor( "EMA 2", colorCycle ), ParamStyle("Style") );
E1 = EMA(C,per1);
E2 = EMA(C,per2);

Buy = E1 > E2;
// If E1 is > than E2 for more than 5000 MilliSec (5 sec) Buy.
Sell = E2 > E1;
// If E2 is > than E1 for more than 5000 MilliSec (5 sec) Buy.
Buy=ExRem(Buy,Sell) ;

dist = 1.8*ATR(15);
for( i = 0; i < BarCount; i++ )
if( Buy[i] ) PlotText( "" + L[ i ], i, L[ i ]-dist[i], colorWhite, colorGreen );
if( Sell[i] ) PlotText( "" + H[ i ], i, H[ i ]+dist[i], colorWhite, colorRed );

Have you looked in the users guide ?

You would have found this:


  • hold the alert signal Trading system toolbox
SYNTAX Hold( EXPRESSION, periods )
FUNCTION Holds a "true" result of EXPRESSION for the specified number of periods . This true result is held true over the number of periods specified even if a "false" result is generated.
EXAMPLE hold( cross(rsi(14),70),5 )