Add pause after buy/sell condition is true


I am using an external application to run each time buy signal is true,
however the file keeps on re executing when working with tick data.
i have used exrem and this problem isn't there when i do back testing on 1min data but on tick even if i scroll through chart the if conduction seems to be executing when when buy value is 0;
Would it be possible to add delay or a pause of 1/2mins after each trade.


periods = Param( "Periods", 15, 1, 200, 1 );
Ksmooth = Param( "%K avg", 3, 1, 200, 1 );
Dsmooth = Param( "%D avg", 3, 1, 200, 1 );
myStochD=StochD( periods , Ksmooth, DSmooth );
myStochK=StochK( periods , Ksmooth);

Buy = Cross(myStochK, myStochD );
Sell = Cross( myStochD, myStochK );
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);

_TRACE("Buy Conduction= " +Buy);

Plot( myStochD, "Stochastic %D"+_PARAM_VALUES(), ParamColor( "ColorD", colorRed ), ParamStyle("StyleD") );
Plot( myStochK, "Stochastic %K", ParamColor( "ColorK", colorGreen ), ParamStyle("StyleK") );

PlotShapes(IIf(Sell, shapeHollowDownArrow , shapeNone), colorRed);
PlotShapes(IIf(Buy, shapeHollowUpArrow , shapeNone), colorBlue);

if ( LastValue(Buy) == True )


You will have to use a static variable and set a Flag.

The Flag can either be reset after an event occurs or at a later DateTime() in which case you can store the time stamp the first time Buy signal occurs and compare with Now() until a specified time passes.

Delay/Pause of 1/2min is more like a desperate resort, reason a more logical and it can be done.
I'm not saying, 30sec cant be done, but having a sound approach is better.


after going through, this is the code i came up with. however i would like to know if there is any better way to do it.


StochasticD = StochD(15,3,3);
StochasticK = StochK(15,3);

Buy = Cross(StochasticK,StochasticD);
Sell = Cross(StochasticD,StochasticK);
BuyPrice = Close;
PlotShapes(buy* shapeCircle,colorYellow);

// calculate Time Difference 
last_time = TimeNum();
Buy_time = ValueWhen(Buy,last_time);
pasuetime = DateTimeDiff(last_time,Buy_time);

// Clear order flag when time difference is > 10000 
if( LastValue(pasuetime) >= 10000)
   _TRACE("Order Cleared");

// set order flag and execute TestRun
if( LastValue( Buy ) And Nz( StaticVarGet("OrderAlreadyPlaced") ) == False )
	StaticVarSet( "OrderAlreadyPlaced", True );
	_TRACE("Order Placed");