So when your signal is set place your trade and toggle a flag . . .
SignalSet = true;
but only place the trade
if(SignalSet == false)
So now your SignalSet flag will be true and you won't have any more trades placed for the same signal . . . When you have detected that your signal has gone . . .
SignalSet = false;
. . . and next time you have a signal to place the trade you can . . .
SignalSet = true
Do you know what moving average is ?.
If you do what I said, you will be able to answer RaptorUK's question "How do you know when the signal has gone ?" and you won't have many orders on every bars.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.