Limit Number of Open Trades Per Function in EA
Forum on trading, automated trading systems and testing trading strategies
When you post code please use the CODE button (Alt-S)!

Hi guys,
...................
Hello,
maybe on strategy tester you use 'open price only' sets, but in real time you can't uses.
In open price sets, expert runs once time in starting bar. There is no option on real time for that (you can to made a part of code for that).
To control orcers, need to count open orders.
If you need to place orders from differents functions and manage them separately, need to use different ID for each function.
- www.mql5.com
Hi guys,
I have an issue with my EA where it works fine on the back test, but goes completely berserk on the live. What happens is when I back test, the EA places a total of 269 trades right? With a win rate of just over 60%. But when I released the beast into the lives, it placed more than 40 trades within seconds and was continuing to place more before I removed it from the chart. I could tell which section of the code it was executing to take those trades based on the signal at the time, but I could not find any reason on the code for it to do this. The code is below.
I would ideally like to have this function place and have only 10 trades open at a time. I was able to achieve this by using OrdersTotal(). But now my issue is I have 4 other modules in the code and I also want each of the not to open more than 10 trades at a time. If I use OrdersTotal() on all of them, The entire EA can only place 10 trades. If one module runs and places its 10 trades, the other modules will not be able to place trades because there are already 10 trades open.
I hope I have given enough detail for you to be able to assist.
void scalpExpert()
{
double lowerBand = iBands(_Symbol, _Period, 21, 2, 0, PRICE_CLOSE, MODE_LOWER, 1);
double upperBand = iBands(_Symbol, _Period, 21, 2, 0, PRICE_CLOSE, MODE_UPPER, 1);
double referenceSMA = iMA(_Symbol, _Period, 200, 0, MODE_SMA, PRICE_CLOSE, 1);// Calculates SMA for previous candle.
double bandWidth = 0.0110;
Alert("Band width = " + (upperBand - lowerBand));
if((upperBand - lowerBand) <= bandWidth && Month() != 3)//Check if bollinger bands have compressed and month is not March
{
if(lowerBand < Close[6] < upperBand && lowerBand < Close[5] < upperBand && lowerBand < Close[4] < upperBand && lowerBand < Close[3] < upperBand && lowerBand < Close[2] < upperBand &&lowerBand < Close[1] < upperBand)
{
if(lowerBand < Open[6] < upperBand && lowerBand < Open[5] < upperBand && lowerBand < Open[4] < upperBand && lowerBand < Open[3] < upperBand && lowerBand < Open[2] < upperBand && lowerBand < Open[1] < upperBand)
{
if(Close[0] > upperBand)
{
placeOrder(true, stopLoss, 50, lotSize);
}//Nested IF3
if(Close[0] < lowerBand)
{
placeOrder(false, stopLoss, 50, lotSize);
}//Nested IF4
}//Nested IF2
}//Nested IF1
}//Nesting IF
}//End