# Same candle Buy and Sell signal problem

Hey guys,
I've been working on a trailing stop loss formula.
Mainly based on a knowledge base article but with some differences.

``````for (i = 0; i < BarCount; i++)
{
if( LongTrailStop == 0 AND Buy[ i ])
{
LongTrailStop = High[ i ] - LongStopLossParam;
}
else
{
}

if ( ShortTrailStop == 0 AND Short[ i ])
{
ShortTrailStop = Low[ i ] + ShortStopLossParam;
}
else
{
Short[ i ] = 0;
}

if( LongTrailStop > 0 AND Low[ i ] < LongTrailStop )
{
Sell[ i ] = 1;
LongTrailStop = 0;
}

if( ShortTrailStop > 0 AND High[ i ] > ShortTrailStop )
{
Cover[ i ] = 1;
ShortTrailStop = 0;
}

if( LongTrailStop > 0 )
{
LongTrailStop = Max( High[ i ] - LongStopLossParam, LongTrailStop );
LongTrailARRAY[ i ] = LongTrailStop;
}
if( ShortTrailStop > 0)
{
ShortTrailStop = Min( Low[ i ] + ShortStopLossParam, ShortTrailStop );
ShortTrailARRAY[ i ] = ShortTrailStop;
}
}
``````

And while testing I've noticed one problem. If stop loss is hit during the same candle the trade started, then I receive multiple Buy/Sell signals until next bar starts.

Is there any neat way to prevent this happening inside existing for loop?
Or should I introduce some sort of "NewMinute" check which equals to 1 only at the beginning of each minute. So that I check if NewMinute is 1 before entering trade.

Thank you