Buy Signal generated but code not executed

I am trying to write a script which executed some function if buy or sell signal is generated. I am using LastValue. If I use LastValue with Buy it works sometimes. If I use Ref(Buy, -1) it works all the time

//This code is executed for all signals
if (LastValue(Ref( Buy, -1 )) OR LastValue(Ref( Sell, -1 ))    )
	{
		_TRACE("Ececute function for Buy or sell");
	}	

//This code is not executed for all signals
if (LastValue( Buy) OR LastValue( Sell)    )
	{
		_TRACE("Ececute function for Buy or sell");
	}

I am facing similar issues. Were you able to resolve the issue? If yes, how?

I haven't been able to solve the problem

@yatinchaubal, I don't understand your "sample" code, or your question or situation...

Why are you using Lastvalue?

My suggestion... post full code, or build your own Exploration AFL.

The Exploration will allow you to show values for what ever you want on each day/bar so you can see what is going on.

Also, check out How do I debug my formula?

I expect that buy/sell orders are sent on candle completion. 2nd if is correct. 1st if generates intermittent signals