Have signal close before entry

 

:) In programming the Williams %R to buy/sell when it crosses the trigger line, I am having a problem with the fact that on a H1 chart, The Williams % R value may dip down below/above the trigger line for a split second, trigger the order, and then immediatley come back above/below the trigger line. How do I program the EA so that it doesn't signal an order until the Williams CLOSES above/below trigger line?

Here's the piece of code for a buy signal

williamsrcurrent = iWPR (NULL, 0, 50, 0);
williamsrprevious = iWPR (NULL, 0, 50, 1);

isBuying = (williamsrprevious < -80 && williamsrcurrent > -80);

Thanks folks :)

Pat

Reason: