Problem with "crosses over" ...

 
Hi!

I have a little problem with MQL4! Normally i work with another software to develop trading systems or expert advisors. But now my employer told me to switch to MetaTrader und now i try to code my systems into MQL4. So now the problem: One part of a system is that a trade runs up after the price crossed over/under the last high/low. At my old software i had the possibility to code it like "P crosses over High[1]". But when i code it with MQL4 with the ">" sign it generates several trades in the same bar. But i just want one trade in one bar.

How can i solve this problem? Thanks a lot!!!

Dear AJ
 
I think that's because the occured trading signal has quickly disappeared. For example, the close value on H1 bar is actually varying for every minute. It is high likely that it crosses over a value but then crosses back after a while. That's why you see it generates several trades at the same bar. To avoid such an issue, you can trade according to the previous bar or use some tricks to calculate the average of recent bars.
 

Use this function. It will solve your problem.


bool ExistPositions() {
for (int i=0; i<OrdersTotal(); i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC) {
return(True);
}
}
}
return(false);
}

Reason: